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

using std::cin;
using std::cout;
using notes_t = std::vector<size_t>;
using std::find;

int main() {
    size_t n;
    size_t bits = 1;
    notes_t notes = {};
    size_t i = 0, j = 0;

    cin >> n;
    notes.push_back(1);
    while (bits < n) {
        if (i == j) {
            notes.push_back(1);
            j = notes.size() - 1;
            i = 0;
        } else {
            notes.push_back(notes[i] + 1);
            ++i;
        }
        bits += notes.back();
    }

    if (bits > n) {
        auto overflow = bits - n;
        auto it = find(notes.rbegin(), notes.rend(), overflow);
        *it = 0;
        cout << notes.size() - 1 << '\n';
    } else {
        cout << notes.size() << '\n';
    }

    for (size_t k = notes.size(); k >= 1; --k)
        if (notes[k - 1] > 0)
            cout << k << ' ';
    cout << '\n';
    return 0;
}