#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
const double EPS = 1e-6;
const long long INF = (1LL << 62);
const long long P = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> ops;
  long long turn = 0;
  long long opct = 0;
  set<long long> valid;
  long long first = 1;
  while (first < 1e9) {
    valid.insert(first - 1);
    first *= 2;
  }
  while (n != 1) {
    if (!turn) {
      long long cts = 1;
      for (; (n >> cts); cts++) {
      }
      long long nv = (1LL << cts) - 1;
      ops.push_back(cts);
      n = n ^ nv;
    } else {
      n += 1;
    }
    opct++;
    turn = !turn;
    if (valid.count(n)) break;
  }
  cout << opct << endl;
  for (long long x : ops) cout << x << " ";
  return 0;
}
