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

#define ll long long
#define fors(u, n, s) for(ll u=(s); u < (n); u++)
#define foru(u, n) fors(u, n, 0)
#define ir(a, b, x) (((a) <= (x)) && ((x) <= (b)))
#define vec vector
#define pb push_back

using namespace std;

vec<int> max_power;

vec<int> ans;

int main()
{
    int n; cin >> n;

    max_power.pb(0);

    int pnt=1;

    while(true){
        max_power.pb(max_power[pnt-1] + __builtin_popcount(pnt));
        if(max_power[pnt]>=n) break;
        pnt++;
    }

    while(n!=0){
        if(ir(max_power[pnt-1]+1, max_power[pnt], n)){
            n -= __builtin_popcount(pnt);
            ans.pb(pnt);
        }
        pnt--;
    }

    cout << ans.size() << endl;
    for(auto i : ans) cout << i << " ";

    return 0;
}