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
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-all-loops")
//#pragma GCC target("avx,sse2,sse3,ssse3,sse4,lzcnt,popcnt")

#include <bits/stdc++.h>
#include <fstream>

#define ll long long
#define point pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define show(x) cerr << (#x) << " = " << x << '\n'
#define print(x) if (1) {cerr << (#x) << " = "; for (auto it : x) \
      cerr << it << ' '; cerr << '\n';}
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0)

using namespace std;

const int N = 300000 + 64;
const int INF = 2e9 + 64;
const ll MAX = 2e18 + 64;
const int MOD = 998244353;

int popcount(int x) {
	bitset<32> bs(x); return bs.count();
}

signed main() {
	int n;
	cin >> n;

	vector<int> ans;
	int sum = 0;

	for (int i = 1; sum < n; ++i)
		sum += popcount(i), ans.pb(i);

	reverse(all(ans));
	for (int i = 0; i < ans.size(); ++i)
		if (sum - popcount(ans[i]) == n) {
			ans.erase(ans.begin() + i); break;
		}

	cout << ans.size() << '\n';
	for (auto it : ans)
		cout << it << ' ';
}