Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of *n* vertices numbered from 0 to *n* - 1. For all 0 ≤ *u* &lt; *v* &lt; *n*, vertex *u* and vertex *v* are connected with an undirected edge that has weight <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b1dd244036db71efcfe46a5cd4ba74e2bd3f2935.png" style="max-width: 100.0%;max-height: 100.0%;"/> (where <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c4b7092c0f7ce6535f2574569c98f7b3c2fe2c5f.png" style="max-width: 100.0%;max-height: 100.0%;"/> is the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)). Can you find the weight of the minimum spanning tree of that graph?

You can read about complete graphs in [https://en.wikipedia.org/wiki/Complete_graph](https://en.wikipedia.org/wiki/Complete_graph)

You can read about the minimum spanning tree in [https://en.wikipedia.org/wiki/Minimum_spanning_tree](https://en.wikipedia.org/wiki/Minimum_spanning_tree)

The weight of the minimum spanning tree is the sum of the weights on the edges included in it.
The only line contains an integer *n* (2 ≤ *n* ≤ 10<sup class="upper-index">12</sup>), the number of vertices in the graph.
In the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/20e1655a0ec8e8d788bd2f5af92f93c968c65f3c.png" style="max-width: 100.0%;max-height: 100.0%;"/> The weight of the minimum spanning tree is 1+2+1=4.
4
4
10
21
2
1
1000000000000
20140978692096
999999999999
20140978692095
23131234
293058929
100000
877968
1024
5120
536870912
7784628224
536870911
7784628223
536870913
8321499136
123456789
1680249144
200
844
3
3
5
8
6
9
7
11
1000
5052
12000
84624
65536
524288
1048576
10485760
8
12
549755813888
10720238370816
549755813887
10720238370815
549755813889
11269994184704
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: Jalpaiguri Govt Enggineering College

'''
from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,Counter,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('0')

file = 1
def ceil(a,b):
    return (a+b-1)//b

'''

The tree will be look like...........


            0

    1 2  4       8   16 32 64 128 ......
  1/   1/2\    1/2|4\
     3  5  6  9 10  11
           1\
             7



so, the answer will be number of element having lsb is ith bit * 2^i for all i.
lsb(x) = x&(-x)
lsb(6) = 110 = 1th bit from right


Now, count how many number having lsb is 1
let's take some number havint lsb is 1 -> 2 6 10 14 18 22 .... -> a = 2 & d = 4(in A.P series)

similar for lsb = 2
4 12 20 28 ....-> a = 4 & d = 8

for lsb = i the series will be 2^i,(2^i + 2^(i+1)),[2^i + 2^(i+1) + 2^(i+1)].....

but stil we don't know in ith series how many number has?

let's assume the number will be ...t

so, n >= a + (t-1)*d 

=> n >= 2^i + (t-1)*2^(i+1) 
=> n >= 2^i[1 + 2t - 2] 
=> n/x <= 2t+1   (where x = 2^i)
=> (n-x)/x <= 2t
=> (n-x)/2*x <= t

t = (n-x)/2*x + 1

'''


def solve():

    
    # for _ in range(1,ii()+1):
        res = 0
        n = ii()
        n-=1
        for i in range(40):
            x = pow(2,i)
            t = (n-x)//(2*x) + 1
            if t>=0:
                res += (t*x)
        print(res)
        
if __name__ =="__main__":

    if(file):
    
       if path.exists('input.txt'):
           sys.stdin=open('input.txt', 'r')
           sys.stdout=open('output.txt','w')
       else:
           input=sys.stdin.readline
    solve()
