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

int cnt(int x) {
	return __builtin_popcount(x);
}

vector<int> v;
int N = 0;

int main() {
	int n;
	scanf("%d", &n);
	
	int w = 0;
	for (int i=1; i<1000000; i++) {
		v.push_back(i);
		w += cnt(i);
		N++;
		
		if (w >= n)
			break;
	}
	
	for (int i=v.size()-1; i>=0; i--) {
		if (w - cnt(v[i]) >= n) {
			w -= cnt(v[i]);
			N--;
			v[i] = -1;
		}
	}
	
	printf("%d\n", N);
	printf("%d", v.back());
	v.pop_back();
	while (v.size() > 0) {
		if (v.back() > 0)
			printf(" %d", v.back());
		v.pop_back();
	}
	printf("\n");
	
	return 0;
}