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
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    int x = 1;
    while(sum < n) {
        sum += __builtin_popcount(x);
        x++;
    }
    x--;

    vector<int> ans;
    while(sum != n) {
        if(sum - __builtin_popcount(x) >= n) sum -= __builtin_popcount(x);
        else ans.push_back(x);
        x--;
    }

    while(x) {
        ans.push_back(x);
        x--;
    }

    cout << ans.size() << '\n';
    for(auto a: ans) cout << a << ' ';

    return 0;
}