#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int MAX = 2e5 + 10;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int find(int x) {
  int aa = 0, bb = -1;
  while (x != 0) {
    if (x % 2 == 0) bb = aa;
    aa++;
    x /= 2;
  }
  if (bb == -1) return -1;
  return bb + 1;
}
int v[50];
int main() {
  int x;
  cin >> x;
  int i = -1, sum = 0;
  if (find(x) == -1) {
    cout << '0';
    return 0;
  }
  while (find(x) != -1) {
    sum++;
    int n = find(x);
    i++;
    v[i] = find(x) + 1;
    x = x ^ ((int)pow(2, find(x)) - 1);
    if (find(x) != -1) {
      x = x + 1;
      sum++;
    }
  }
  cout << sum << '\n';
  for (int j = 0; j <= i; j++) {
    cout << v[j] - 1 << ' ';
  }
}
