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
#include<iostream>

int mb(int x){
	int ret = 0;
	for(;x>0;){
		ret += x%2;
		x /= 2;
	}
	return ret;
}

int main(){
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);
	int sum = 0, n, j = 0, k = -1;
	std::cin >> n;
	for(; sum < n; j++)
		sum += mb(j);
	j--;
	if(sum != n){
		sum = sum - n;
		for(k = j-1; mb(k) != sum; k--){}
	}
	
	std::cout << ((k == -1) ? j : j-1) << "\n";
	
	for(int i = j; i >= 1; i--) if(i != k) std::cout << i << " ";
	
	return 0;
}