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

using namespace std;


#ifdef USE_FILE_CIN
ifstream input("muz.in");
#define cin input
#endif


vector<int> bitCounts;

int computeCounts(int n) {
    bitCounts.reserve(130000);
    int sum = 0, cnt;

    for (int i = 0; sum < n; i++) {
        cnt = __builtin_popcount(i);
        bitCounts.push_back(cnt);
        sum += cnt;
    }

    return sum;
}

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

    int reqSum;
    
    cin >> reqSum;
    int totalSum = computeCounts(reqSum);
    
    vector<int> result;
    result.reserve(bitCounts.size());

    for (int i = bitCounts.size(); i>=0; i--) {
        if (totalSum - bitCounts[i] < reqSum) {
            result.push_back(i);
        } else {
            totalSum -= bitCounts[i];
        }
    }
    
    cout << result.size() << '\n';
    for (int num : result) cout << num << ' ';


    return 0;
}