#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';
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgaW50IGxvbmcgbG9uZwoKc2lnbmVkIG1haW4oKSB7CiAgICBpbnQgbiA9IDYxNzQsIHJlcyA9IDA7CiAgICBmb3IgKGludCBpID0gMDsgKDFMTCA8PCBpKSA8PSBuOyBpKyspIHsKICAgICAgICBpbnQgeCA9IG4gLyAoMUxMIDw8IGkpOwogICAgICAgIGludCBrID0gKHggKyAxKSAvIDI7CiAgICAgICAgcmVzICs9IGsgKiBrOwogICAgfQogICAgY291dCA8PCByZXMgPDwgJ1xuJzsKfQ==