#include <bits/stdc++.h>
using namespace std;
int x, t, ans[100010], cnt;
int main() {
  int n;
  scanf("%d", &x);
  while (1) {
    int c1 = 0, c2 = 0, c0 = 0, f0 = 0;
    bool f = 0;
    for (int i = 1; i <= 31; i++) {
      if (x & (1 << (i - 1))) {
        c1++;
        if (!f) c2++;
      } else
        f = 1;
      if (!(x & (1 << (i - 1))) && !f0) {
        c0++;
      } else
        f0 = 1;
    }
    if (c2 == c1) break;
    t++;
    x ^= ((1 << c0) - 1);
    ans[++cnt] = c0;
    c1 = 0, c2 = 0, f = 0;
    for (int i = 1; i <= 31; i++) {
      if (x & (1 << (i - 1))) {
        c1++;
        if (!f) c2++;
      } else
        f = 1;
    }
    if (c1 == c2) break;
    t++;
    x++;
  }
  printf("%d\n", t);
  for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]);
  return 0;
}
