#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long x;
  cin >> x;
  vector<long long> ans;
  int count = 0;
  while (1) {
    long long k = (int)(log2(x)) + 1;
    long long m = 1 << k;
    m--;
    x = x ^ m;
    count++;
    ans.push_back(k);
    if (x == 0) {
      break;
    }
    int f = 0;
    for (int i = 0; i < 32; i++) {
      long long p = 1 << i;
      p--;
      if (x == p) {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      break;
    }
    x++;
    count++;
    for (int i = 0; i < 32; i++) {
      long long p = 1 << i;
      p--;
      if (x == p) {
        f = 1;
        break;
      }
    }
    if (f == 1) {
      break;
    }
  }
  cout << count << endl;
  for (auto i : ans) {
    cout << i << " ";
  }
}
