#include <bits/stdc++.h>
using namespace std;
void solve(int x) {
  vector<int> ans;
  set<int> p;
  int res = 0;
  for (int i = 0; i <= 20; i++) {
    p.insert((1 << i) - 1);
  }
  for (int i = 0; i < 20; i++) {
    int need = -1;
    for (int j = 0; j < 20; j++) {
      if ((x >> j) & 1) {
        need = j;
        break;
      }
    }
    if (need == -1) {
      break;
    }
    x ^= (1 << need) - 1;
    ans.push_back(need);
    res++;
    if (p.count(x)) {
      break;
    }
    x++;
    res++;
    if (p.count(x)) {
      break;
    }
  }
  cout << res << '\n';
  if (res > 40 || !p.count(x)) {
    cout << '#' << x << '\n';
    exit(0);
  }
  for (int c : ans) {
    cout << c << ' ';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x;
  cin >> x;
  solve(x);
  return 0;
}
