#include <bits/stdc++.h>
using namespace std;
long long x, ans;
vector<long long> vans;
pair<long long, long long> count(long long a) {
  long long tmp = a, len = 0;
  while (tmp > 0) {
    tmp >>= 1;
    len++;
  }
  tmp = 1;
  long long k = 0, ret;
  while (k < len) {
    if ((a & tmp) == 0) ret = k;
    tmp <<= 1;
    k++;
  }
  long long ret1 = 0;
  while (__builtin_popcount(ret1) < ret) {
    ret1++;
    ret1 <<= 1;
  }
  ret1++;
  return make_pair(ret + 1, ret1);
}
int main() {
  cin >> x;
  ans = 0;
  while (__builtin_popcount(x + 1) != 1) {
    if (ans >= 40) break;
    pair<long long, long long> n = count(x);
    vans.push_back(n.first);
    ans++;
    x ^= n.second;
    if (__builtin_popcount(x + 1) == 1) break;
    ans++;
    x++;
  }
  cout << ans << "\n";
  long long sez = vans.size();
  for (int i = 0; i < sez; i++) {
    cout << vans[i] << " ";
  }
  cout << "\n";
}
