#include <bits/stdc++.h>
using namespace std;
int highbit(int x) {
  int ans = 0;
  if (x >> 10) {
    ans += 10;
    x >>= 10;
  }
  if (x >> 5) {
    ans += 5;
    x >>= 5;
  }
  if (x >> 3) {
    ans += 3;
    x >>= 3;
  }
  while (x) {
    ans++;
    x >>= 1;
  }
  return ans;
}
int main(int argc, char *argv[]) {
  int n, tn, th, ct = 0;
  int ans[40];
  scanf("%d", &n);
  while (n & (n + 1)) {
    tn = n;
    th = highbit(tn);
    while (tn >= (1 << th)) tn -= (1 << th--);
    ans[ct++] = th;
    n = n ^ ((1 << th) - 1);
    if ((n & (n + 1)) == 0) break;
    n++;
    ct++;
  }
  printf("%d\n", ct);
  if (ct) {
    printf("%d", ans[0]);
    for (int i = 2; i < ct; i += 2) printf(" %d", ans[i]);
    putchar('\n');
  }
  return 0;
}
