#include using namespace std; int main() { long long N; cin >> N; vector T; while (N) { T.push_back(N); N /= 2; } int T_N = T.size(); vector sum(T_N + 1); for (int i = 1; i <= T_N; i++) { sum[i] = sum[i - 1] + T[i - 1]; } unsigned long long Max = 0; unsigned long long S = sum[T_N]; for (int i = 0; i < T_N; i++) { Max = max(Max, sum[i] + (sum[i + 1] - sum[i]) * 2); } cout << Max - S; }