N= int(input())

def b(N):
    if N < 2:
        res = N
    else:
        if N % 2 == 0:
            res = b(N//2)
        else:
            res = b( (N-1)//2 ) + b( (N+1)//2 )
    return res
def a(N):
    if N > 0:
        res = a(N-1)
    else:
        res = 0
    return res + b(N+1)

print(a(N))