#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int T;
  T = 1;
  while (T--) {
    int x, z, n, i, j;
    cin >> x;
    vector<int> ans;
    int ct = 0, zz, pre = 0;
    int flag = 0;
    while (((x & (x + 1)) != 0)) {
      if (flag == 1) {
        ++x;
        flag = 1 - flag;
        ++ct;
        continue;
      }
      j = x;
      zz = 1;
      while (j > 0) {
        if (j % 2 == 0) {
          pre = zz;
        }
        j = j / 2;
        zz = zz * 2;
      }
      pre = pre * 2;
      ans.push_back(log2(pre));
      --pre;
      x = (x ^ pre);
      ++ct;
      flag = 1 - flag;
    }
    cout << ct << endl;
    for (i = 0; i < ans.size(); ++i) cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}
