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
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define PB push_back
#define SIZE(c) ((int)(c).size())
#define INT(x) int x; scanf("%d", &x)

typedef vector<int> VI;

int r[1000001];

int main() {
	INT(n);
	FOR(i,1,n+1) {
		int b = min(i, 17);
		int mi = 2000000000;
		FOR(k,1,b+1) {
			int x = r[i - k] + 1;
			int d = k - __builtin_popcount(x);
			if (d < 0) continue;
			if (d) REP(j,17) if (!(x & (1 << j))) {
				x |= 1 << j;
				if (!--d) break;
			}
			mi = min(mi, x);
		}
		r[i] = mi;
	}
	VI v;
	while (n) {
		v.PB(r[n]);
		n -= __builtin_popcount(r[n]);
	}
	printf("%d\n", SIZE(v));
	bool start = 1;
	FORE(it,v) {
		if (!start) printf(" ");
		start = 0;
		printf("%d", *it);
	}
	printf("\n");
}