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
48
49
50
51
#include <iostream>

using namespace std;

int itoa(int value) {
	int tmp_value;
	int res = 0;

	do {
		tmp_value = value;
		value /= 2;
		res += tmp_value - value * 2;
	} while (value);

	return res;
}

class dtab {
public:
	int w;
	int b;
};

int main() {

	int n;
	cin >> n;
	int s = 0;
	dtab t[n];
	int i = 0;
	do {
		t[i].b = itoa(i + 1);
		t[i].w = i + 1;
		s += t[i].b;
		i++;
	} while(s < n);

	int w = s - n;
	cout << i - (w > 0 ? 1 : 0) << endl;
	for (int k = i-1; k >=0 ; k--) {
		if (w != t[k].b)
		{
			cout << t[k].w << " ";
		}
		else {
			w = 0;
		}
	}
	cout << endl;
	return 0;
}