#include <bits/stdc++.h>
using namespace std;
int cnt[30];
vector<int> res;
int f[30];
int main() {
  int x;
  cin >> x;
  f[0] = 1;
  int flag = 0;
  for (int i = 1; i < 30; i++) {
    f[i] = f[i - 1] * 2;
    if (f[i] == x) flag = 1;
  }
  for (int i = 0; i < 30; i++) {
    if (f[i] == x) {
      if (i == 0)
        printf("0\n");
      else
        printf("1\n%d", i);
      return 0;
    }
  }
  int num = x;
  int n = 0;
  while (num) {
    cnt[n++] = num % 2;
    num /= 2;
  }
  int pre = -1;
  if (!cnt[0]) {
    res.push_back(0);
  }
  for (int i = 1; i < n; i++) {
    if (!cnt[i] && pre == -1) {
      pre = i;
    } else if (cnt[i]) {
      if (pre != -1) {
        res.push_back(i);
        if (pre > 1) res.push_back(pre);
        pre = -1;
      }
    }
  }
  cout << res.size() * 2 << endl;
  for (int i = 0; i < res.size(); i++) {
    printf("%d ", res[i]);
  }
  return 0;
}
