using static System.Math; using System; public class Hello { static void Main() { var x = long.Parse(Console.ReadLine().Trim()); getAns(x); } static void getAns(long x) { var imin = Max(0, x - 60); var imax = x + 60; for (long i = imin; i <= imax; i++) { var bc = bitCount((ulong)i); var chk = i ^ bc; if (chk == x) { Console.WriteLine(i); return; } } Console.WriteLine(-1); } static int bitCount(ulong bits) { bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555); bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333); bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f); bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff); bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff); return (int)(bits & 0x00000000ffffffff) + (int)(bits >> 32); } }