#include <bits/stdc++.h>
using namespace std;
const long long maxn = 30;
inline long long Read() {
  long long x(0), f(1);
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x * f;
}
long long val, len, top;
long long a[maxn], sta[maxn];
int main() {
  val = Read();
  long long tmp(val);
  while (tmp) {
    a[++len] = tmp & 1;
    tmp >>= 1;
  }
  long long ret(0);
  if (val & 1 == 1) {
    long long ans(0);
    while (true) {
      long long now(0);
      for (long long i = len; i >= 1; --i) {
        if (!a[i]) {
          now = i;
          break;
        }
      }
      if (!now) {
        break;
      }
      sta[++top] = now;
      for (long long i = now; i >= 1; --i) {
        a[i] ^= 1;
      }
      ++a[1];
      ret += 2;
    }
  } else {
    while (true) {
      long long now(0);
      for (long long i = len; i >= 1; --i) {
        if (!a[i]) {
          now = i;
          break;
        }
      }
      for (long long i = now; i >= 1; --i) a[i] ^= 1;
      sta[++top] = now;
      now = 0;
      for (long long i = len; i >= 1; --i)
        if (!a[i]) {
          now = i;
          break;
        }
      ++ret;
      if (!now) break;
      ++a[1];
      for (long long i = 1; i <= len; ++i) {
        if (a[i] == 2) {
          a[i] = 0;
          ++a[i + 1];
          if (i == len) break;
        } else
          break;
      }
      ++ret;
    }
  }
  cout << ret << endl;
  for (long long i = 1; i <= top; ++i) cout << sta[i] << ' ';
  return 0;
}
