#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MAXN = +3;
int n, cnt;
stringstream ss;
bool check(int x) {
  for (int i = 1; i <= x; i *= 2) {
    if ((x & i) == 0) return 0;
  }
  return 1;
}
int main() {
  int k = 2;
  cin >> n;
  while (check(n) == 0) {
    cnt++;
    if (cnt % 2) {
      k = 0;
      while ((1 << k) <= n) {
        k++;
      }
      n ^= (1 << k) - 1;
      ss << k << " ";
    } else {
      n++;
    }
  }
  cout << cnt << endl << ss.str() << endl;
  return 0;
}
