#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 50;
long long x;
int bit[30];
long long f[40];
vector<int> ans;
int main() {
  f[0] = 1;
  for (int i = 1; i <= 32; i++) {
    f[i] = f[i - 1] * 2;
  }
  scanf("%lld", &x);
  for (int i = 0; i <= 32; i++) {
    if (x == (f[i] - 1)) {
      printf("%d\n", 0);
      return 0;
    }
  }
  ans.clear();
  int tot = 0;
  while (true) {
    tot++;
    long long n = x;
    int cnt = 0;
    while (n) {
      bit[++cnt] = n % 2;
      n /= 2;
    }
    for (int i = cnt; i >= 1; i--) {
      if (bit[i] == 0) {
        x ^= (f[i] - 1);
        ans.push_back(i);
        break;
      }
    }
    for (int i = 0; i <= 32; i++) {
      if (x == (f[i] - 1)) {
        printf("%d\n", tot);
        for (int j = 0; j < ans.size(); j++) {
          if (j == 0)
            printf("%d", ans[j]);
          else
            printf(" %d", ans[j]);
        }
        printf("\n");
        return 0;
      }
    }
    tot++;
    x += 1;
    for (int i = 0; i <= 32; i++) {
      if (x == (f[i] - 1)) {
        printf("%d\n", tot);
        for (int j = 0; j < ans.size(); j++) {
          if (j == 0)
            printf("%d", ans[j]);
          else
            printf(" %d", ans[j]);
        }
        printf("\n");
        return 0;
      }
    }
  }
  return 0;
}
