using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; class Program { static int K = 18; static int MaxLeftBits = 40 - K; public void Solve() { long N = Reader.Long(); var count = new int[MaxLeftBits + 1, 64]; var diff = new long[MaxLeftBits + 1, 64]; var sw = Stopwatch.StartNew(); for (int bits = 0; bits <= MaxLeftBits; bits++) for (int mod = 0; mod < 64; mod++) { if (bits == 0 && mod == 0) continue; int x = mod; while (x < (1 << K)) { x += bits + BitCount32(x); count[bits, mod]++; } diff[bits, mod] = x - mod; } long ans = 1; long i = 1; for (int left = 0; left < N / (1 << K); left++) { ans += count[BitCount32(left), i % 64]; i += diff[BitCount32(left), i % 64]; } while (i < N) { ans++; i += BitCount64(i); } Console.WriteLine((i == N) ? ans : -1); } static int BitCount32(int x) { x -= x >> 1 & 0x55555555; x = (x & 0x33333333) + (x >> 2 & 0x33333333); return ((x + (x >> 4) & 0x0f0f0f0f) * 0x01010101) >> 24; } static int BitCount64(long x) { x -= x >> 1 & 0x5555555555555555; x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333); return (int)((x + (x >> 4) & 0x0f0f0f0f0f0f0f0f) * 0x0101010101010101 >> 56); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { private static TextReader reader = Console.In; private static readonly char[] separator = { ' ' }; private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; private static string[] A = new string[0]; private static int i; private static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); } public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); } public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Next()).ToArray(); } public static string Line() { return reader.ReadLine().Trim(); } private static string[] Split(string s) { return s.Split(separator, op); } private static string Next() { CheckNext(); return A[i++]; } private static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }