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
#include <bits/stdc++.h>
#define ct __builtin_popcount
#define pb push_back
#define sz size()

using namespace std;

int main() {
	int n;
	scanf("%d", &n);

	vector <int> w;

	int s = 0;
	for (int i=1; s < n; i++) {
		w.pb(i);
		s += ct(i);
	}

	reverse(w.begin(), w.end());

	int l = w.sz;

	for (int &i: w) {
		if (s - ct(i) >= n) {
			s -= ct(i);
			i = 0;
			l--;
		}
	}

	printf("%d\n", l);
	for (int i: w) {
		if (i > 0) printf("%d ", i);
	}
	printf("\n");

	return 0;
}