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
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

vector < int > V;
vector < int > P;

int main(void){
    int n;
    scanf("%d",&n);
    for(int i = 1; n > 0 ;i++){
        V.push_back(i);
        n -= __builtin_popcount(i);
    }

    reverse(V.begin(),V.end());

    for(int i = 0; i < V.size();i++){
        if(n + __builtin_popcount(V[i]) <= 0){
            n += __builtin_popcount(V[i]);
        }else{
            P.push_back(V[i]);
        }
    }
    printf("%d\n",P.size());
    for(int i = 0; i < P.size();i++){
        printf("%d ",P[i]);
    }

    return 0;
}