#pragma region library #if defined(__GNUC__) && !defined(__llvm__) && !defined(__clang__) #pragma GCC optimize("O3") #pragma GCC target("avx512f") #pragma GCC optimize("unroll-loops") #include #endif #if __has_include() #include #endif #pragma region #define itrall(x) std::begin(x), std::end(x) #define rep32(i, l, r) for (int i = (int)(l); (i) < (int)(r); ++(i)) #define rep64(i, l, r) for (long long i = (long long)(l); i < (long long)(r); ++(i)) #define revrep32(i, r, l) for (int i = (int)(r); (i) >= (int)(l); --(i)) #define revrep64(i, r, l) for (long long i = (long long)(r); i >= (long long)(l); --(i)) using u32 = unsigned int; using usize = size_t; using index_t = size_t; using i64 = long long; using u64 = unsigned long long; constexpr size_t operator "" _uz(unsigned long long v) { return static_cast(v); } template using Heap = std::priority_queue; template using RevHeap = std::priority_queue, std::greater>; template using SHeap = std::priority_queue, F>; constexpr int dx[] = { 1, 0, -1, 0 }; constexpr int dy[] = { 0, 1, 0, -1 }; constexpr int INF32 = 1001001001; constexpr long long INF64 = 1501501501501501501ll; constexpr int mod = 1000000007; constexpr int mod2 = 998244353; #pragma endregion template > constexpr bool chmin(T& xmin, const U& x, Comp comp = {}) noexcept { return comp(x, xmin) ? xmin = x, true : false; } template > constexpr bool chmax(T& xmax, const U& x, Comp comp = {}) noexcept { return comp(x, xmax) ? xmax = x, true : false; } template constexpr type len(const T& v) noexcept { return (type)(v.size()); } namespace nlb { template constexpr T Pow(T A, U B) { T res = 1; while (B) { if (B & 1) { res *= A; } A *= A; B >>= 1; } return res; } template constexpr T modpow(T A, U B, M MOD = 1000000007) { A %= MOD; T res = 1; while (B) { if (B & 1) { res *= A; res %= MOD; } A *= A; A %= MOD; B >>= 1; } return res; } template constexpr T inverse(T A, const M MOD = 1000000007) { T B = MOD, U = 1, V = 0; while (B) { T t = A / B; A -= t * B; std::swap(A, B); U -= t * V; std::swap(U, V); } U %= MOD; return U < 0 ? U += MOD, U : U; } template constexpr T gcd(T A, T B) { while (B) { const T C = A; A = B; B = C % B; } return A; } template constexpr T lcm(const T A, const T B) { return A / gcd(A, B) * B; } template constexpr bool isprime(const T N) { if (N == 1) return false; for (T i = 2; i * i <= N; i++) if (N % i == 0) return false; return true; } inline std::tuple extgcd(const long long a, const long long b) { if (b == 0) return { a,1,0 }; long long g, x, y; std::tie(g, x, y) = extgcd(b, a % b); return std::make_tuple(g, y, x - a / b * y); } inline std::pair Chinese_Rem(const std::vector& b, const std::vector& m) { long long r = 0, M = 1; for (int i = 0; i < (int)b.size(); ++i) { long long p, q, d; std::tie(d, p, q) = extgcd(M, m[i]); if ((b[i] - r) % d != 0) return std::make_pair(0, -1); long long tmp = (b[i] - r) / d * p % (m[i] / d); r += M * tmp; M *= m[i] / d; } return std::make_pair((r % M + M) % M, M); } } class ProCon_all_init { static constexpr bool float_fixed = true; static constexpr int ios_perc = 15; static constexpr bool ios_fast = true; static constexpr bool auto_flush = false; public: ProCon_all_init() { if (ios_fast) { std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); } if (float_fixed) { std::cout << std::fixed << std::setprecision(ios_perc); } if (auto_flush) { std::cout << std::unitbuf; } } } ProCon_; #pragma endregion class Problem { public: void solve() { i64 N; std::cin >> N; std::vector Score; while (N != 0) { Score.emplace_back(N); N /= 2; } i64 Answer = 0; rep32(i, 0, len(Score)) { i64 sum = 0; rep32(j, 0, i) sum += Score[i]; sum += Score[i] * 2; chmax(Answer, sum); } std::cout << Answer - std::accumulate(itrall(Score), 0ll) << std::endl; } }; int main(void) { Problem solver; solver.solve(); }