n = gets.to_i count = 0 i = 0 while n > 0 count += i+1 if n%2 == 1 n >>= 1 end puts count