using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Linq;

namespace CSharp_Contests
{
    internal class Program
    {
        private static bool IsB(int number)
        {

            var bits = (new BitArray(new int[] {number})).OfType<bool>().Reverse().SkipWhile(a => a == false).ToArray();
            var ones = bits.TakeWhile(a => a).Count();
            var zeros = bits.Skip(ones).TakeWhile(a => a == false).Count();
            return ones + zeros == bits.Length && ones - 1 == zeros;
        }

        public static void Main()
        {
            int number = int.Parse(Console.ReadLine());
            for (int i = number; i > 0; i--)
            {
                if (number %i == 0 && IsB(i))
                {
                    Console.WriteLine(i);
                    break;
                }
            }
#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMP
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Int32.Parse(Console.ReadLine());
            Console.WriteLine(Run(input));
        }
        public static int Run(int a)
        {
            var InputNumber = a;
            var number = a;

            for (var q = 1; q < InputNumber; q++)
            {
                if (InputNumber % number != 0)
                {
                    number--;
                    continue;

                }
                string BinaryCode = Convert.ToString(number, 2);
                char[] charArray = BinaryCode.ToArray();
                int[] intArray = Array.ConvertAll(charArray, c => (int)Char.GetNumericValue(c));

                int middle = 0;
                if (intArray.Length % 2 == 0)
                {
                    middle = (intArray.Length / 2) + 1;
                }
                else
                {
                    middle = intArray.Length / 2 + intArray.Length % 2;
                }

                if (middle == intArray.Length)
                {
                    number--;
                    continue;
                }
                if (intArray.Length == 4)
                {
                    number--;
                    continue;
                }
                bool Ones = true;
                for (var i = 0; i < middle; i++)
                {
                    if (intArray[i] != 1)
                    {
                        Ones = false;
                        break;
                    }
                }
                if (!Ones)
                {
                    number--;
                    continue;
                }

                if (intArray.Length % 2 == 0)
                {
                    number--;
                    continue;
                }

                bool Zeros = true;
                for (var j = intArray.Length - 1; j >= middle; j--)
                {
                    if (intArray[j] != 0)
                    {
                        Zeros = false;
                        break;
                    }
                }
                if (!Zeros)
                {
                    number--;
                    continue;
                }

                return number;

            }
            return number;
        }
    }
}

using System;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] deliters = { 32640, 8128, 2016, 496, 120, 28, 6, 1 };
            foreach (int deliter in deliters)
                if (n%deliter==0)
                {
                    Console.WriteLine(deliter);
                    break;
                }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

namespace Codeforces
{
    class Program : IDisposable
    {
        private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
        private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

        private void Solve()
        {
            var n= int.Parse(Console.ReadLine());
            var list = new List<long>() {1,6,28,120,496,2016,8128,32640};
            for (int i = list.Count - 1; i >= 0; i--)
            {
                if (n >= list[i] && n%list[i] == 0)
                {
                    Console.WriteLine(list[i]);
                    return;
                }
            }
        }

        int BinarySearch(int[] arr, int q)
        {
            var l = 0;
            var r = arr.Length - 1;
            //int med = -1;
            while (l <= r)
            {
                var med = l + (r - l) / 2;
                if (arr[med] == q)
                {
                    return med;
                }
                if (q < arr[med])
                {
                    r = med - 1;
                }
                else
                {
                    l = med + 1;
                }
            }
            return -1;
        }

        static void Main(string[] args)
        {
            var p = new Program();
            p.Solve();
            //Console.ReadLine();
            //p.Dispose();
            //////////////////////////////
        }

        #region Helpers

        private static int ReadInt()
        {
            return int.Parse(textReader.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(textReader.ReadLine());
        }

        private static int[] ReadIntArray()
        {
            return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        #endregion

        public void Dispose()
        {
            textReader.Close();
            textWriter.Close();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      var n = input.ReadInt();
      for (int i = n; i > 0; i--)
      {
        if (n % i == 0 && isBeauty(i))
        {
          Console.Write(i);
          break;
        }
      }
    }

    private static bool isBeauty(int n)
    {
      var s = Convert.ToString(n, 2);
      var c1 = s.TakeWhile(c => c == '1').Count();
      var c0 = s.Skip(c1).TakeWhile(c => c == '0').Count();
      return c1 + c0 == s.Length && c1 == c0 + 1;
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }

    #region Service functions

    private static int GCD(int a, int b)
    {
      while (b != 0)
      {
        a %= b;
        int t = b;
        b = a;
        a = t;
      }
      return a;
    }

    #endregion
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(this.ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Achill
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp = Console.ReadLine().Split().Select(item => Int32.Parse(item)).ToArray();
            String tmp = Convert.ToString(inp[0], 2), res = "", response ="";
            bool flag = false;
            res += "1";
            for (int i = 0; i < tmp.Length; ++i)
            {
                if (inp[0] >= FromBinary(res))
                {
                    if(inp[0] % FromBinary(res) == 0)
                    {
                        response = res;
                    }
                    res = "1" + res;
                    res += "0";
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine(FromBinary(response));
            //Console.ReadKey();
        }

        static int FromBinary(string input)
        {
            int big = new int();
            foreach (var c in input)
            {
                big <<= 1;
                big += c - '0';
            }

            return big;
        }
    }
}

using System;

public class Test
{
	public static void Main()
	{
		int l = int.Parse(Console.ReadLine());
		int k = 0;
		for(int x = 1;x<l+1;x++){
			if(((float)l/x)==(int)(l/x)){
				int ko = (int)(l/x);
				if(CheckPerfecto(ToByte(ko))==true){
					k = ko;
					break;
				}
			}
		}

		Console.WriteLine(k);
	}

	public static string ToByte(int a){
		int ost = 2;
	//	int s = a;

		string o = "";
		string o2 = "";

		while(a>=2){
			int d=(int)(a/2);
			ost = a-(2*d);
			a=d;
			o+=""+ost;
		}
		o+=""+a;

		for(int x = o.Length-1;x>=0;x--){
			o2+=o[x];
		}

		return o2;
	}

	public static bool CheckPerfecto(string g){
		int zero = 0;
		int numb = 0;

		int len = g.Length;

		float numbcount = ((float)len-1)/2;

		if (numbcount-(int)numbcount==0) {
			if(Sum(g.Substring((int)numbcount+1,(int)numbcount))==0 && Sum(g.Substring(0,(int)numbcount+1))==(int)numbcount+1){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}

	public static int Sum(string g){
		int sum = 0;
		foreach(char a in g){
			sum+=int.Parse(a+"");
		}
		return sum;
	}
}

using System;
using System.Linq;
namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int count = (int)Math.Ceiling(Math.Log(n, 2));
            if (count % 2 == 0)
                count--;
            int rez = 0;
            do
            {
                string str = new string('1', count / 2 + 1) + new string('0', count / 2);
                count -= 2;
                rez = Convert.ToInt32(str, 2);
            }
            while (n % rez != 0);
            Console.WriteLine(rez);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] prekr = new int[8] {1,6,28,120,496,2016,8128,32640};
            int ch = int.Parse(Console.ReadLine().Trim());
            int rez = 0;
            for (int i = 7; i >= 0; i--) {
                if (ch % prekr[i] == 0) {
                    rez = prekr[i];
                    break;
                }
            }
            Console.WriteLine(rez);
//            Console.ReadKey();
        }
    }
}

using System;
using System.Linq;

namespace CSharp
{
    class _893B
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(Enumerable.Range(1, n).Where(d => n % d == 0 && IsBeautiful(d)).Max());
        }

