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
// C2 - MUZ
#include <iostream>
#include <vector>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n, sum;
	int *bits;
	vector<int> result;
	
	cin >> n;
	bits = new int[n];
	
	bits[0] = 0;
	
	sum = 0;
	for (int i = 1; i <= n; ++i) {
		bits[i] = bits[i / 2] + (i % 2);
		sum += bits[i];
		if (sum >= n) {
			for (int j = i; j > 0; --j) {
				if (sum - bits[j] >= n) {
					sum -= bits[j];
				} else {
					result.push_back(j);
				}				
			}
			break;	
		}
	}
	
	cout << result.size() << endl;
	for (unsigned i = 0; i < result.size(); ++i) {
		cout << result[i] << " ";
	}
	cout << endl;
	
	delete [] bits;
	
	return 0;
}