#include <bits/stdc++.h>
using namespace std;
bool longcat(int x) {
  x++;
  return !(x - (x & (-x)));
}
vector<int> ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("case.in", "r")) freopen("case.in", "r", stdin);
  int x;
  cin >> x;
  int i;
  for (i = 19; !(x & (1 << i)); --i)
    ;
  int t = 0;
  while (!longcat(x)) {
    if (x & (1 << i)) {
      ans.push_back(0);
      t++;
    } else {
      ans.push_back(i + 1);
      x ^= (1 << (i + 1)) - 1;
      t++;
    }
    if (!longcat(x)) {
      x++;
      t++;
    }
    i--;
  }
  cout << t << "\n";
  for (int x : ans) cout << x << " ";
  cout << "\n";
  return 0;
}
