#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class T>
ostream &operator<<(ostream &os, set<T> V) {
  os << "{";
  for (auto vv : V) os << vv << ",";
  return os << "}";
}
const int inf = 1e9 + 1;
const int C = 27;
const int N = 1000123;
int z, n, m, second;
int largest_bit(int second) {
  int r = 0;
  for (int i = 0; i < 30; i++) {
    if (((1 << i) & second)) r = i;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> second;
  vector<int> res;
  int k = 1;
  while ((second & (second + 1)) != 0) {
    if (k % 2) {
      int b = largest_bit(second);
      second ^= (1 << (b + 1)) - 1;
      res.push_back(b + 1);
    } else {
      second++;
    }
    k++;
  }
  cout << k - 1 << endl;
  for (int r : res) {
    cout << r << " ";
  }
  cout << endl;
  return 0;
}
