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

using namespace std;
#define endl '\n'
#define fi first
#define sc second
#define LL long long

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int N;
	cin >> N;
	int temp = 0;
	vector<int> Skipped;
	int i = 0;
	while(temp < N){
		i++;
		int Ti = i, noB = 0;
		while(Ti > 0){
			if(Ti % 2) noB++;
			Ti /= 2;
		}
		temp += noB;
		if(Skipped.empty() | Skipped.size() < noB){
			Skipped.push_back(i);
		}
		else{
			Skipped[noB - 1] = i;
		}
	}
	int skip = 0; if(temp != N) skip = Skipped[temp - N - 1];
	if(skip != 0) cout << i-1 << endl;
	else cout << i << endl;
	for(int it = i; it > 0; it--){
		if(it != skip) cout << it << " ";
	}
	cout << endl;
	return 0;
}