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

using namespace std;

int bitpref[1000000+6];

int bsearch(int x){
    int l=1,p=1000000,s;
    while(l<p){
        s = (l+p)/2;
        if(bitpref[s]>=x){
            p=s;
        }
        else{
            l=s+1;
        }
    }
    return l;
}
vector<int> ret;

int main(){
    /* cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0); */

    int n;
    cin>>n;
    for(int i=1;i<=1000003;i++){
        bitpref[i] = bitpref[i-1]+__builtin_popcount(i);
    }
    int k;
    while(n>0){
        k = bsearch(n);
        ret.push_back(k);
        n-=__builtin_popcount(k);
    }
    cout<<ret.size()<<'\n';
    reverse(ret.begin(),ret.end());
    while(ret.size()){
        cout<<ret.back()<<' ';
        ret.pop_back();
    }

    return 0;
}