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
28
29
30
31
32
33
import sys

bits = [0, 1]
totals = [0, 1]
MAX = int(sys.stdin.readline())
p2 = 2

while True:
    for i in range(p2):
        bits.append(bits[i] + 1)
        totals.append(totals[-1] + bits[-1])
    if totals[-1] > MAX:
        break
    p2 *= 2

# print(bits)
# print(totals)

result = []
to_produce = MAX
n = len(bits)

while True:
    n -= 1
    if to_produce <= totals[n] - bits[n]:
        continue
    result.append(n)
    to_produce -= bits[n]
    if to_produce == 0:
        break

print(len(result))
print(" ".join(str(x) for x in result))