#include <bits/stdc++.h>
using namespace std;
long long int setBitNumber(long long int n) {
  if (n == 0) return 0;
  long long int msb = 0;
  while (n != 0) {
    n = n / 2;
    msb++;
  }
  return (1 << msb);
}
bool isPowerOfTwo(int n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
int main() {
  long long int x, count = 0, i, x1, count1 = 0;
  vector<long long int> g1;
  cin >> x;
  while (!isPowerOfTwo(x + 1)) {
    x1 = log2(setBitNumber(x)) - 1;
    long long int t1 = pow(2, x1 + 1) - 1;
    x = x ^ t1;
    g1.push_back(x1 + 1);
    count++;
    if (!isPowerOfTwo(x + 1)) {
      x++;
      count++;
    }
  }
  cout << count << endl;
  for (i = 0; i < g1.size(); i++) cout << g1[i] << " ";
  return 0;
}
