#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long int MAX = -1000000000000000000;
const long long int MIN = 1000000000000000000;
const long long int inf = 1000000000;
const long long int KOK = 100000;
const long long int LOG = 30;
const long long int li = 1000005;
const long long int mod = 1000000007;
long long int n, m, cev, b, a[li], k, at, fl;
string s;
vector<long long int> v;
vector<long long int> vv;
inline long long int solve() {
  scanf("%lld", &n);
  for (long long int i = 1; i <= 30; i++) {
    long long int us = (1 << i);
    if (us == n + 1) {
      printf("0\n");
      return 0;
    }
    if (us == n) {
      printf("1\n%lld\n", i);
      return 0;
    }
    if (us > n) break;
    at = i;
  }
  long long int tut = n;
  long long int sayici = 0;
  while (1) {
    sayici++;
    if (sayici % 2 == 1) {
      v.clear();
      tut = n;
      fl = 0;
      while (tut > 0) {
        if (tut % 2 == 0) v.push_back(0);
        if (tut % 2 != 0) v.push_back(1);
        tut /= 2;
      }
      reverse(v.begin(), v.end());
      for (long long int i = 0; i < (long long int)v.size(); i++) {
        if (v[i] == 0) {
          at = i;
          fl = 1;
          break;
        }
      }
      long long int say = 0;
      long long int mo = 1;
      if (fl == 1) {
        for (long long int i = at; i < (long long int)v.size(); i++) {
          say += mo * 1;
          mo *= 2;
        }
        n = n ^ say;
        vv.push_back(v.size() - at);
      }
    } else
      n++;
    for (long long int i = 1; i <= 30; i++) {
      long long int us = (1 << i);
      if (us == n + 1) {
        printf("%lld\n", sayici);
        for (int i = 0; i < (int)vv.size(); i++) {
          printf("%lld ", vv[i]);
        }
        return 0;
      }
      if (us == n) {
        printf("1\n%lld\n", i - 1);
        return 0;
      }
      if (us > n) break;
      at = i;
    }
  }
  return 0;
}
int main(void) {
  solve();
  return 0;
}