        private static bool IsBeautiful(int n)
        {
            string binary = Convert.ToString(n, 2);
            int k = binary.Length / 2;
            return binary.Take(k + 1).All(c => c == '1') && binary.Reverse().Take(k).All(c => c == '0');
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();

        /*
         * 二進表現が連続k+1個1,k個0なら美しい
         *
         * nの約数最大
         */

        int ans = 1;
        for (int k = 1; ; k++)
        {
            var tmp = ((1 << k) - 1) * (1 << (k - 1));
            if(tmp <= n)
            {
                if (n % tmp == 0) ans = tmp;
            }
            else
            {
                break;
            }
        }

        Console.WriteLine(ans);

    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        var N = sc.Int;
        for (int i = N; i >= 1; i--)
            if (N % i == 0)
            {
                var n = i;
                int b = 30;
                for (; b >= 0; b--)
                    if (n % (1<<b) == 0) break;
                n >>= b;
                int c = 30;
                for (; c >= 0; c--)
                    if (n == (1 << c) - 1) break;
                if (c == b + 1) Fail(i);
            }
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }
}
#endregion

using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Linq;

namespace CSharp_Contests
{
    internal class Program
    {
        private static int zeros, ones, number, mask = 0;
        private const int stop = 1 << 25;

        public static void Main()
        {
            number = int.Parse(Console.ReadLine());

            for (int i = number; i > 0; i--)
            {
                if (number % i == 0)
                {
                    zeros = ones = 0;
                    mask = 1;
                    while ((i & mask) == 0)
                    {
                        zeros++;
                        mask <<= 1;
                    }
                    while ((i & mask) == mask)
                    {
                        ones++;
                        mask <<= 1;
                    }
                    while (mask < stop)
                    {
                        if ((i & mask) != 0)
                        {
                            ones = zeros = 0;
                            break;
                        }
                        mask <<= 1;
                    }
                    if (ones == zeros + 1)
                    {
                        Console.WriteLine(i);
                        break;
                    }
                }
            }
#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Beautiful_Divisors
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static long Solve(string[] args)
        {
            int n = Next();

            var s = new Stack<int>();
            for (int i = 0;; i++)
            {
                int p = (1 << i)*((2 << i) - 1);
                if (p > n)
                    break;
                s.Push(p);
            }
            return s.FirstOrDefault(l => n%l == 0);
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Beautiful_Divisors
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static long Solve(string[] args)
        {
            int n = Next();

            var s = new Stack<int>();
            for (int i = 0;; i++)
            {
                int p = ((2 << i) - 1) << i;
                if (p > n)
                    break;
                s.Push(p);
            }
            return s.FirstOrDefault(l => n%l == 0);
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
namespace _893B
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long result = 0;
            for (int j = 1; j < 25; j++)
            {
                long num = ((1L << j) - 1L) * (1L << (j - 1));
                if (num <= n && n % num == 0 && num > result)
                    result = num;
            }
            Console.WriteLine(result);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForceProblemSolve
{
    class B
    {

        public static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int m = 0;

            int i = 1;
            while (i <= n)
            {
                if (n % i == 0)
                {

                    for (int j = 0; j <= i; j++)
                    {
                        if((Math.Pow(2, j) - 1) * Math.Pow(2, j - 1) == i)
                        {
                                if (i > m)
                                {
                                    m = i;
                                }
                            }
                        }
                    /*string s = Convert.ToString(i, 2);

                    int zero = 0, one = 0;
                    for (int j = 0; j < s.Length; j++)
                    {
                        if (s[j] == '0')
                        {
                            zero++;
                        }
                        else
                        {
                            one++;
                        }
                    }
                    if ((one == zero + 1) && ( (Math.Pow(2,i)-1)*Math.Pow(2,i-1) == i))
                    {
                        if (i > m)
                        {
                            m = i;
                        }
                    }*/

                }
                i++;
            }

            Console.WriteLine(m);

        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }
        object Solve()
        {
            var n = ReadLong();
            {
                var k = 0;
                var curr = n;
                while (curr % 2 == 0)
                {
                    curr >>= 1;
                    k++;
                }
                if (curr == (1 << (k + 1)) - 1)
                    return n;
            }
            if (n == 1)
                return 1;
            for (var i = n / 2; i >= 1; i--)
            {
                if (n % i == 0)
                {
                    var k = 0;
                    var curr = i;
                    while (curr % 2 == 0)
                    {
                        curr >>= 1;
                        k++;
                    }
                    if (curr == (1 << (k + 1)) - 1)
                        return i;
                }
            }
            throw new Exception("huj");
        }
        long fastpow(long b, long x)
        {
            checked
            {
                if (x == 0)
                    return 1;
                if (x == 1)
                    return b;
                if (x % 2 == 0)
                    return fastpow(b * b % commonMod, x / 2);
                return b * fastpow(b, x - 1) % commonMod;
            }
        }
        int nod(int a, int b)
        {
            if (a < b)
                return nod(b, a);
            if (b == 0)
                return a;
            return nod(b, a % b);
        }

        class End
        {
            public long Val { get; set; }
            public bool Left { get; set; }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10)
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            //var i = s.IndexOf(' ');
            //return new[] { long.Parse(s.Substring(0, i)), long.Parse(s.Substring(i + 1)) };
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }

}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
//			using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var n = sr.NextInt64();
            var pows = new long[20];
            var val = 1;
            pows[0] = 1;
            for (var i = 1; i < pows.Length; i++) {
                val *= 2;
                pows[i] = val;
            }
            var divisors = new List<long>();
            for (var k = 1; k < pows.Length; k++) {
                var next = (pows[k] - 1) * (pows[k - 1]);
                divisors.Add(next);
            }
            for (var i = divisors.Count - 1; i >= 0; i--) {
                if (n % divisors[i] == 0) {
                    sw.WriteLine(divisors[i]);
                    return;
                }
            }
            throw new InvalidOperationException();
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
   class B
   {
     static void Main(string[] args)
     {
       int n = int.Parse(Console.ReadLine());

       int k = 2;

       for(int i=10;i>=1;i--)
       {
         double num = (Math.Pow(2,i) - 1) * Math.Pow(2,i-1);
         if(n%num==0){
           k = (int)num;
           break;
         }
       }
       Console.WriteLine(k);

     }
   }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

namespace CodeforcesTemplate
{
    public static class Permutation
    {
        private static bool Next(ref int[] arr)
        {
            int k, j, l;
            for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }
            if (j == -1)
            {
                arr = arr.OrderBy(c => c).ToArray();
                return false;
            }
            for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }
            var tmp = arr[j];
            arr[j] = arr[l];
            arr[l] = tmp;
            for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)
            {
                tmp = arr[k];
                arr[k] = arr[l];
                arr[l] = tmp;
            }
            return true;
        }
        public static IEnumerable<int[]> AllPermutations(int[] arr)
        {
            do yield return arr;
            while (Next(ref arr));
        }
    }

