#include <bits/stdc++.h>
const int N = 1e5 + 5;
const int M = 1e3 + 5;
const long long MOD = 1e9 + 7;
const long long INF = 66;
const double Exp = 1e-8;
const double PI = acos(-1);
using namespace std;
int x;
int ans[INF];
int cnt = 0;
int lowerbit(int x) { return x & (-x); }
int getdit(int val) {
  int tcnt = 0;
  while (val) {
    tcnt++;
    val >>= 1;
  }
  return tcnt;
}
bool judge(int val) {
  int pos = getdit(val);
  return ((1 << pos) - 1) == val;
}
int main() {
  int t = 0;
  scanf("%d", &x);
  int big = getdit(x);
  int pos = big - 1;
  big = 1 << (big - 1);
  while (x != 0) {
    if (judge(x)) {
      break;
    }
    if ((big & x) == 0) {
      x = x ^ (big * 2 - 1);
      t++;
      ans[cnt++] = pos + 1;
      if (judge(x)) {
        break;
      }
      x++;
      t++;
      if (judge(x)) {
        break;
      }
    }
    big >>= 1;
    pos--;
  }
  printf("%d\n", t);
  for (int i = 0; i < cnt; ++i) printf("%d ", ans[i]);
}
