#include <bits/stdc++.h>
using namespace std;
template <class T>
constexpr T lcm(T m, T n) {
  return m / __gcd(m, n) * n;
}
template <typename I>
void join(ostream &ost, I s, I t, string d = " ") {
  for (auto i = s; i != t; ++i) {
    if (i != s) ost << d;
    ost << *i;
  }
  ost << endl;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &a : v) is >> a;
  return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
bool chmin(T &a, const U &b) {
  return (a > b ? a = b, true : false);
}
template <typename T, typename U>
bool chmax(T &a, const U &b) {
  return (a < b ? a = b, true : false);
}
template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}
vector<int> b(31);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k = 1;
  for (int i = (0); i <= (30); ++i) {
    b[i] = k - 1;
    k *= 2;
  }
  ((void)0);
  int x;
  while (cin >> x) {
    vector<int> ans;
    int k = 0;
    for (long long int i = 1; i <= x; i *= 2) {
      k++;
    }
    ((void)0);
    ((void)0);
    int cnt = 0;
    for (int i = (k - 1); i >= (0); --i) {
      if ((x & (1 << i)) == 0) {
        x ^= ((1 << (i + 1)) - 1);
        ans.push_back(i + 1);
        ((void)0);
        ++cnt;
        if (count((b).begin(), (b).end(), x)) {
          break;
        }
        x += 1;
        ((void)0);
        ++cnt;
        if (count((b).begin(), (b).end(), x)) {
          break;
        }
      }
    }
    ((void)0);
    cout << cnt << endl;
    join(cout, (ans).begin(), (ans).end());
  }
  return 0;
}
