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
//2022-12-13
//author: Marcin Rolbiecki
#include <bits/stdc++.h>
using namespace std;

const int maxN = 1e6+10;

int n;
int lastB [maxN];
vector <int> ans;

int ile (int a) {
	
	int res = 0;
	for (int b = 1; b <= a; b<<=1)
		if (a&b) res++;
	return res;
}

int main () {
		
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	int sum = 0, l = 1;
	
	while (sum < n) {
		
		int il = ile(l);
		sum += il;
		lastB [il] = l;
		ans.push_back(l);
		l++;
	}
	
	reverse (ans.begin(), ans.end());
	
	cout << (sum - n ? ans.size() - 1: ans.size()) << '\n';
	
	for (int a : ans)
		if (a != lastB[sum-n])
			cout << a << ' ';
	
	return 0;
}