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
def count2bin(n):
    count = 0
    while n > 0:
        count += n % 2
        n //=2
    return count
a = int(input())
sumDigit = 0
i = 0
while sumDigit < a:
    i += 1
    sumDigit += count2bin(i)
count = i
lista = [True] * (i+1)
while sumDigit > a:
    d1 = count2bin(i)
    if sumDigit - d1  == a:
        count -=1
        lista[i] = False
        break
    if sumDigit - d1 > a:
        sumDigit -= d1
        count -=1
        lista[i] = False
        
    i -=1

print(count)
for j in range(len(lista)-1,0,-1):
    if lista[j]:
        print(j,end=" ")