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
#include<iostream>
#include <vector>

using namespace std;

int bits(int n) {
    int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
	}
    return count;
}


int main() {
    int n = 0;

    int s = 0;
    int l = 0;
	cin >> n;
    while (s < n) {
        l+=1;
        s+= bits(l);
	}
    int nad = s-n;
    vector<int> wyn;
    for (int el=l; el >=0; el--) {
        if (bits(el) > nad)
            wyn.push_back(el);
        else
            nad-=bits(el);
	}
	cout << wyn.size() << "\n";
    for (auto el: wyn)
        cout << el << " ";
    cout << "\n";
}