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
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

int tab[2000009];

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	tab[0] = 1;

	int pre = 0;
	int cur = 0;
	for(int i=1;cur+__builtin_popcount(i)<=2000000;i++) {
		cur += __builtin_popcount(i);
		for(int j=pre+1;j<=cur;j++) tab[j] = i;
		pre = cur;
	}

	int n;
	cin >> n;

	int MAX = tab[n];
	vector<int> v;
	while(n) {
		while(tab[n]!=MAX) MAX--;
		v.pb(MAX);
		n-=__builtin_popcount(MAX);
		MAX--;
	}
	cout << sz(v) << "\n";
	for(int x:v) cout << x << " ";
	cout << "\n";
}