#include <bits/stdc++.h>
using namespace std;
long long nMod = 1e9 + 7;
inline long long GCD(long long a, long long b) {
  while (b != 0) {
    long long c = a % b;
    a = b;
    b = c;
  }
  return a;
};
inline long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; };
int n;
int arr[25];
bool check(int n) {
  int l = log2(n);
  for (int i = l; i >= 0; i--) {
    if (((n >> i) & 1) == 0) {
      return false;
    }
  }
  return true;
}
vector<int> step;
void vietnakid() {
  int p = 1;
  for (int i = 0; i < 25; i++) {
    p *= 2;
    arr[i] = p - 1;
  }
  cin >> n;
  int l = log2(n);
  for (int i = l; i >= 0; i--) {
    if (((n >> i) & 1) == 0) {
      n ^= arr[i];
      step.push_back(i + 1);
      if (check(n)) {
        break;
      }
      n++;
      step.push_back(1000000007);
    }
  }
  cout << step.size() << "\n";
  for (int i = 0; i < step.size(); i += 2) {
    cout << step[i] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  vietnakid();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
