#include <bits/stdc++.h>
using namespace std;
long long k = 0;
bool check(long long n) {
  long long s = 0;
  for (long long i = 0; i <= k; i++) {
    if ((1 << i) & n) s++;
  }
  if (s - 1 == k)
    return 1;
  else
    return 0;
}
int main() {
  long long n, m;
  long long a[10000] = {0};
  cin >> n;
  for (long long i = 0; i <= 21; i++) {
    if ((1 << i) & n) k = i;
  }
  long long t = 0;
  long long z = 0;
  for (long long i = k - 1; i >= 0; i--) {
    if (!((1 << i) & n)) {
      t++;
      a[t] = i + 1;
      n = n ^ ((1 << (i + 1)) - 1);
      if (!check(n)) {
        z++;
        n++;
      } else
        break;
    }
  }
  cout << t + z << endl;
  for (long long i = 1; i <= t; i++) {
    cout << a[i] << " ";
  }
}
