#include <bits/stdc++.h>
using namespace std;
int highbit(int x, int *i) {
  for (*i = 20; *i >= 0; (*i)--)
    if ((x >> (*i)) & 1) return 1 << *i;
  return 0;
}
int main() {
  int x, i, a;
  vector<int> ans;
  scanf("%d", &x);
  a = 0;
  while (__builtin_popcount(x + 1) != 1) {
    x = (x ^ (highbit(x, &i) * 2 - 1));
    a++;
    ans.push_back(i + 1);
    if (__builtin_popcount(x + 1) == 1) break;
    x += 1;
    a++;
  }
  printf("%d\n", a);
  for (i = 0; i < ans.size(); i++) {
    if (i > 0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}
