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
#include <bits/stdc++.h>
using namespace std;

int night[20];
int sum=0, it=0;

int main(){
    int n; cin >> n;
    while (sum<n){
        it++;
        int a = __builtin_popcount(it);
        sum += a;
        night[a-1] = it;
    }

    if (sum==n){
        cout << it << endl;
        for (int i=it; i>0; i--){
            cout << i << " ";
        }
    }
    else {
        cout << it-1 << endl;

        for (int i=it; i>night[sum-n-1]; i--){
            cout << i << " ";
        }
        for (int i=night[sum-n-1]-1; i>0; i--){
            cout << i << " ";
        }
    }

    return 0;
}