#include using namespace std; #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define rep(i, n) repl(i, 0, n) #define CST(x) cout << fixed << setprecision(x) using ll = long long; constexpr ll MOD = 1000000007; constexpr int inf = 1e9 + 10; constexpr ll INF = (ll)4e18 + 10; constexpr int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; constexpr int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector vec; ll p = 1; while (n) { if (n % 2) vec.push_back(p); p *= 2, n /= 2; } ll x = 1LL << (ll)vec.size(); x = (x + 1) / 2; ll ans = 0; rep(i, (ll)vec.size()) { if (x >> i & 1) ans += vec[i]; } cout << ans << endl; return 0; }