#include <bits/stdc++.h>
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
using namespace std;
int a[N], b[N];
int main() {
  int x;
  cin >> x;
  int cc = 0;
  std::vector<int> v;
  int t = x, m = 0;
  while (t) m++, t /= 2;
  t = x;
  for (int i = m; i >= 0; i--) {
    if (t & (1 << (i - 1))) continue;
    cc++;
    v.push_back(i);
    t ^= (1 << i) - 1;
    if (t + 1 == 1 << (m))
      break;
    else
      t++, cc++;
    if (t + 1 == 1 << (m)) break;
  }
  cout << cc << endl;
  for (auto e : v) cout << e << " ";
  return 0;
}
