#include <bits/stdc++.h>
template <class C>
C& mini(C& a, C b) {
  if (b < a) a = b;
  return a;
}
template <class C>
C& maxi(C& a, C b) {
  if (a < b) a = b;
  return a;
}
using namespace std;
template <typename T>
void read(T& x) {
  x.read();
}
template <typename T>
void read(vector<T>& v) {
  for (T& x : v) read(x);
}
template <typename X, typename Y>
void read(pair<X, Y>& p) {
  read(p.first);
  read(p.second);
}
template <>
void read(int& x) {
  scanf("%d", &x);
}
template <>
void read(unsigned int& x) {
  scanf("%u", &x);
}
template <>
void read(long long& x) {
  scanf("%lld", &x);
}
template <>
void read(unsigned long long& x) {
  scanf("%llu", &x);
}
template <typename T>
void readv(vector<T>& v) {
  int N;
  read(N);
  v.resize(N);
  read(v);
}
template <typename T, typename... Ts>
void read(T& x, Ts&... args) {
  read(x);
  read(args...);
}
int main(int argc, const char* argv[]) {
  int x;
  read(x);
  std::vector<int> ops;
  while (x & (x - 1)) {
    int n = __builtin_ctz(x);
    ops.push_back(n);
    x ^= (1 << n) - 1;
    x++;
  }
  printf("%d\n", ops.size() * 2 + 1);
  for (int d : ops) printf("%d ", d);
  printf("%d\n", __builtin_ctz(x));
  return 0;
}
