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
#include <bits/stdc++.h>
#define ss second
#define ff first
#define pb push_back
#define ll long long

//Igor Rostkowski


using namespace std;

int n,pop;
int sp[1000000];
vector <int> v;

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

    cin>>n;

    for(int i=1;pop<=1000000;i++)
    {
        sp[i]=pop+__builtin_popcount(i);
        pop+=__builtin_popcount(i);
        //cout<<i<<"\n";
    }

    for(int i=120205;i>=0;i--)
    {
        if(sp[i]<n)
        {
            v.pb(i+1);
            n-=__builtin_popcount(i+1);
            //cout<<i+1<<" "<<n<<"\n";
        }
    }

    cout<<v.size()<<"\n";

    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }


    return 0;
}