#include <bits/stdc++.h>
const int mo = 1000000007;
const int inf = 0x3f3f3f3f;
double pi = 3.14159265358979323846;
double e = 2.71828182845904523536;
using namespace std;
void read(int &x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' && ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
vector<int> v;
int fun(int x) {
  int y = x;
  stack<int> s;
  while (x) {
    s.push(x % 2);
    x /= 2;
  }
  int cnt = s.size();
  while (!s.empty()) {
    if (s.top() == 0) {
      break;
    }
    s.pop();
    cnt--;
  }
  y = y ^ ((1 << cnt) - 1);
  v.push_back(cnt);
  return y;
}
bool check(int x) {
  while (x) {
    if (x % 2 == 0) return false;
    x /= 2;
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  int flag = 1;
  int ans = 0;
  while (1) {
    if (check(n)) break;
    if (flag)
      n = fun(n);
    else
      n++;
    flag = !flag;
    ans++;
  }
  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << ' ';
  cout << endl;
  return 0;
}
