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;

unsigned short count_bits(uint32_t value) {
     value = value - ((value >> 1) & 0x55555555);
     value = (value & 0x33333333) + ((value >> 2) & 0x33333333);
     return (((value + (value >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}

void solve(){
   int n, x=0,t=1;
   cin>>n;
   while(x<n){
        x+=count_bits(t);
        t++;
   }
   t--;
   if(x==n){
        cout<<t<<endl;
        for(int i=t; i>0; i--)cout<<i<<" ";
        return;
   }
   x=x-n;
  // cout<<t<<" "<<x;
    //cout<<x;

   vector<int>k;
   for(int i=t; i>0; i--){
        if(x!=0 &&count_bits(i)<=x){x-=count_bits(i); continue;}
        k.push_back(i);
   }
   cout<<k.size()<<endl;
   for(int i=0; i<k.size(); i++)cout<<k[i]<<" ";

}



int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    solve();
    return 0;
}