#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  int i = 23, val = 1;
  for (int j = 0; j < 23; j++) val <<= 1;
  while (!(val & x) && i >= 0) {
    val >>= 1;
    i--;
  }
  while ((val & x)) {
    val >>= 1;
    i--;
  }
  vector<int> ans;
  int cnt = 0;
  while (i != -1) {
    ans.push_back(i + 1);
    cnt++;
    x = ((val << 1) - 1) ^ x;
    while ((val & x)) {
      val >>= 1;
      i--;
    }
    if (i != -1) {
      x += 1;
      cnt++;
    }
    while ((val & x)) {
      val >>= 1;
      i--;
    }
  }
  cout << cnt << "\n";
  for (int j = 0; j < ans.size(); j++) cout << ans[j] << " ";
  return 0;
}
