#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};


vector<vector<ll>> memo(200, vector<ll>(200, -1));
ll comb(int n, int k){
    if(memo[n][k] != -1) return memo[n][k];
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    if(n == 0 || k == 0) return 1;
    if(comb(n-1, k) + comb(n-1, k-1) >= INFL) return memo[n][k] = INFL;
    return memo[n][k] = comb(n-1, k) + comb(n-1, k-1);
}

void solve1(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  rep(i, 1<<N){
    vector<ll> a;
    rep(j, N)if((i>>j)&1) a.pb(A[j]);
    if(a.size() % 2 == 1) continue;
    vector<ll> left, right;
    rep(j, a.size()/2) left.pb(a[j]);
    rep(j, a.size()/2) right.pb(a[j+a.size()/2]);
    bool same = 1;
    rep(j, a.size()/2) if(left[j] != right[j]){
      same = 0;
      break;
    }
    if(same){
      ans++;
    }
  }
  cout << ans - 1 << endl;
}

void solve(){
  ll N;
  cin >> N;

  ll len = 0;
  ll ok = 1;
  while(pow_long(2, ok+1) - 1 <= N) ok++;
  vector<ll> ans[ok];
  rep(i, ok) ans[i].pb(1);
  len += ok;
  N -= pow_long(2, ok - 1) - 1;
  ll now = 2;
  while(N){
    pair<ll, ll> tmpM = {-1, -1};//M. id;
    for(ll i = 1; i <= ok / 2; i++){
      ll leftsum = 0, rightsum = 0;
      ll left = i, right = ok - i;
      for(ll j = 0; j <= left; j++){
        double l = comb(left, j);
        double r = comb(right, j);
        if(l * r >= 1. * INFL) continue;
        leftsum += comb(left, j) * comb(right, j);
      }
      if(leftsum + rightsum > N) continue;
      if(tmpM.f < leftsum + rightsum){
        tmpM = {leftsum + rightsum, i};
      }
    }
    if(tmpM.f == -1){
      break;
    }
    N -= tmpM.f;
    ans[tmpM.s-1].pb(now);
    now++;
    len += 2;
  }

  vector<ll> sub;
  rep(i, ok){
    rep(j, ans[i].size()){
      if(ans[i][j] == 1) continue;
      sub.pb(ans[i][j]);
    }
  }

  cout << len + 2 * N << endl;
  revrep(i, sub.size()){
    cout << sub[i] << " ";
  }
  rep(i, ok){
    rep(j, ans[i].size()){
      cout << ans[i][j] << " ";
    }
  }
  rep(i, N){
    cout << now << " " << now << " ";
    now++;
  }
  cout << endl;

}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  //solve1();
}


Measured memory_bytes: 640