#include <bits/stdc++.h>
using namespace std;
long long int INF = 10000000000;
long long int base(long long int x) {
  long double temp = (double)log2(x);
  long long int ti = temp;
  return ti;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int x;
  cin >> x;
  long long int n;
  long double temp = (double)log2(x);
  long long int ti = temp;
  ti++;
  long long int target = pow(2, ti) - 1;
  if (x == target) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long int> bv;
  int count = 0;
  while (true) {
    if (x == target) {
      break;
    }
    if (count % 2 == 0) {
      long long int diff = target - x;
      long long int b = base(diff);
      b++;
      long long int help = pow(2, b);
      help--;
      x = x ^ help;
      bv.push_back(b);
    } else {
      x++;
    }
    count++;
  }
  cout << count << endl;
  for (long long int i = 0; i < bv.size(); i++) {
    cout << bv[i] << " ";
  }
  return 0;
}
