#include <bits/stdc++.h>
using namespace std;
int func(int n) {
  int i = 1, val = 1, ans = 0;
  while (val <= n) {
    if ((val & n) == 0) {
      ans = i;
    }
    i++;
    val *= 2;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    int n;
    cin >> n;
    int steps = 0;
    vector<int> ans;
    while (func(n) != 0) {
      steps++;
      ans.push_back(func(n));
      n = n ^ ((int)(pow(2, func(n))) - 1);
      if (func(n) == 0) {
        break;
      } else {
        n++;
        steps++;
      }
    }
    cout << steps << "\n";
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
  }
}
