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

using namespace std;

const int N = 1E6 + 5;

int n, cnt, licz, wyn;
bool zl[N];


int main() {
    ios_base::sync_with_stdio(0);

    cin >> n;
    cnt = n;
    licz = 0;
    while (cnt > 0) {
        licz++;
        cnt -= __builtin_popcount(licz);
        zl[licz] = true;
    }

    wyn = licz;

    for (int i = licz; i >= 1; i--) {
        if (__builtin_popcount(i) <= -cnt) {
            cnt += __builtin_popcount(i);
            zl[i] = false;
            wyn--;
        }
    }

    cout << wyn << endl;
    for (int i = licz; i >= 1; i--) {
        if (zl[i]) cout << i << " ";
    }


    
}