#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

vector<int> solve(lint x){
	if(x == 1) return vector<int>();
	if(x & 1){
		auto ret = solve(x-1);
		for(auto &i : ret) i++;
		ret.push_back(1);
		return ret;
	}
	auto ret = solve(x >> 1);
	ret.push_back(ret.size() + 1);
	return ret;
}

int main(){
	lint n;
	cin >> n;
	n++;
	vector<int> perm = solve(n);
	cout << 2 * perm.size() << endl;
	for(auto &i : perm) cout << i << " ";
	for(int i=1; i<=perm.size(); i++) cout << i << " ";
}
