#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long n = 1000001;
bool prime[1000001];
long long p;
long long max(long long a, long long b) {
  if (a >= b) {
    return a;
  }
  return b;
}
void solve() {
  long long x;
  cin >> x;
  long long count = 0;
  long long last = 0;
  for (long long i = 0; (1 << i) <= x; i++) {
    if (((1 << i) & x) == 0) {
      last = i;
    }
    count++;
  }
  if (x == ((1 << count) - 1)) {
    cout << 0 << endl;
    return;
  }
  vector<long long> ans;
  long long small = 0;
  long long j = 0;
  while (x != ((1 << count) - 1)) {
    if (j > 40) {
      break;
    }
    last++;
    ans.push_back(last);
    x = x ^ ((1 << last) - 1);
    small++;
    if (x == ((1 << count) - 1)) {
      break;
    }
    x++;
    small++;
    last = 0;
    for (long long i = 0; (1 << i) <= x; i++) {
      if (((1 << i) & x) == 0) {
        last = i;
      }
    }
    j += 2;
  }
  cout << small << "\n";
  for (long long i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
