#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long expo(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long ret = expo(a, b / 2);
    ret = (ret * ret) % 1000000007;
    return ret;
  } else {
    long long ret = expo(a, b / 2);
    ret = (ret * ret) % 1000000007;
    ret = (ret * a) % 1000000007;
    return ret;
  }
}
bool is_prime(long long x) {
  if (x == 1) return false;
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
int arr[200005], sze[200005];
int root(int i) {
  while (arr[i] != i) i = arr[arr[i]];
  return i;
}
void unionn(int u, int v) {
  int a = root(u);
  int b = root(v);
  if (a == b) return;
  if (sze[a] > sze[b]) swap(a, b);
  arr[a] = arr[b];
  sze[b] += sze[a];
}
long long inf = 1e18;
int main() {
  int n;
  vector<int> b;
  cin >> n;
  while (n) {
    b.push_back(n & 1);
    n = n >> 1;
  }
  int ans = 0;
  vector<int> f;
  reverse(b.begin(), b.end());
  for (int i = 0; i < b.size(); i++) {
    if (b[i] == 0) {
      ans++;
      f.push_back(b.size() - i);
      for (int j = i; j < b.size(); j++) {
        b[j] = (b[j] + 1) % 2;
      }
      bool g = true;
      for (int k = 0; k < b.size(); k++) {
        if (b[k] == 0) g = false;
      }
      if (g) break;
      for (int k = b.size() - 1; k >= i; k--) {
        if (b[k] == 1)
          b[k] = 0;
        else {
          ans++;
          b[k] = 1;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  for (int i = 0; i < f.size(); i++) cout << f[i] << ' ';
}
