#include #define rep(i,n) for (int i=0; i < (int)(n); i++) #define all(c) c.begin(), c.end() using namespace std; typedef long long ll; typedef long double ld; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; int main() { ios::sync_with_stdio(0); cin.tie(0); //入出力高速化 int N; cin>>N; vi A(N+1, -1); A[0] = 0; A[1] = 1; queue Q; Q.push(1); while(!Q.empty()) { int i = Q.front(); Q.pop(); int p = __builtin_popcount(i); int f = i + p, b = i - p; if(f <= N && A[f] == -1) { A[f] = A[i] + 1; Q.push(f); } if(1 < b && A[b] == -1) { A[b] = A[i] + 1; Q.push(b); } } cout<