    class Program
    {
        private const string FILENAME = "distance4";

        private const string INPUT = FILENAME + ".in";

        private const string OUTPUT = FILENAME + ".out";

        private static Stopwatch _stopwatch = new Stopwatch();

        private static StreamReader _reader = null;
        private static StreamWriter _writer = null;

        private static string[] _curLine;
        private static int _curTokenIdx;

        private static char[] _whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        private static string ReadNextToken()
        {
            if (_curTokenIdx >= _curLine.Length)
            {
                //Read next line
                string line = _reader.ReadLine();
                if (line != null)
                    _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    _curLine = new string[] { };
                _curTokenIdx = 0;
            }

            if (_curTokenIdx >= _curLine.Length)
                return null;

            return _curLine[_curTokenIdx++];
        }

        private static int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        private static void RunTimer()
        {
#if (DEBUG)

            _stopwatch.Start();

#endif
        }

        private static void Main(string[] args)
        {

#if (DEBUG)
            double before = GC.GetTotalMemory(false);
#endif

            int[] niceDigits = new int[8] { 1, 6, 28, 120, 496, 2016, 8128, 32640 };

            int a = int.Parse(Console.ReadLine().Trim());

            int rez = 0;

            for (int i = 7; i >= 0; i--)
            {
                if (a % niceDigits[i] == 0)
                {
                    rez = niceDigits[i];
                    break;
                }
            }

            Console.WriteLine(rez);

#if (DEBUG)
            _stopwatch.Stop();

            double after = GC.GetTotalMemory(false);

            double consumedInMegabytes = (after - before) / (1024 * 1024);

            Console.WriteLine($"Time elapsed: {_stopwatch.Elapsed}");

            Console.WriteLine($"Consumed memory (MB): {consumedInMegabytes}");

            Console.ReadKey();
#endif

        }

        private static int CountLeadZeros(string source)
        {
            int countZero = 0;

            for (int i = source.Length - 1; i >= 0; i--)
            {
                if (source[i] == '0')
                {
                    countZero++;
                }

                else
                {
                    break;
                }

            }

            return countZero;
        }

        private static string ReverseString(string source)
        {
            char[] reverseArray = source.ToCharArray();

            Array.Reverse(reverseArray);

            string reversedString = new string(reverseArray);

            return reversedString;
        }

        private static int[] CopyOfRange(int[] src, int start, int end)
        {
            int len = end - start;
            int[] dest = new int[len];
            Array.Copy(src, start, dest, 0, len);
            return dest;
        }

        private static string StreamReader()
        {

            if (_reader == null)
                _reader = new StreamReader(INPUT);
            string response = _reader.ReadLine();
            if (_reader.EndOfStream)
                _reader.Close();
            return response;

        }

        private static void StreamWriter(string text)
        {

            if (_writer == null)
                _writer = new StreamWriter(OUTPUT);
            _writer.WriteLine(text);

        }

        private static int BFS(int start, int end, int[,] arr)
        {
            Queue<KeyValuePair<int, int>> queue = new Queue<KeyValuePair<int, int>>();
            List<bool> visited = new List<bool>();
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                visited.Add(false);
            }

            queue.Enqueue(new KeyValuePair<int, int>(start, 0));
            KeyValuePair<int, int> node;
            int level = 0;
            bool flag = false;

            while (queue.Count != 0)
            {
                node = queue.Dequeue();
                if (node.Key == end)
                {
                    return node.Value;
                }
                flag = false;
                for (int i = 0; i < arr.GetLength(0); i++)
                {

                    if (arr[node.Key, i] == 1)
                    {
                        if (visited[i] == false)
                        {
                            if (!flag)
                            {
                                level = node.Value + 1;
                                flag = true;
                            }
                            queue.Enqueue(new KeyValuePair<int, int>(i, level));
                            visited[i] = true;
                        }
                    }
                }

            }
            return 0;

        }

        private static void Write(string source)
        {
            File.WriteAllText(OUTPUT, source);
        }

        private static string ReadString()
        {
            return File.ReadAllText(INPUT);
        }

        private static void WriteStringArray(string[] source)
        {
            File.WriteAllLines(OUTPUT, source);
        }

        private static string[] ReadStringArray()
        {
            return File.ReadAllLines(INPUT);
        }

        private static int[] GetIntArray()
        {
            return ReadString().Split(' ').Select(int.Parse).ToArray();
        }

        private static double[] GetDoubleArray()
        {
            return ReadString().Split(' ').Select(double.Parse).ToArray();
        }

