#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
map<int, int> mp;
vector<int> vv;
int main() {
  int k = 1;
  for (int i = 1; i <= 30; i++) {
    k *= 2;
    mp[k - 1] = 1;
  }
  int n, cnt = 0;
  scanf("%d", &n);
  while (mp[n] != 1) {
    cnt++;
    if (cnt % 2 == 0)
      n++;
    else {
      int x = n & (-n), t = 0;
      n ^= (x - 1);
      while (x) {
        t++;
        x >>= 1;
      }
      vv.push_back(t - 1);
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < vv.size(); i++) printf("%d ", vv[i]);
  return 0;
}
