#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; using P = pair; priority_queue, greater

> q; auto dist= [&](Int x){ Int res=n+(1<<15); for(Int i=0;i<20;i++) if((x<=n) chmin(res,(x< dp; dp[1]=0; q.emplace(dist(1),1); while(!q.empty()){ Int x=q.top().second;q.pop(); if(x==n) break; if(!dp.count(x*2)||dp[x*2]>dp[x]+1){ dp[x*2]=dp[x]+1; q.emplace(dp[x*2]+dist(x*2),x*2); } if(!dp.count(x-1)||dp[x-1]>dp[x]+1){ dp[x-1]=dp[x]+1; q.emplace(dp[x-1]+dist(x-1),x-1); } } cout<