#include #define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME #define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <; template T Max(T &a,T b){return a=max(a,b);} template T Min(T &a,T b){return a=min(a,b);} template ostream& operator<<(ostream& o,pair p){return o<<"("< ostream& operator<<(ostream& o,tuple t){ return o<<"("<(t)<<","<(t)<<","<(t)<<")";} template istream& operator>>(istream& i,pair &p){return i>>p.first>>p.second;} template ostream& operator<<(ostream& o,vector a){Int i=0;for(T t:a)o<<(i++?" ":"")< istream& operator>>(istream& i,vector &a){for(T &t:a)i>>t;return i;} //INSERT ABOVE HERE Int bfs(Int N){ vector D(N+1, INF); queue Q; Q.push(1); D[1] = 1; while(!Q.empty()){ Int num = Q.front(); Q.pop(); Int cost = D[num]; if(num == N) return cost; Int v = __builtin_popcount(num); for(Int i=-1;i<=1;i++){ if(i == 0) continue; Int nnum = num + v * i; Int ncost = cost + 1; if(nnum < 0 || nnum > N || D[nnum] <= ncost) continue; D[nnum] = ncost; Q.push(nnum); } } return -1; } signed main(){ srand((unsigned)time(NULL)); cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); Int N; cin>>N; Int ans = bfs(N); cout<