#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x, t = 0;
  bool ok = 0;
  vector<int> res;
  cin >> x;
  for (int i = (19); i >= (0); i--) {
    if (!(x & (1 << i))) {
      if (ok) {
        x++, t++;
        ok = 0;
      }
      if (!(x & (1 << i))) {
        res.push_back(i + 1);
        x ^= ((1 << (i + 1)) - 1), t++;
        ok = 1;
      }
    }
  }
  cout << t << '\n';
  for (int i : res) cout << i << ' ';
  return 0;
}
