1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import sys

n = int(sys.stdin.readline())
bitcounts = [bin(i).count("1") for i in range(120207)]
max_with_bits = [0] * 17
total = 0
solution = []
i = 0
while total < n:
    i += 1
    max_with_bits[bitcounts[i]] = i
    solution.append(i)
    total += bitcounts[i]
if total > n:
    solution.remove(max_with_bits[total-n])
solution.reverse()
print(len(solution))
print(' '.join([str(e) for e in solution]))