#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int er[100];
bool odd = false;
bool check(int x) {
  int flag = 0;
  while (x != 0) {
    if (x % 2 == 0) return false;
    x /= 2;
  }
  return true;
}
void run(int &x) {
  int flag = 0;
  vector<int> a;
  a.clear();
  int t = x;
  while (t != 0) {
    a.push_back(t % 2);
    t /= 2;
  }
  for (int i = a.size() - 1; i >= 0; i--) {
    if (a[i] == 0) {
      ans.push_back(i);
      x = x xor er[i + 1];
      break;
    }
  }
  if (check(x)) {
    odd = true;
    return;
  }
  x++;
}
int main() {
  er[1] = 1;
  for (int i = 2; i <= 41; i++) {
    er[i] = er[i - 1] * 2 + 1;
  }
  int x;
  cin >> x;
  ans.clear();
  while (!check(x)) {
    run(x);
  }
  if (!odd)
    cout << ans.size() * 2 << endl;
  else
    cout << ans.size() * 2 - 1 << endl;
  for (int i = 0; i < ans.size(); i++) {
    if (i != ans.size() - 1)
      cout << ans[i] + 1 << " ";
    else
      cout << ans[i] + 1 << endl;
  }
  return 0;
}
