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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;


#define st first
#define nd second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define rsz(x) resize(x)
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef pair<int,int>pii;
typedef long double ldl;
typedef pair<ll,ll>pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll>vll;
typedef unsigned long long ul;


int main()
{
	BOOST
	int n;
	cin>>n;
	int cnt=0;
	int last=0;
	while(cnt < n)
	{
		last++;
		cnt+=__builtin_popcount(last);		
	}
	int r = cnt-n;
	if(r)
		cout<<last-1<<'\n';
	else
		cout<<last<<'\n';
	bool used=0;
	for(int i = last ; i > 0 ; i--)
	{
		if(!used && __builtin_popcount(i)==r)
		{
			used = 1;
			continue;
		}
		cout<<i<<' ';
	}
	cout<<'\n';
	return 0;
}