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
47
48
49
50
51
52
53
//
// Jan Zachar 14/12/2022
//
#include <iostream>
using namespace std;



int n;

int cntr;
int s;
int maxi = 1;
int sp[1000001]{};
int used[1000001]{};

int count_bits(int x) {
    int c = 0;
    while (x) {
        c += x & 1;
        x >>= 1;
    }
    return c;
}

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

    cin >> n;
    for (;; maxi++) {
        s = count_bits(maxi);
        sp[maxi] = sp[maxi-1]+s;
        if (sp[maxi] >= n) break;
    }
    cntr = maxi;

    for (int i = maxi; i > 1; i--) {
        if (sp[maxi]-(sp[i]-sp[i-1]) >= n) {
            sp[maxi] -= sp[i]-sp[i-1];
            used[i] = true;
            --cntr;
        }
        if (sp[maxi] == n) break;
    }

    cout << cntr << endl;
    for (int i = maxi; i > 0; i--) {
        if (!used[i]) cout << i << " ";
    }
    cout << endl;
}