#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int x, i, j, n;
  cin >> x;
  vector<long long int> vec;
  long long int count = 0;
  while (true) {
    long long int y;
    for (i = 30; i >= 0; i--) {
      y = (1 << i);
      if (y <= x && (y & x) == 0) {
        count++;
        break;
      }
    }
    if (i == -1) break;
    y = y * 2;
    long long int z = log2(y);
    vec.push_back(z);
    y--;
    x = x ^ y;
    for (i = 30; i >= 0; i--) {
      y = (1 << i);
      if (y <= x && (y & x) == 0) {
        count++;
        break;
      }
    }
    if (i == -1) break;
    x++;
  }
  cout << count << endl;
  for (i = 0; i < vec.size(); i++) cout << vec[i] << " ";
}
