#include <bits/stdc++.h>
using namespace std;
bool shu[30] = {};
int x;
int n[25] = {};
int find_1(int x) {
  int p = 0, i = 0;
  while (x) {
    int m = x & 1;
    if (p == 1 && m == 1) {
      break;
    }
    if (m == 1)
      p = 0;
    else
      p = 1;
    x >>= 1;
    i++;
  }
  return i;
}
bool per(int x) {
  int y = x;
  int i = 0, cnt1 = 0;
  while (y) {
    shu[i] = y & 1;
    if (shu[i] == 1) cnt1++;
    y >>= 1;
    i++;
  }
  if (x == pow(2, cnt1) - 1) {
    return true;
  } else
    return false;
}
void coutt(int sum, int j) {
  cout << sum << endl;
  for (int i = 0; i < j; i++) {
    cout << n[i] << " ";
  }
  cout << endl;
}
int main() {
  cin >> x;
  if (per(x)) {
    cout << 0 << endl;
    return 0;
  }
  int j = 0, sum = 0;
  while (1) {
    int dis = find_1(x);
    n[j] = dis;
    j++;
    sum++;
    int mm = pow(2, dis) - 1;
    x = x ^ mm;
    if (per(x)) {
      coutt(sum, j);
      return 0;
    }
    x += 1;
    sum++;
    if (per(x)) {
      coutt(sum, j);
      return 0;
    }
  }
}
