#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const int maxn = 1e7 + 233;
int n, m, k, cnt;
vector<int> ans;
map<int, int> vis;
int get_first_0(int x) {
  for (int i = 20; i >= 0; i--) {
    if (x & (1 << i) || (1 << i) > x)
      ;
    else
      return i;
  }
  return -1;
}
int main() {
  for (int i = 0; i <= 20; i++) vis[(1 << i) - 1] = 1;
  scanf("%d", &n);
  m = n;
  while (true) {
    if (vis[m]) break;
    k = get_first_0(m);
    m ^= ((1 << (k + 1)) - 1);
    cnt++;
    ans.push_back(k + 1);
    if (vis[m]) break;
    m++;
    cnt++;
  }
  printf("%d\n", cnt);
  for (int i = 0; i < (cnt + 1) / 2; i++) printf("%d ", ans[i]);
  return 0;
}
