#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return (b == 0) ? a : gcd(b, a % b);
}
const unsigned int MOD = 1000000007;
template <class T>
T power(T a, long long int n) {
  T res = 1;
  while (n > 0) {
    if (n % 2) res = res * a;
    a = a * a, n = n / 2;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int count = 0;
  long long int n;
  cin >> n;
  vector<long long int> ans;
  ;
  bool flag = 1;
  while (1) {
    if (__builtin_popcount(n) == 32 - __builtin_clz(n))
      break;
    else if (flag == 1) {
      long long int f = 32 - __builtin_clz(n);
      f--;
      long long int temp = 1 << f;
      while (temp & n) temp = temp >> 1;
      temp = temp << 1;
      ans.push_back(32 - __builtin_clz(temp) - 1);
      n = n xor (temp - 1);
      flag = 0;
    } else {
      flag = 1;
      n += 1;
    }
    count++;
  }
  if (ans.size() == 0)
    cout << 0 << endl;
  else {
    cout << count << endl;
    ;
    for (int i = 0; i < ans.size(); i++) cout << ans.at(i) << " ";
    ;
  }
}
