#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int bi[45];
long long x;
bool valid(int x) { return !(x & (x + 1)); }
using namespace std;
int main() {
  cin >> x;
  queue<int> q;
  int ans = 0;
  while (!valid(x)) {
    int l = 0;
    while (x >> l) l++;
    l--;
    for (; (x >> l) & 1; l--)
      ;
    q.push(l + 1);
    ans++;
    x = x ^ ((1 << (l + 1)) - 1);
    if (valid(x)) break;
    ans++;
    x++;
  }
  cout << ans << endl;
  int f = 0;
  while (!q.empty()) {
    if (f) {
      cout << " ";
    }
    cout << q.front();
    q.pop();
    f = 1;
  }
  return 0;
}
