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

int main() {
    std::ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int f = 1, first[n+1] = {0,};
    for (int i = 1; i <= n; ++i) {
        while (1) {
            int b = i - __builtin_popcount(f);
            if (first[b] < f) break;
            f += 1;
        }
        first[i] = f;
    }
    vector<int> ret;
    while (n > 0) {
        ret.push_back(first[n]);
        n -= __builtin_popcount(first[n]);
    }
    cout << ret.size() << endl;
    cout << ret[0];
    for (int j = 1; j < ret.size(); j++) cout << ' ' << ret[j];
    cout << endl;
}