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
#include <iostream>
#include <vector>
int cBin(int n) {
	int count = 0;
	while (n != 0) {
		if ((n % 2) == 1) { count++;}
		n /= 2;
	}
	return count;
}
int main()
{
	int bS = 0, i = 1, n;
	std::vector <int> tab;
	std::cin >> n;
	for (i; bS < n; i++) {bS += cBin(i);};
	--i; tab.push_back(i); --i;
	for (i; bS != n; i--) {
		bS -= cBin(i);
		if (bS < n) {bS += cBin(i); tab.push_back(i);}
	}		
	for (i; i > 0; i--) { tab.push_back(i); }
	std:: cout << tab.size() << "\n";
	for (int j = 0; j < tab.size(); j++) { std::cout << tab[j] << " ";}
}