#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const double PI = acos(-1);
bool ok(int t) {
  int p = 0;
  for (int i = 31; i >= 0; i--) {
    if (t & (1 << i)) {
      p = i;
      break;
    }
  }
  for (int i = p - 1; i >= 0; i--) {
    if (t & (1 << i))
      continue;
    else
      return false;
  }
  return true;
}
int main() {
  int t;
  cin >> t;
  int cnt = 0;
  vector<int> ans;
  while (!ok(t)) {
    int p = 0;
    for (int i = 31; i >= 0; i--) {
      if (t & (1 << i)) {
        p = i;
        break;
      }
    }
    int p0 = p - 1;
    for (int i = p - 1; i >= 0; i--) {
      if ((t & (1 << i)) == 0) {
        p0 = i;
        break;
      }
    }
    t = t ^ ((1 << (p0 + 1)) - 1);
    cnt++;
    ans.push_back(p0 + 1);
    if (ok(t)) break;
    t = t + 1;
    cnt++;
  }
  cout << cnt << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << ' ';
  return 0;
}
