#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  int t;
  cin >> t;
  int ans = 0;
  vector<int> vec;
  bool fl = 1;
  while (fl) {
    int xx = 0;
    for (xx = 0; (1 << xx) <= t; xx++)
      ;
    if ((1 << xx) - 1 == t) {
      fl = 0;
      break;
    }
    vec.push_back(xx);
    t ^= (1 << xx) - 1;
    ans++;
    xx = 0;
    for (xx = 0; (1 << xx) <= t; xx++)
      ;
    if ((1 << xx) - 1 == t) {
      fl = 0;
      break;
    }
    ans++;
    t++;
  }
  cout << ans << "\n";
  for (int x : vec) {
    cout << x << " ";
  }
  cout << "\n";
}
