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
47
48
49
50
51
52
#include<iostream>
#include<vector>

int count(int x) {
    int res = 0;
    while (x > 0) {
        if (x & 1) {
            res++;
        }
        x >>= 1;
    }
    return res;
}

int T[1000005];

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n;
    std::cin >> n;

    T[0] = 0;
    int k = 1;
    int i = 1;
    while (i <= n) {
        int c = count(k);
        for (int j = 0; j < c && j + i <= n; j++) {
            T[i + j] = k;
        }
        i += c;
        k ++;
    }

    // for (int i = 0; i <= n; i++) {
    //     std::cout << i << " " << T[i] << "\n";
    // }

    std::vector<int> v;
    while (n > 0) {
        v.push_back(T[n]);
        n -= count(T[n]);
    }

    std::cout << v.size() << "\n";
    for (int x: v) {
        std::cout << x << " ";
    }

    return 0;
}