#pragma GCC target ("avx2") // #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include using namespace std; using ll=long long; template using V = vector; template using P = pair; using vll = V; using vii = V; using vvll = V; using vvii = V< V >; using PII = P; using PLL = P; #define RevREP(i,n,a) for(ll i=n;i>a;i--) // (a,n] #define REP(i,a,n) for(ll i=a;i inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; } template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; } #define DEBUG_VLL(vec) for(int sz=0;sz> d; ll ans = 0; int maxb = 0; while (d > 0) { ll tmp = 0, bit = 0; while (tmp <= d - (1LL << bit)) tmp += (1LL << bit++); chmax(maxb, int(bit)); if ((tmp << 1LL) == d) { ans += (1LL << bit); if (maxb - bit <= 1) ans += 1; break; } else { d -= tmp; ans += (1LL << (bit - 1)); } } cout << ans << '\n'; return 0; }