#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>n; vector dp(n+1,-1); queue q; dp[1]=1; q.emplace(1); while(!q.empty()){ Int v=q.front();q.pop(); Int x=__builtin_popcount(v); if(v-x>0&&dp[v-x]<0){ dp[v-x]=dp[v]+1; q.emplace(v-x); } if(v+x<=n&&dp[v+x]<0){ dp[v+x]=dp[v]+1; q.emplace(v+x); } } cout<