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
#define make_pair mp
#define emplace_back pb
#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(time(0));
const int N = 1e6+505;
int n;
int dp[N], num[N];
vector<int> res;
int main()
{
    scanf("%d", &n);
    int sum = 0;
    int it = 0;
    while(sum < n) {
        it++;
        num[it] = it % 2 + num[it / 2];
        int prevsum = sum + 1;
        sum += num[it];
        //printf("%d %d %d\n", it, num[it], sum);
        for(int i=prevsum;i<=sum;i++) dp[i] = it;
    }
    while(n) {
        int k = dp[n];
        res.pb(k);
        n -= num[k];
    }
    printf("%d\n", (int)res.size());
    for(int i=0;i<res.size();i++) printf("%d ", res[i]);
	return 0;
}