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
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = b; i >= a; i--)
#define cat(x) cout << #x << ": " << x << endl

using namespace std;
using ll = long long;

int n;

int main() {
	cin.tie(0)->sync_with_stdio(0);

	cin >> n;

	int s = 0;
	int m = 1;
	while (s < n) {
		s += __builtin_popcount(m++);
	}
	
	vector<int> res;
	per(i, 1, m - 1) {
		if (s - __builtin_popcount(i) >= n) {
			s -= __builtin_popcount(i);
		} else {
			res.push_back(i);
		}
	}

	cout << res.size() << "\n";
	for (auto x : res) {
		cout << x << " ";
	}
	cout << "\n";

	return 0;
}