#include <bits/stdc++.h>
using namespace std;
int x;
int o, prevfind;
vector<int> n;
int find(int num) {
  int last = 0, i;
  i = 0;
  while (num > 0) {
    i++;
    if (num % 2 == 0) last = i;
    num /= 2;
  }
  return last;
}
int main() {
  cin >> x;
  prevfind = find(x);
  while (prevfind != 0) {
    o++;
    prevfind = find(x);
    x = x ^ ((1 << prevfind) - 1);
    n.push_back(prevfind);
    prevfind = find(x);
    if (prevfind == 0) break;
    o++;
    x++;
    prevfind = find(x);
  }
  cout << o << endl;
  for (int i = 0; i < n.size(); ++i) {
    cout << n[i] << ' ';
  }
  cout << endl;
  return 0;
}
