def chop(n) count = 0 base = 1 while n > base if n > base * 2 base <<= 1 count += 1 else break end end count end n = gets.to_i count = 0 while n > 1 if n > 1 c = chop(n) n -= 1 << c count += c end end puts count