#include <bits/stdc++.h>
using std::vector;
bool judge(int x) {
  for (int i = 0; i < 31; i++) {
    if (x == (1 << i) - 1) return true;
  }
  return false;
}
int get_hzero(int x) {
  int res = 0, pre = 0;
  for (int i = 0; i < 31; i++) {
    if (x & (1 << i))
      res = pre;
    else
      pre = i;
  }
  return res;
}
int main() {
  int x;
  while (~scanf("%d", &x)) {
    int bit[100];
    int ans = 0;
    vector<int> vec;
    while (!judge(x)) {
      int num = get_hzero(x) + 1;
      vec.push_back(num);
      x ^= (1 << num) - 1;
      ans++;
      if (!judge(x)) x += 1, ans++;
    }
    printf("%d\n", ans);
    for (int i = 0; i < vec.size(); i++)
      printf("%d%c", vec[i], " \n"[i == vec.size() - 1]);
  }
  return 0;
}
