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