#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    int n = 6174, res = 0;
    for (int i = 0; (1LL << i) <= n; i++) {
        int x = n / (1LL << i);
        int k = (x + 1) / 2;
        res += k * k;
    }
    cout << res << '\n';
}