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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    // prepare tab
    vector<int>X{0, 1, 2, 4, 5, 7};
    while (X.back() < n)
        X.push_back(X.back() + __builtin_popcount(X.size()));

    // get result
    vector<int>R;
    while (n) {
        int p = lower_bound(X.begin(), X.end(), n) - X.begin();
        R.push_back(p);
        n -= __builtin_popcount(p);
    }

    // print
    cout << R.size() << "\n";
    for (int x : R)
        cout << x << " ";
    cout << "\n";


    return 0;
}