def each_exp(num) current = num Enumerator.new {|y| while current > 0 y << current r,m = current.divmod(2) current = r end } end n = gets.to_i puts n * 2 - each_exp(n).inject(0,&:+)