#include <bits/stdc++.h>
using namespace std;
int msb(long long int n) {
  int f = 1;
  while ((1LL << f) <= n) f++;
  return f - 1;
}
bool is2m(long long int n) {
  int count = 0;
  while (n) {
    int b = n % 2;
    if (b) count++;
    n /= 2;
  }
  if (count == 1)
    return true;
  else
    return false;
}
bool is2m_1(long long int n) {
  int count = 0;
  while (n) {
    int b = n % 2;
    if (b == 0) count++;
    n /= 2;
  }
  if (count > 0)
    return false;
  else
    return true;
}
int main() {
  long long int x;
  cin >> x;
  int flag = 1;
  int i = 1;
  vector<int> ans;
  int count = 0;
  while (flag) {
    if (is2m_1(x)) break;
    if (i % 2) {
      if (is2m(x)) {
        long long int w = msb(x);
        long long int m = w;
        w = (1LL << w) - 1;
        x = x ^ w;
        ans.push_back(m);
        count++;
      } else {
        long long int w = msb(x) + 1;
        long long int m = w;
        w = (1LL << w) - 1;
        x = x ^ w;
        ans.push_back(m);
        count++;
      }
    } else {
      count++;
      x = x + 1;
    }
    i++;
  }
  cout << count << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
  return 0;
}
