#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int x, n;
bool ok(int x) { return (x & (x + 1)) == 0; }
int cal(int x) {
  int res = 0;
  while (x) res++, x /= 2;
  return res;
}
int f = 1;
bool ok2(int x) {
  while (x % 2 == 0) x /= 2;
  return ok(x);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> x;
  vector<int> v;
  n = cal(x);
  int ans = 0;
  int B = 0;
  while (!ok(x)) {
    int t = n - 1;
    if (ok2(x)) {
      ans--;
      int tmp = 0;
      while (x % 2 == 0) tmp++, x /= 2;
      v.push_back(tmp);
      break;
    }
    for (; t >= 0; t--) {
      if (((x >> t) & 1) == 0) {
        break;
      }
    }
    t++;
    x ^= (1 << (t)) - 1;
    x++;
    v.push_back(t);
  }
  ans += v.size() * 2;
  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  return 0;
}
