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

using namespace std;

int main(){
    int n;
    cin >> n;
    int moce[n];
    moce[0] = moce[1] = 1;
    for(int i = 2; i < n; i++){
        if(i % 2 == 0)
            moce[i] = 1 + moce[(i / 2) - 1];
        else
            moce[i] = moce[(i - 1) / 2];
    }

    int cur = 0, cnt = 0;

    while(cur < n){
        cur += moce[cnt];
        cnt++;
    }
    
    int ans[cnt], it = 0;
    while(cur != n){
        if(cur - moce[cnt-1] < n){
            ans[it] = cnt;
            it++;
            cnt--;
        } else{
            cur -= moce[cnt-1];
            cnt--;
        }
    }
    
    while(cnt > 0){
        ans[it] = cnt;
        cnt--;
        it++;
    }
    
    cout << it << endl;

    for(int j = 0; j < it; j++)
        cout << ans[j] << " ";
}