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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define loopr(i,x,n) for(ll i = n-1;i>=x;i--)
#define all(v) v.begin(),v.end()
#define print(v) for(auto xx : v){cout<<xx<<" ";}cout<<endl;
#define debug if(DEBUG) cout 
#define ff first
#define ss second
const ll Mod = 1E9+7, L = 1E18, N = 1E6+9;


#ifdef ONLINE_JUDGE
bool DEBUG = false;
#else
bool DEBUG = true;
#endif

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

    int n;
    cin >> n;
    vector<int> v, ans;

    int i = 1, sum = 0;
    while (sum <= n) {
        sum += __builtin_popcount(i);
        v.push_back(i++);
    }
    bool ok = false;
    for(int i = v.size()-1;i >= 0;i--){
        if (ok) ans.push_back(v[i]);
        else if (sum - __builtin_popcount(v[i]) == n) {
            ok = true;
            continue;
        }
        else ans.push_back(v[i]);
    }
    cout << ans.size() << '\n';
    print(ans);
}