#include <bits/stdc++.h>
using namespace std;
int ans[200010];
template <typename _T>
void rd(_T &x) {
  int f = 1;
  x = 0;
  char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9')
    x = (x << 3) + (x << 1) + (s - '0'), s = getchar();
  x *= f;
}
bool check(int x) {
  x++;
  return (x & -x) == x;
}
int main() {
  int x;
  rd(x);
  int step = 0, m = 30;
  while ((x >> m) == 0) m--;
  while (!check(x)) {
    step++;
    if (step & 1)
      for (int i = m; i >= 0; i--)
        if (((x >> i) & 1) == 0) {
          static int len = 0;
          x ^= ((1 << (i + 1)) - 1);
          ans[++len] = i + 1;
          break;
        }
    if (!(step & 1)) x++;
  }
  printf("%d\n", step);
  int M = (step & 1) ? ((step >> 1) + 1) : (step >> 1);
  for (int i = 1; i <= M; i++) printf("%d ", ans[i]);
  return 0;
}
