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

int main() {
	int n;
	cin >> n;
	int lbit[20];
	int dsc = -1;
	int fin = 0, sum = 0;
	while(sum<n){
		int temp = 0, t = fin+1;
		while(t>0){
			temp+=t%2;
			t/=2;
		}
		lbit[temp-1]=fin+1;
		sum+=temp;
		fin++;
	}
	if(sum>n){
		dsc=lbit[sum-n-1];
	}
	if(dsc!=-1) cout << fin-1 << '\n';
	else cout << fin << '\n';
	for(int i = fin;i > 0; i--){
		if(i!=dsc) cout << i << ' ';
	}
	return 0;
}