#include <bits/stdc++.h>
using namespace std;
int a[21], top = 0, n, x;
queue<int> q;
int main() {
  cin >> x;
  while (x) a[++n] = x & 1, x >>= 1;
  while (a[top + 1] == 0) top++;
  while (top < n) {
    q.push(top);
    while (a[top + 1] == 1) top++;
    a[top + 1] = 1;
  }
  cout << q.size() * 2 - 1 << endl;
  while (!q.empty()) cout << q.front() << " ", q.pop();
}
