#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  ;
  long long n1 = n, c = 0;
  vector<long long> v;
  while (n1) {
    c++;
    n1 /= 2;
  }
  long long cnt = 0, i = (1 << (c - 1)), val = c;
  while (i > 0) {
    if (!(i & n)) {
      if (cnt % 2 == 0) {
        v.push_back(c);
        long long val = (1 << c) - 1;
        n = n ^ val;
        i /= 2;
        c--;
      } else
        n++;
      cnt++;
    } else {
      i /= 2;
      c--;
    }
  }
  cout << cnt << "\n";
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
