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
54
55
56
57
58
59
60
61
62
63
64
65
66
#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)
#define boost {ios_base::sync_with_stdio(false); cin.tie(); cout.tie();}
 
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 1e6+69, INF = 1e9+6969;

int n;
int dp[nax][2], st[30];
vi prep[30];
int N = 17;

int bigger(int x, int bits) {
    while(prep[bits][st[bits]] <= x) 
        st[bits]++;
    return prep[bits][st[bits]];
}

int main()
{
    for(int i=1;i<(1 << N);i++) {
        prep[__builtin_popcount(i)].pb(i);
    }
    // for(int i=0;i<N;i++) {
    //     prep[i].insert(INF);
    // }
    scanf("%d", &n);
    dp[1][0] = -1;
    dp[1][1] = 1;
    for(int i=2;i<=n;i++) {
        dp[i][1] = INF;
        dp[i][0] = -1;
        for(int j = i - 1; j >= max(1, i - N + 1); j--) {
            int cur = bigger(dp[j][1], i - j);
            if(cur < dp[i][1]) {
                dp[i][1] = cur;
                dp[i][0] = j;
            }
        }
    }

    vi ans;
    while(n != -1) {
        ans.pb(dp[n][1]);
        n = dp[n][0];
    }
    printf("%d\n", (int)ans.size());
    for(auto e: ans) {
        printf("%d ", e);
    }
    puts("");


	return 0;
}