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 boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const int N = 1e6 + 10;
bool taken[N];

int main() {
    boost;

    int n, sum=0,x,i=0;
    cin >> n;
    while(sum < n) {
        i++;
        sum += __builtin_popcount(i);
        taken[i] = 1;
    }
    sum = sum-n;
    while(sum > 0){
        x = __builtin_popcount(i);
        if(sum - x >= 0) {
            sum -= x;
            taken[i] = 0;
        }
        i--;
    }
    int res = 0;
    for(int j=1e6; j>0; j--) {
        if(taken[j]) res++;
    }
    cout << res << "\n";
    for(int j=1e6; j>0; j--) {
        if(taken[j]) cout << j << " ";
    }
    cout << "\n";


    return 0;
}