import std.stdio; import std.conv, std.array, std.algorithm, std.string; import std.math, std.random, std.range, std.datetime; import std.bigint; void main(){ int n = readln.chomp.to!int; int[] dp; dp.length = n + 1; foreach(i; 0 .. (n + 1)) dp[i] = -1; dp[1] = 1; int[] q = [1]; while(q.length){ int i = q[0]; q = q[1 .. $]; int d; for(int j = i; j > 0; j /= 2) if(j % 2 > 0) d += 1; if(i - d >= 1 && dp[i - d] < 0){ dp[i - d] = dp[i] + 1; q ~= i - d; } if(i + d <= n && dp[i + d] < 0){ dp[i + d] = dp[i] + 1; q ~= i + d; } } dp[n].writeln; }