import sequtils,strutils proc cnt(n : int64) : int64 = if n < 2: return 0 var p = 1 while p * 2 + 1 <= n: p = p * 2 + 1 if p == n: return 0 return p + 1 - (n - p) + cnt(n - p - 1) * 2 var N = stdin.readline.parseBiggestInt echo cnt(N)