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
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
import typing
import collections


def _debug(*args):
    print(*args, file=sys.stderr)


def count_bits_set(x: int) -> int:
    return bin(x).count('1')


def solve(n: int) -> typing.Sequence[int]:
    out = collections.deque()
    i = 1
    while True:
        c = count_bits_set(i)
        n -= c
        if n >= 0:
            out.appendleft(i)
            if n == 0:
                return out
        else:
            for j, el in enumerate(out):
                if n + count_bits_set(el) == 0:
                    del out[j]
                    break
            out.appendleft(i)
            return out
        i += 1


def main():
    readline = sys.stdin.readline
    write = sys.stdout.write
    n = int(readline().strip())
    result = solve(n)
    write(f'{len(result)}\n')
    for item in result:
        write(f'{item} ')
    sys.stdout.flush()


if __name__ == '__main__':
    main()