        private static int[,] ReadINT2XArray(List<string> lines)
        {
            int[,] arr = new int[lines.Count, lines.Count];

            for (int i = 0; i < lines.Count; i++)
            {
                int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                for (int j = 0; j < lines.Count; j++)
                {
                    arr[i, j] = row[j];
                }
            }

            return arr;
        }
    }
}

// Problem: 893B - Beautiful Divisors
// Author: Gusztav Szmolik

using System;

class BeautifulDivisors
    {
    static int Main ()
        {
        string[] words = ReadSplitLine (1);
        if (words == null)
            return -1;
        uint n;
        if (!UInt32.TryParse (words[0], out n))
            return -1;
        if (n < 1 || n > 100000)
            return -1;
        uint ans = 0;
        for (uint i = 1; i <= n && ans == 0; i++)
            {
            if (n%i > 0)
                continue;
            uint divisor = n/i;
            uint tmpConvBin = divisor;
            byte countZero = 0;
            byte countOne = 0;
            bool solved = true;
            bool procZero = true;
            while (tmpConvBin > 0 && solved)
                {
                byte digitBin = Convert.ToByte (tmpConvBin%2);
                tmpConvBin /= 2;
                if (digitBin == 0)
                    {
                    if (procZero)
                        countZero++;
                    else
                        solved = false;
                    }
                else
                    {
                    if (procZero)
                        {
                        procZero = false;
                        countOne = 1;
                        }
                    else
                        {
                        countOne++;
                        if (countOne > countZero+1)
                            solved = false;
                        }
                    }
                }
            if (solved && countOne == countZero+1)
                ans = divisor;
            }
        Console.WriteLine (ans > 0 ? ans : 1);
        return 0;
        }

    static string[] ReadSplitLine (uint numWordNeed)
        {
        string line = Console.ReadLine ();
        if (line == null)
            return null;
        char[] delims = new char[2] {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        return (words.Length == numWordNeed ? words : null);
        }
    }

using System;
using System.Collections.Generic;
using System.Linq;

namespace b
{
    class Program
    {
        static IEnumerable<uint> GetButifulNumbers(uint n) {
            for (int i = 1;i<15;i++) {
                yield return (uint)(Math.Pow(2, i) - 1) * (uint)(Math.Pow(2, i- 1));
            }
        }
        static void Main(string[] args)
        {
            var butiful = GetButifulNumbers(10000).ToList();
            var input = uint.Parse(Console.ReadLine());
            var gcdButiful = butiful.Last(i => input%i == 0);
            Console.WriteLine(gcdButiful);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cs
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0, n = Convert.ToInt32(Console.ReadLine());
            for(int k = 1; k <= 10; ++k)
            {
                if (n % (((1 << k) - 1) * (1 << k - 1)) == 0)
                {
                    ans = ((1 << k) - 1) * (1 << k - 1);
                }
            }
            Console.WriteLine(ans);
        }
    }
}

using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

public class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for(int i = n; i >= 1; i--)
		{
			string binary = Convert.ToString(i, 2);
			int q1 = 0;
			bool w1 = true;
			int q2 = 0;
			bool w2 = true;
			for(int j = 0; j < binary.Length; j++)
			{
				if(binary[j] == '1' && w1)
				{
					q1++;
				}
				else if(binary[j] == '0')
				{
					w1 = false;
					q2++;
				}
				else
				{
					w2 = false;
					break;
				}
			}
			if(w2)
			{
				if(n % i != 0)
				{
					continue;
				}
					if(q1 == q2+1)
					{
						Console.WriteLine(i);
						return;
					}
			}
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Beautiful_Divisors
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            for(int i=n;i>0;i--)
            {
                if (n % i != 0)
                    continue;
                string binary = Convert.ToString(i, 2);
                int ones = 0;
                int zeroes = 0;
                bool flag = false;
                bool correct = true;
                int count = 0;
                while(count!=binary.Length)
                {
                    if (!flag)
                    {
                        if(binary[count]=='1')
                        {
                            ones++;
                            count++;
                        }
                        else
                        {
                            zeroes++;
                            flag = true;
                            count++;
                        }
                    }
                    else
                    {
                        if(binary[count]=='0')
                        {
                            zeroes++;
                            count++;
                        }
                        else
                        {
                            correct = false;
                            break;
                        }
                    }
                }
                if(correct&&ones-1==zeroes)
                {
                    Console.WriteLine(i);
                    break;
                }

            }
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMP
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Int32.Parse(Console.ReadLine());
            Console.WriteLine(Run(input));
        }
        public static int Run(int a)
        {
            var inputNumber = a;
            var divider = a;

            for (var q = 1; q < inputNumber; q++)
            {
                if (inputNumber % divider != 0)//ищем делитель
                {
                    divider--;
                    continue;
                }
                string binaryCode = Convert.ToString(divider, 2);
                char[] charArray = binaryCode.ToArray();
                int[] intArray = Array.ConvertAll(charArray, c => (int)char.GetNumericValue(c));
                int middle = 0;
                //if (intArray.Length % 2 == 0)
                //{
                //    middle = intArray.Length / 2 +1;
                //}
                //else
                //{
                //    middle = intArray.Length / 2 + 1;
                //}
                if (intArray.Length % 2 == 0)
                {
                    divider--;
                    continue;
                }
                middle = intArray.Length / 2 + 1;
                if (middle == intArray.Length)
                {
                    divider--;
                    continue;
                }

                //if (intArray.Length == 4)
                //{
                //    divider--;
                //    continue;
                //}
                bool Ones = true;
                for (var i = 0; i < middle; i++)
                {
                    if (intArray[i] != 1)
                    {
                        Ones = false;
                        break;
                    }
                }
                if (!Ones)
                {
                    divider--;
                    continue;
                }

                bool Zeros = true;
                for (var j = intArray.Length - 1; j >= middle; j--)
                {
                    if (intArray[j] != 0)
                    {
                        Zeros = false;
                        break;
                    }
                }
                if (!Zeros)
                {
                    divider--;
                    continue;
                }

                return divider;

            }
            return divider;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      var n = input.ReadInt();
      for (int i = n; i > 0; i--)
      {
        if (isBeauty(i))
        {
          Console.Write(i);
          break;
        }
      }
    }

