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

#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

using namespace std;

int n;
int res, bits, currentTune = 1;
vector<int> tunes;

void readInput() {
    boost;
    cin >> n;
}

void solve() {
    while (bits < n) {
        tunes.push_back(currentTune);
        bits += __builtin_popcount(currentTune);
        currentTune++;
        res++;
    }

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

    for (auto it = tunes.begin(); it != tunes.end(); it++) {
        if (bits - __builtin_popcount(*it) == n) {
            tunes.erase(it);
            res--;
            break;
        }
    }
}

void printResult() {
    cout << res << endl;
    for (auto tune: tunes) {
        cout << tune << " ";
    }
    cout << endl;
}

int32_t main() {
    readInput();
    solve();
    printResult();
}