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
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define cln cout<<"\n---------------\n"
using namespace std;

constexpr int N = 1e6+7;
constexpr int MOD = 1e9+7;
int T[N], P[N];


void solve () {
    vector <int> v;
    int n; cin>>n;
    for (int i=1; i<N; ++i) {
        T[i] = __builtin_popcount(i);
        P[i] = P[i-1] + T[i];
    }
    for (int i=N-1; i>=0; --i) {
        if (P[i] < n) {
            v.pb(i+1);
            n -= T[i+1];
        }
    }
    cout<<v.size()<<'\n';
    for (auto x : v) {
        cout<<x<<' ';
    }
}


int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; t = 1;
    while (t--) {
        solve();
    }
    return 0;
}