#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long CheckIsZero(long long num) {
  stack<long long> s;
  while (num) {
    s.push(num & 1);
    num = num >> 1;
  }
  while (!s.empty() && s.top() != 0) s.pop();
  return s.size();
}
bool Check(long long val, long long count) {
  if (val == 0) {
    cout << count << endl;
    if (v.size()) {
      for (auto x : v) cout << x << " ";
    }
    return 1;
  }
  return 0;
}
int main() {
  long long num, count = 0;
  cin >> num;
  while (true) {
    long long val = CheckIsZero(num);
    if (Check(val, count)) {
      return 0;
    }
    v.push_back(val);
    num = (num ^ ((1 << val) - 1));
    count += 1;
    val = CheckIsZero(num);
    if (Check(val, count)) return 0;
    num += 1;
    count += 1;
  }
  return 0;
}
