#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int x, t;
vector<int> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> x;
  while (1) {
    int lst = -1, lst2 = -1;
    for (int i = 30; i >= 0; i--) {
      if (((1 << i) & x) == 0 && (1 << i) <= x) {
        if (lst == -1) lst = i;
      }
      if (lst != -1 && ((1 << i) & x) != 0) lst2 = i;
    }
    if (lst == -1) break;
    v.push_back(lst + 1);
    if (lst2 == -1) {
      t = -1;
      break;
    }
    x = (x ^ ((1 << (lst + 1)) - 1)) + 1;
  }
  cout << (int)v.size() * 2 + t << "\n";
  for (auto i : v) cout << i << " ";
}
