#include <bits/stdc++.h>
using namespace std;
int msb0(int);
bool check(int);
int main() {
  int n;
  cin >> n;
  int count = 0;
  vector<int> v;
  while (check(n)) {
    int a = msb0(n);
    v.push_back(a);
    a = pow(2, a) - 1;
    n = n ^ a;
    count++;
    if (!(check(n))) break;
    n++;
    count++;
    if (!(check(n))) break;
  }
  cout << count << endl;
  if (count == 0) return 0;
  for (auto it = v.begin(); it != v.end(); it++) {
    cout << *it << " ";
  }
  return 0;
}
bool check(int x) {
  int y = 0, i = 1;
  while (x) {
    if (!(x & 1)) y = i;
    i = i * 2;
    x = x >> 1;
  }
  if (y == 0)
    return 0;
  else
    return 1;
}
int msb0(int x) {
  int y = 0, i = 0;
  while (x) {
    if (!(x & 1)) y = i;
    i++;
    x = x >> 1;
  }
  y++;
  return y;
}
