#include <bits/stdc++.h>
using namespace std;
bool test(int a) {
  for (int i = 2; i <= (a + 1); i *= 2) {
    if (i == a + 1) {
      return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  unsigned int x, p, b, ops = 0;
  cin >> x;
  vector<int> bits;
  vector<int> ans;
  while (!test(x)) {
    for (int i = 1, j = 1; i < x; i *= 2, j++) {
      if ((x & i) == 0) {
        b = (i << 1) - 1;
        p = j;
      }
    }
    ans.push_back(p);
    x = x ^ b;
    ops++;
    if (test(x)) {
      break;
    }
    x++;
    ops++;
  }
  cout << ops << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
  return 0;
}
