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;

int n;
int suma;

vector <int> ans;
vector <bool> anss;

int nie;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cin >> n;

	for(int i = 1; suma < n;i++){
		ans.push_back(i);
		anss.push_back(true);
		suma += __builtin_popcount(i);
	}

	for(int i = ans.size()-1; suma > n; i--){
		if(suma - __builtin_popcount(ans[i]) >= n){
			anss[i] = false;
			suma -= __builtin_popcount(ans[i]);
			nie++;
		}
	}

	cout << ans.size() - nie << "\n";


	for(int i = ans.size()-1; i >= 0; i--){
		if(anss[i]) cout << ans[i] << " ";
	}

	return 0;
}