#include #include #include #include using namespace std; using namespace atcoder; using namespace __gnu_pbds; using ll=long long; using ld=long double; using vll=vector; using vvll=vector; using pll=pair; // using mint=modint; // template // using ordered_map=tree,rb_tree_tag,tree_order_statistics_node_update>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin>>N; vll dist(N+1,-1); queueq; dist[1]=1; q.push(1); while(!q.empty()){ ll u=q.front(); q.pop(); ll d=__builtin_popcount(u); ll l=u-d,r=u+d; if(l>=1&&dist[l]==-1){ dist[l]=dist[u]+1; q.push(l); } if(r<=N&&dist[r]==-1){ dist[r]=dist[u]+1; q.push(r); } } cout<