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

int moc[1000007];
bool use[1000007];

int bity(int n) {
	int a = 0;
	while (n > 0) {
		if (n%2 == 1) ++a;
		n /= 2;
	}
	return a;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int n; cin >> n;
	
	int i = 1, bitsum = 0;
	while (bitsum < n) {
		moc[i] = bity(i);
		bitsum += moc[i];
		++i;
	}
	
	int maks = --i;
	int ignore;
	while (bitsum-n != 0) {
		if (moc[i] == bitsum-n) {
			ignore = i;
			break;
		}
		--i;
	}
	
	if (bitsum-n != 0) cout << maks-1 << "\n"; else cout << maks << "\n";
	for (i = maks; i > 0; --i) {
		if (i != ignore) cout << i << " ";
	}
	
	return 0;
}