#include <bits/stdc++.h>
using namespace std;
int x, cnt;
vector<int> rj;
bool good(int n) {
  bool t = false;
  for (int i = 20; i >= 0; i--) {
    if (n & (1 << i)) t = true;
    if (t && !(n & (1 << i))) return false;
  }
  return true;
}
int fix(int n) {
  bool t = false;
  for (int i = 20; i >= 0; i--) {
    if (n & (1 << i)) t = true;
    if (t && !(n & (1 << i))) {
      int m = (1 << (i + 1)) - 1;
      n ^= m;
      rj.push_back(i + 1);
      break;
    }
  }
  return n;
}
void stop(int n) {
  cout << n << "\n";
  for (int i = 0; i < rj.size(); i++) {
    cout << rj[i] << " ";
  }
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> x;
  if (good(x)) stop(cnt);
  while (true) {
    x = fix(x);
    cnt++;
    if (good(x)) stop(cnt);
    x++;
    cnt++;
    if (good(x)) stop(cnt);
  }
  return 0;
}
