1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from sys import stdin, stdout

def get_bit_power(k: int) -> int:
    s = format(k, "b")
    return sum([c=="1" for c in s])

n = int(stdin.readline())

total = 0
first = 0
while total < n:
    first += 1
    total += get_bit_power(first)

melody = list(range(first, 0, -1))
remove_idx = 0

while total > n:
    idx_power = get_bit_power(melody[remove_idx])
    if (total-idx_power>=n):
       del melody[remove_idx]
       total -= idx_power
    else:
        remove_idx += 1

stdout.write(str(len(melody))+"\n")
stdout.write(" ".join([str(x) for x in melody])+"\n")