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
#include <iostream>
#include <vector>
#include <algorithm>

// ale durne zadanko

int main() {
	std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
	
	int n;
	std::cin >> n;
	
	int bcnt = 0;
	int i;
	for (i = 0; bcnt <= n; ) {
		bcnt += __builtin_popcount(++i);
	}
	
	int diff = bcnt - n;
	
	std::cout << i-1 << '\n';
	bool notremoved = true;
	for (int j = i; j >= 1; --j) {
		if (notremoved && __builtin_popcount(j) == diff) {
			notremoved = false;
		} else {
			std::cout << j << ' ';
		}
	}
	std::cout << '\n';
	
	return 0;
}