#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using Graph = vector>; using ll = long long; typedef pair P_ll; typedef pair P; const ll INF_ll = 1e17; const int INF = 1e8; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template using min_priority_queue = priority_queue, greater>; int main() { ll D; cin >> D; ll l = 0; ll r = D + 1; while (r - l > 1) { ll mid = (r + l) / 2; ll now = 0; ll x = mid; while (x > 0) { now += x; x /= 2; } if (now >= D) { r = mid; } else { l = mid; } } // cout << r << " " << l << endl; for (ll x = r; x <= r + 100000; x++) { ll y = x; ll now = 0; while (y > 0) { now += y; y /= 2; if (now == D) { cout << x << endl; return 0; } } } cout << D << endl; return 0; }