    private static bool isBeauty(int n)
    {
      var s = Convert.ToString(n, 2);
      var c1 = s.TakeWhile(c => c == '1').Count();
      var c0 = s.Skip(c1).TakeWhile(c => c == '0').Count();
      return c1 + c0 == s.Length && c1 == c0 + 1;
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }

    #region Service functions

    private static int GCD(int a, int b)
    {
      while (b != 0)
      {
        a %= b;
        int t = b;
        b = a;
        a = t;
      }
      return a;
    }

    #endregion
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(this.ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(this.ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;

public class Test
{
	public static void Main()
	{
		int l = int.Parse(Console.ReadLine());
		int k = 0;
		for(int x = 1;x<l+1;x++){
			if(((float)l/x)==(int)(l/x)){
				int ko = (int)(l/x);
				if(CheckPerfecto(ToByte(ko))==true){
					k = ko;
					Console.WriteLine("Fuck go back "+ToByte(ko));
					break;
				}
			}
		}

		Console.WriteLine(k);
	}

	public static string ToByte(int a){
		int ost = 2;
	//	int s = a;

		string o = "";
		string o2 = "";

		while(a>=2){
			int d=(int)(a/2);
			ost = a-(2*d);
			a=d;
			o+=""+ost;
		}
		o+=""+a;

		for(int x = o.Length-1;x>=0;x--){
			o2+=o[x];
		}

		return o2;
	}

	public static bool CheckPerfecto(string g){
		int zero = 0;
		int numb = 0;

		int len = g.Length;

		float numbcount = ((float)len-1)/2;

		if (numbcount-(int)numbcount==0) {
			if(Sum(g.Substring((int)numbcount+1,(int)numbcount))==0 && Sum(g.Substring(0,(int)numbcount+1))==(int)numbcount+1){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}

	public static int Sum(string g){
		int sum = 0;
		foreach(char a in g){
			sum+=int.Parse(a+"");
		}
		return sum;
	}
}

using System;

public class Test
{
	public static void Main()
	{
		int l = int.Parse(Console.ReadLine());
		int k = 0;
		for(int x = 1;x<l+1;x++){
			if(((float)l/x)==(int)(l/x)){
				int ko = (int)(l/x);
				if(CheckPerfecto(ToByte(ko))==true){
					k = ko;
					break;
				}
			}
		}

		Console.WriteLine(k);
	}

	public static string ToByte(int a){
		int ost = 2;
		int s = a;

		string o = "";
		string o2 = "";

		while(a>=2){
			int d=(int)(a/2);
			ost = a-(2*d);
			a=d;
			o+=""+ost;
		}
		o+=""+a;

		for(int x = o.Length-1;x>=0;x--){
			o2+=o[x];
		}

		return o2;
	}

	public static bool CheckPerfecto(string g){
		int zero = 0;
		int numb = 0;

		foreach(char a in g){
			if(a=='1'){ numb++; }
			if(a=='0'){ zero++; }
		}
		return (numb-1==zero);
	}
}

using System;
using System.Collections;
using System.IO;
using System.Runtime.CompilerServices;
using System.Linq;

namespace CSharp_Contests
{
    internal class Program
    {
        private static bool IsB(int number)
        {
            var bits = (new BitArray(new int[] {number})).OfType<bool>().Reverse().SkipWhile(a => a == false).ToArray();
            var ones = bits.TakeWhile(a => a).Count();
            var zeros = bits.Skip(ones).TakeWhile(a => a == false).Count();
            return ones + zeros == bits.Length && ones - 1 == zeros;
        }

        public static void Main()
        {
            int number = int.Parse(Console.ReadLine());
            int divisor = number;
            while (divisor > 1)
            {
                divisor = (int) Math.Ceiling(divisor / 2.0);
                if (IsB(divisor))
                {
                    Console.WriteLine(divisor);
#if DEBUG
                    Console.ReadLine();
#endif
                    return;
                }
            }
            Console.WriteLine('1');
#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}

using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Linq;

namespace CSharp_Contests
{
    internal class Program
    {
        private static bool IsB(int number)
        {

            var bits = (new BitArray(new int[] {number})).OfType<bool>().Reverse().SkipWhile(a => a == false).ToArray();
            var ones = bits.TakeWhile(a => a).Count();
            var zeros = bits.Skip(ones).TakeWhile(a => a == false).Count();
            return ones + zeros == bits.Length && ones - 1 == zeros;
        }

        public static void Main()
        {
            int number = int.Parse(Console.ReadLine());
            for (int i = number -1; i > 0; i--)
            {
                if (number %i == 0 && IsB(i))
                {
                    Console.WriteLine(i);
                    break;
                }
            }
#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}

using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Linq;

namespace CSharp_Contests
{
    internal class Program
    {
        private static int zeros, ones, number, mask = 0;

        public static void Main()
        {
            number = int.Parse(Console.ReadLine());

            for (int i = number; i > 0; i--)
            {
                if (number % i == 0)
                {
                    zeros = ones = 0;
                    mask = 1;
                    while ((i & mask) == 0)
                    {
                        zeros++;
                        mask <<= 1;
                    }
                    while ((i & mask) == mask)
                    {
                        ones++;
                        mask <<= 1;
                    }
                    if (ones == zeros + 1)
                    {
                        Console.WriteLine(i);
                        break;
                    }
                }
            }
#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }
        object Solve()
        {
            var n = ReadLong();
            for (var i = n / 2; i >= 1; i--)
            {
                if (n % i == 0)
                {
                    var k = 0;
                    var curr = i;
                    while (curr % 2 == 0)
                    {
                        curr >>= 1;
                        k++;
                    }
                    if (curr == (1 << (k + 1)) - 1)
                        return i;
                }
            }
            throw new Exception("huj");
        }
        long fastpow(long b, long x)
        {
            checked
            {
                if (x == 0)
                    return 1;
                if (x == 1)
                    return b;
                if (x % 2 == 0)
                    return fastpow(b * b % commonMod, x / 2);
                return b * fastpow(b, x - 1) % commonMod;
            }
        }
        int nod(int a, int b)
        {
            if (a < b)
                return nod(b, a);
            if (b == 0)
                return a;
            return nod(b, a % b);
        }

        class End
        {
            public long Val { get; set; }
            public bool Left { get; set; }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10)
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            //var i = s.IndexOf(' ');
            //return new[] { long.Parse(s.Substring(0, i)), long.Parse(s.Substring(i + 1)) };
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }

}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

namespace CodeforcesTemplate
{
    public static class Permutation
    {
        private static bool Next(ref int[] arr)
        {
            int k, j, l;
            for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }
            if (j == -1)
            {
                arr = arr.OrderBy(c => c).ToArray();
                return false;
            }
            for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }
            var tmp = arr[j];
            arr[j] = arr[l];
            arr[l] = tmp;
            for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)
            {
                tmp = arr[k];
                arr[k] = arr[l];
                arr[l] = tmp;
            }
            return true;
        }
        public static IEnumerable<int[]> AllPermutations(int[] arr)
        {
            do yield return arr;
            while (Next(ref arr));
        }
    }

    class Program
    {
        private const string FILENAME = "distance4";

        private const string INPUT = FILENAME + ".in";

        private const string OUTPUT = FILENAME + ".out";

        private static Stopwatch _stopwatch = new Stopwatch();

        private static StreamReader _reader = null;
        private static StreamWriter _writer = null;

        private static string[] _curLine;
        private static int _curTokenIdx;

        private static char[] _whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        private static string ReadNextToken()
        {
            if (_curTokenIdx >= _curLine.Length)
            {
                //Read next line
                string line = _reader.ReadLine();
                if (line != null)
                    _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    _curLine = new string[] { };
                _curTokenIdx = 0;
            }

            if (_curTokenIdx >= _curLine.Length)
                return null;

            return _curLine[_curTokenIdx++];
        }

        private static int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        private static void RunTimer()
        {
#if (DEBUG)

            _stopwatch.Start();

#endif
        }

        private static void Main(string[] args)
        {

#if (DEBUG)
            double before = GC.GetTotalMemory(false);
#endif

            int n = int.Parse(Console.ReadLine());

            List<int> del = new List<int>();

            for (int i = 1; i <= n; i++)
            {
                if (n % i == 0)
                {
                    del.Add(i);
                }
            }

            del.Reverse();

            foreach (int dig in del)
            {
                string binaryCode = Convert.ToString(dig, 2);

                int one = 0;

                int zero = 0;

                for (int i = 0; i < binaryCode.Length; i++)
                {
                    if(binaryCode[i] == '0')
                    {
                        zero++;
                    }

                    if(binaryCode[i] == '1')
                    {
                        one++;
                    }
                }

                if((one - 1) == zero)
                {
                    Console.WriteLine(dig);

                    return;
                }
            }

#if (DEBUG)
            _stopwatch.Stop();

            double after = GC.GetTotalMemory(false);

            double consumedInMegabytes = (after - before) / (1024 * 1024);

            Console.WriteLine($"Time elapsed: {_stopwatch.Elapsed}");

            Console.WriteLine($"Consumed memory (MB): {consumedInMegabytes}");

            Console.ReadKey();
#endif

        }

        private static int CountLeadZeros(string source)
        {
            int countZero = 0;

            for (int i = source.Length - 1; i >= 0; i--)
            {
                if (source[i] == '0')
                {
                    countZero++;
                }

                else
                {
                    break;
                }

            }

            return countZero;
        }

        private static string ReverseString(string source)
        {
            char[] reverseArray = source.ToCharArray();

            Array.Reverse(reverseArray);

            string reversedString = new string(reverseArray);

            return reversedString;
        }

        private static int[] CopyOfRange(int[] src, int start, int end)
        {
            int len = end - start;
            int[] dest = new int[len];
            Array.Copy(src, start, dest, 0, len);
            return dest;
        }

        private static string StreamReader()
        {

            if (_reader == null)
                _reader = new StreamReader(INPUT);
            string response = _reader.ReadLine();
            if (_reader.EndOfStream)
                _reader.Close();
            return response;

        }

        private static void StreamWriter(string text)
        {

            if (_writer == null)
                _writer = new StreamWriter(OUTPUT);
            _writer.WriteLine(text);

        }

        private static int BFS(int start, int end, int[,] arr)
        {
            Queue<KeyValuePair<int, int>> queue = new Queue<KeyValuePair<int, int>>();
            List<bool> visited = new List<bool>();
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                visited.Add(false);
            }

            queue.Enqueue(new KeyValuePair<int, int>(start, 0));
            KeyValuePair<int, int> node;
            int level = 0;
            bool flag = false;

            while (queue.Count != 0)
            {
                node = queue.Dequeue();
                if (node.Key == end)
                {
                    return node.Value;
                }
                flag = false;
                for (int i = 0; i < arr.GetLength(0); i++)
                {

                    if (arr[node.Key, i] == 1)
                    {
                        if (visited[i] == false)
                        {
                            if (!flag)
                            {
                                level = node.Value + 1;
                                flag = true;
                            }
                            queue.Enqueue(new KeyValuePair<int, int>(i, level));
                            visited[i] = true;
                        }
                    }
                }

            }
            return 0;

        }

        private static void Write(string source)
        {
            File.WriteAllText(OUTPUT, source);
        }

        private static string ReadString()
        {
            return File.ReadAllText(INPUT);
        }

        private static void WriteStringArray(string[] source)
        {
            File.WriteAllLines(OUTPUT, source);
        }

        private static string[] ReadStringArray()
        {
            return File.ReadAllLines(INPUT);
        }

        private static int[] GetIntArray()
        {
            return ReadString().Split(' ').Select(int.Parse).ToArray();
        }

        private static double[] GetDoubleArray()
        {
            return ReadString().Split(' ').Select(double.Parse).ToArray();
        }

        private static int[,] ReadINT2XArray(List<string> lines)
        {
            int[,] arr = new int[lines.Count, lines.Count];

            for (int i = 0; i < lines.Count; i++)
            {
                int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                for (int j = 0; j < lines.Count; j++)
                {
                    arr[i, j] = row[j];
                }
            }

            return arr;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace b
{
    class Program
    {
        static bool IsButifull(uint a) {
            bool checkingZeros = true;
            bool checkingOnes = false;
            int zeros = 0;
            int ones = 0;
            while(a > 0){
                if (checkingZeros) {
                    if ((a & 1) == 0){
                        zeros++;
                    }else {
                        checkingZeros = false;
                        checkingOnes = true;
                    }
                }
                if (checkingOnes) {
                    if ((a & 1) == 1) {
                        ones++;
                    }else {
                        return false;
                    }
                    if (ones - 1 > zeros) {
                        return false;
                    }
                }
                a = a >> 1;
            }
            return ones - 1 == zeros;
        }
        static IEnumerable<uint> GetButifulNumbers(uint n) {
            for (uint i=0;i<n;i++) {
                if (IsButifull(i))
                    yield return i;
            }
            yield break;
        }
        static void Main(string[] args)
        {
            var input = uint.Parse(Console.ReadLine());
            var gcdButiful = GetButifulNumbers(10000).ToList().Last(i => input%i == 0);

            Console.WriteLine(gcdButiful);
        }
    }
}

using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

public class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for(int i = n; i >= 1; i--)
		{
			string binary = Convert.ToString(i, 2);
			int q1 = 0;
			bool w1 = true;
			int q2 = 0;
			bool w2 = true;
			for(int j = 0; j < binary.Length; j++)
			{
				if(binary[j] == '1' && w1)
				{
					q1++;
				}
				else if(binary[j] == '0')
				{
					w1 = false;
					q2++;
				}
				else
				{
					w2 = false;
					break;
				}
			}
			if(w2)
				{
					if(q1 == q2+1)
					{
						Console.WriteLine(i);
						return;
					}
				}
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMP
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Int32.Parse(Console.ReadLine());
            Console.WriteLine(Run(input));
        }
        public static int Run(int a)
        {
            var InputNumber = a;
            var number = a;

            for (var q = 1; q < InputNumber; q++)
            {
                if (InputNumber % number != 0)
                {
                    number--;
                    continue;

                }
                string BinaryCode = Convert.ToString(number, 2);
                char[] charArray = BinaryCode.ToArray();
                int[] intArray = Array.ConvertAll(charArray, c => (int)Char.GetNumericValue(c));

                int middle = 0;
                if (intArray.Length % 2 == 0)
                {
                    middle = (intArray.Length / 2) + 1;
                }
                else
                {
                    middle = intArray.Length / 2 + intArray.Length % 2;
                }

                if (middle == intArray.Length)
                {
                    number--;
                    continue;
                }

                bool Ones = true;
                for (var i = 0; i < middle; i++)
                {
                    if (intArray[i] != 1)
                    {
                        Ones = false;
                        break;
                    }
                }
                if (!Ones)
                {
                    number--;
                    continue;
                }

                bool Zeros = true;
                for (var j = intArray.Length - 1; j >= middle; j--)
                {
                    if (intArray[j] != 0)
                    {
                        Zeros = false;
                        break;
                    }
                }
                if (!Zeros)
                {
                    number--;
                    continue;
                }

                return number;

            }
            return number;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMP
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Int32.Parse(Console.ReadLine());
            Console.WriteLine(Run(input));
        }
        public static int Run(int a)
        {
            var InputNumber = a;
            var number = a;

            for (var q = 1; q <= InputNumber - 1; q++)
            {
                if (InputNumber % number != 0)
                {
                    number--;
                    continue;

                }
                string BinaryCode = Convert.ToString(number, 2);
                char[] charArray = BinaryCode.ToArray();
                int[] intArray = Array.ConvertAll(charArray, c => (int)Char.GetNumericValue(c));

                int middle = intArray.Length / 2 + intArray.Length % 2;

                bool Ones = true;
                for (var i = 0; i <= middle; i++)
                {
                    if (intArray[i] != 1)
                    {
                        Ones = false;
                        break;
                    }
                }
                if (!Ones)
                {
                    number--;
                    continue;
                }

                bool Zeros = true;
                for (var j = intArray.Length - 1; j >= middle; j--)
                {
                    if (intArray[j] != 0)
                    {
                        Zeros = false;
                        break;
                    }
                }
                if (!Zeros)
                {
                    number--;
                    continue;
                }

                return number;

            }
            return number;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMP
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Int32.Parse(Console.ReadLine());
            Console.WriteLine(Run(input));
        }
        public static int Run(int a)
        {
            var number = a;

            for (var q = 1; q <= number; q++)
            {
                string BinaryCode = Convert.ToString(number, 2);
                char[] charArray = BinaryCode.ToArray();
                int[] intArray = Array.ConvertAll(charArray, c => (int)Char.GetNumericValue(c));

                int middle = intArray.Length / 2 + intArray.Length % 2;

                bool Ones = true;
                for (var i = 0; i <= middle; i++)
                {
                    if (intArray[i] != 1)
                    {
                        Ones = false;
                        break;
                    }
                }
                if (!Ones)
                {
                    number--;
                    continue;
                }

                bool Zeros = true;
                for (var j = intArray.Length - 1; j >= middle; j--)
                {
                    if (intArray[j] != 0)
                    {
                        Zeros = false;
                        break;
                    }
                }
                if (!Zeros)
                {
                    number--;
                    continue;
                }

                return number;

            }
            return number;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMP
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Int32.Parse(Console.ReadLine());
            Console.WriteLine(Run(input));
        }
        public static int Run(int a)
        {
            var InputNumber = a;
            var number = a;

            for (var q = 1; q < InputNumber; q++)
            {
                if (InputNumber % number != 0)
                {
                    number--;
                    continue;

                }
                string BinaryCode = Convert.ToString(number, 2);
                char[] charArray = BinaryCode.ToArray();
                int[] intArray = Array.ConvertAll(charArray, c => (int)Char.GetNumericValue(c));

                int middle = 0;
                if (intArray.Length % 2 == 0)
                {
                    middle = (intArray.Length / 2) + 1;
                }
                else
                {
                    middle = intArray.Length / 2 + intArray.Length % 2;
                }

                bool Ones = true;
                for (var i = 0; i < middle; i++)
                {
                    if (intArray[i] != 1)
                    {
                        Ones = false;
                        break;
                    }
                }
                if (!Ones)
                {
                    number--;
                    continue;
                }

                bool Zeros = true;
                for (var j = intArray.Length - 1; j >= middle; j--)
                {
                    if (intArray[j] != 0)
                    {
                        Zeros = false;
                        break;
                    }
                }
                if (!Zeros)
                {
                    number--;
                    continue;
                }

                return number;

            }
            return number;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMP
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Int32.Parse(Console.ReadLine());
            Console.WriteLine(Run(input));
        }
        public static int Run(int a)
        {
            var InputNumber = a;
            var number = a;

            for (var q = 1; q < InputNumber; q++)
            {
                if (InputNumber % number != 0)
                {
                    number--;
                    continue;

                }
                string BinaryCode = Convert.ToString(number, 2);
                char[] charArray = BinaryCode.ToArray();
                int[] intArray = Array.ConvertAll(charArray, c => (int)Char.GetNumericValue(c));

                int middle = 0;
                if (intArray.Length % 2 == 0)
                {
                    middle = (intArray.Length / 2) + 1;
                }
                else
                {
                    middle = intArray.Length / 2 + intArray.Length % 2;
                }

                if (middle == intArray.Length)
                {
                    number--;
                    continue;
                }
                if (intArray.Length == 4)
                {
                    number--;
                    continue;
                }
                bool Ones = true;
                for (var i = 0; i < middle; i++)
                {
                    if (intArray[i] != 1)
                    {
                        Ones = false;
                        break;
                    }
                }
                if (!Ones)
                {
                    number--;
                    continue;
                }

                bool Zeros = true;
                for (var j = intArray.Length - 1; j >= middle; j--)
                {
                    if (intArray[j] != 0)
                    {
                        Zeros = false;
                        break;
                    }
                }
                if (!Zeros)
                {
                    number--;
                    continue;
                }

                return number;

            }
            return number;
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Achill
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp = Console.ReadLine().Split().Select(item => Int32.Parse(item)).ToArray();
            String tmp = Convert.ToString(inp[0], 2), res = "", response ="";
            bool flag = false;
            res += "1";
            for (int i = 0; i < tmp.Length; ++i)
            {
                if (inp[0] > FromBinary(res))
                {
                    if(inp[0] % FromBinary(res) == 0)
                    {
                        response = res;
                    }
                    res = "1" + res;
                    res += "0";
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine(FromBinary(response));
            //Console.ReadKey();
        }

        static int FromBinary(string input)
        {
            int big = new int();
            foreach (var c in input)
            {
                big <<= 1;
                big += c - '0';
            }

            return big;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForceProblemSolve
{
    class B
    {

        public static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int m = 0;

            int i = 1;
            while (i <= n)
            {
               if(n % i == 0)
                {
                    string s = Convert.ToString(i, 2);

                    int zero = 0,one = 0;
                    for (int j = 0; j < s.Length; j++)
                    {
                        if(s[j] == '0')
                        {
                            zero++;
                        }
                        else
                        {
                            one++;
                        }
                    }
                    if ((one == zero + 1)) {
                        if (i > m)
                        {
                            m = i;
                        }
                    }

                }
                i++;
            }

            Console.WriteLine(m);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForceProblemSolve
{
    class B
    {

        public static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int m = 0;

            int i = 1;
            while (i <= n)
            {
                if (n % i == 0)
                {
                    string s = Convert.ToString(i, 2);

                    int zero = 0, one = 0;
                    for (int j = 0; j < s.Length; j++)
                    {
                        if (s[j] == '0')
                        {
                            zero++;
                        }
                        else
                        {
                            one++;
                        }
                    }
                    if ((one == zero + 1) && ( (Math.Pow(2,i)-1)*Math.Pow(2,i-1) == i))
                    {
                        if (i > m)
                        {
                            m = i;
                        }
                    }

                }
                i++;
            }

            Console.WriteLine(m);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForceProblemSolve
{
    class B
    {

        public static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int m = 0;

            int i = 1;
            while (i <= n)
            {
                if (n % i == 0)
                {
                    string s = Convert.ToString(i, 2);

                    int zero = 0, one = 0;
                    for (int j = 0; j < s.Length; j++)
                    {
                        if (s[j] == '0')
                        {
                            zero++;
                        }
                        else
                        {
                            one++;
                        }
                    }
                    if ((one == zero + 1)|| ( (Math.Pow(2,i)-1)*Math.Pow(2,i-1) == n))
                    {
                        if (i > m)
                        {
                            m = i;
                        }
                    }

                }
                i++;
            }

            Console.WriteLine(m);
        }
    }
}

// Problem: 893B - Beautiful Divisors
// Author: Gusztav Szmolik

using System;

class BeautifulDivisors
    {
    static int Main ()
        {
        string[] words = ReadSplitLine (1);
        if (words == null)
            return -1;
        uint n;
        if (!UInt32.TryParse (words[0], out n))
            return -1;
        if (n < 1 || n > 100000)
            return -1;
        uint ans = 0;
        for (ushort i = 1; i*i <= n && ans == 0; i++)
            {
            if (n%i > 0)
                continue;
            uint divisor = n/i;
            uint tmpConvBin = divisor;
            byte countZero = 0;
            byte countOne = 0;
            bool solved = true;
            bool procZero = true;
            while (tmpConvBin > 0 && solved)
                {
                byte digitBin = Convert.ToByte (tmpConvBin%2);
                tmpConvBin /= 2;
                if (digitBin == 0)
                    {
                    if (procZero)
                        countZero++;
                    else
                        solved = false;
                    }
                else
                    {
                    if (procZero)
                        {
                        procZero = false;
                        countOne = 1;
                        }
                    else
                        {
                        countOne++;
                        if (countOne > countZero+1)
                            solved = false;
                        }
                    }
                }
            if (solved && countOne == countZero+1)
                ans = divisor;
            }
        Console.WriteLine (ans > 0 ? ans : 1);
        return 0;
        }

    static string[] ReadSplitLine (uint numWordNeed)
        {
        string line = Console.ReadLine ();
        if (line == null)
            return null;
        char[] delims = new char[2] {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        return (words.Length == numWordNeed ? words : null);
        }
    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Beautiful_Divisors
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            for(int i=n;i>0;i--)
            {
                string binary = Convert.ToString(i, 2);
                int ones = 0;
                int zeroes = 0;
                bool flag = false;
                bool correct = true;
                int count = 0;
                while(count!=binary.Length)
                {
                    if (!flag)
                    {
                        if(binary[count]=='1')
                        {
                            ones++;
                            count++;
                        }
                        else
                        {
                            zeroes++;
                            flag = true;
                            count++;
                        }
                    }
                    else
                    {
                        if(binary[count]=='0')
                        {
                            zeroes++;
                            count++;
                        }
                        else
                        {
                            correct = false;
                            break;
                        }
                    }
                }
                if(correct&&ones-1==zeroes)
                {
                    Console.WriteLine(i);
                    break;
                }

            }
            //Console.ReadKey();
        }
    }
}