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
#include <iostream>
#include <bitset>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

void solve() {
	int n, cnt=0, i=0, tmp;
	cin >> n;
	
	while (cnt < n) {
		i++;
		cnt += __builtin_popcount(i);
	}

	if (cnt == n) {
		cout << i << '\n';
		for (int j = i; j >= 1; j--)
			cout << j << " ";
		return;
	}
	
	cout << i-1 << '\n';
	for (int j = i; j >= 1; j--) { 
		tmp = __builtin_popcount(j);
		if (cnt - tmp == n) {
			for (int k = i; k > j; k--)
				cout << k << " ";
			for (int k = j-1; k >= 1; k--)
				cout << k << " ";
			return;
		}
	}
	
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	solve();
	cout << '\n';

	return 0;
}