#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int base = 1e9;
const int MAX = 1e5;
const double EPS = 1e-9;
const double PI = acos(-1.);
int main() {
  int x;
  cin >> x;
  vector<int> res;
  int cnt = 0;
  for (int i = (0); i < (21); ++i) {
    int k = x;
    vector<int> d;
    while (k) {
      int t = k % 2;
      d.push_back(t);
      k = k / 2;
    }
    reverse(d.begin(), d.end());
    int sz = d.size();
    int n = -1;
    for (int j = (0); j < (sz); ++j) {
      if (d[j] == 0) {
        n = sz - j;
        break;
      }
    }
    if (n == -1) {
      cout << i * 2 << endl;
      for (int j = (0); j < (res.size()); ++j) {
        cout << res[j] << ' ';
      }
      return 0;
    }
    int t = (pow(2, n) - 1);
    x = x ^ t;
    res.push_back(n);
    bool ok = true;
    k = x;
    vector<int> p;
    while (k) {
      int t = k % 2;
      p.push_back(t);
      k = k / 2;
    }
    sz = p.size();
    for (int j = (0); j < (sz); ++j) {
      if (p[j] == 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cnt = (i)*2 + 1;
      cout << cnt << endl;
      for (int j = (0); j < (res.size()); ++j) {
        cout << res[j] << ' ';
      }
      return 0;
    }
    x++;
  }
  return 0;
}
