#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  vector<int> v;
  int x, st, y, op = 0;
  cin >> x;
  if (x == 0 || x == 1 || x == 3 || x == 7 || x == 15 || x == 31 || x == 63 ||
      x == 127 || x == 255 || x == 511 || x == 1023 || x == 2047 || x == 4095 ||
      x == 8191 || x == 16383 || x == 32767 || x == 65535 || x == 131071 ||
      x == 262143 || x == 524287) {
    cout << op;
    return 0;
  }
  while (true) {
    y = x;
    st = 1;
    while (y != 1) {
      y /= 2;
      st++;
    }
    x ^= ((int)pow(2, st) - 1);
    op++;
    v.push_back(st);
    if (x == 0 || x == 1 || x == 3 || x == 7 || x == 15 || x == 31 || x == 63 ||
        x == 127 || x == 255 || x == 511 || x == 1023 || x == 2047 ||
        x == 4095 || x == 8191 || x == 16383 || x == 32767 || x == 65535 ||
        x == 131071 || x == 262143 || x == 524287) {
      cout << op;
      break;
    }
    x++;
    op++;
    if (x == 0 || x == 1 || x == 3 || x == 7 || x == 15 || x == 31 || x == 63 ||
        x == 127 || x == 255 || x == 511 || x == 1023 || x == 2047 ||
        x == 4095 || x == 8191 || x == 16383 || x == 32767 || x == 65535 ||
        x == 131071 || x == 262143 || x == 524287) {
      cout << op;
      break;
    }
  }
  cout << endl;
  for (int i : v) {
    cout << i << " ";
  }
  return 0;
}
