#include #include #include #include using namespace std; int bit[10001]; int dist[100001]; inline int countbit(int n){ int cnt=0; while(n){ if(n&1)cnt++; n>>=1; } } int main(void){ int N; cin>>N; for(int i=0;i<=N;i++){bit[i]=countbit(i);dist[i]=-1;} queue que; dist[1]=1; que.push(1); while(que.empty()==false){ int v=que.front();que.pop(); if(v-bit[v]>0&&dist[v-bit[v]]==-1){ dist[v-bit[v]]=dist[v]+1; que.push(v-bit[v]); } if(v+bit[v]<=N&&dist[v+bit[v]]==-1){ dist[v-bit[v]]=dist[v]+1; que.push(v+bit[v]); } } cout<