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
#include<bits/stdc++.h>
using namespace std;
// int bin(int x){
	// int w=0;
	// for(;x;x/=2)
		// w+=x%2;
	// return w;
// }
int main(){
	int n,x;
	vector <int> res;
	vector <int> pref;
	scanf("%d",&n);
	pref={0};
	x=1;
	while(pref.back()<n){
		pref.push_back(pref.back()+__builtin_popcount(x));
		x++;
	}
	x--;
	while(n>0){
		while(pref[x]>=n)
			x--;
		x++;
		res.push_back(x);
		n-=__builtin_popcount(x);
	}
	printf("%d\n",(int)res.size());
	for(int ai:res)
		printf("%d ",ai);
	printf("\n");
	// print(sum(bin(x)[2:].count('1') for x in res))
	return 0;
}