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
#include <cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<set>
#include<map>
#include<queue>

using namespace std;

const int M = 1e6;
int t[M + 7];
int t2[M + 7];

int number_of_bits(int x) {
    int res = 0;
    while (x) {
        res += x & 1;
        x >>= 1;
    }
    return res;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n; cin >> n;
    int num = 0;
    for(int i = 1; i < M; i ++) {
        int x = number_of_bits(i);
        t2[i] = x;
        t[i] = t[i - 1] + x;
        num = i;
        if(t[i] >= n) break;
    }
    vector<int> res;
    while(num) {
        if(t[num - 1] < n) {
            res.push_back(num);
            n -= t2[num];
        }
        num --;
    }
    cout << res.size() << endl;
    for(auto x: res)
        cout << x << " ";
    return 0;
}