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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int n, s = 0, i = 1, cnt;
	cin >> n;
	
	vector <int> last(32); // last number with i bits on
	while (s < n){
		cnt = __builtin_popcount(i);
		last[cnt] = i;
		s += cnt;
		i++;
	}
	i--;
	
	int rem = last[s - n];
	vector <int> ans;
	while (i >= 1){
		if (i != rem){
			ans.push_back(i);
		}
		i--;
	}
	
	cout << ans.size() << "\n";
	for (int x : ans){
		cout << x << " ";
	}
	cout << "\n";
	
    return 0;
}