#include <bits/stdc++.h>
using namespace std;
const long long mod = 7 + 1e9;
const long long N = 400004;
bool prime[N];
const long long H = 64;
void isprime() {
  memset(prime, true, N);
  for (long long i = 2; i * i < N; i++) {
    if (prime[i] == true) {
      for (long long j = i * i; j < N; j += i) {
        prime[j] = false;
      }
    }
  }
}
long long power(long long a, long long n) {
  long long ans = 1;
  a = a % mod;
  while (n > 0) {
    if (n & 1) {
      ans = (ans * a) % mod;
    }
    n = n >> 1;
    a = (a * a) % mod;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x;
  cin >> x;
  vector<long long> s;
  long long m = 0;
  if (x == 1) {
    cout << "0";
    return 0;
  }
  while (1) {
    long long t = floor(log2(x) + 1);
    if (x == pow(2, t) - 1) {
      break;
    }
    bitset<H> b(x);
    long long i;
    for (i = t - 1; i >= 0; i--) {
      if (b[i] == 0) {
        break;
      }
    }
    long long p = pow(2, i + 1) - 1;
    s.push_back(i + 1);
    m++;
    x = x ^ p;
    if (x == pow(2, t) - 1) {
      break;
    }
    x++;
    m++;
    if (x == pow(2, t) - 1) {
      break;
    }
  }
  cout << m << endl;
  for (long long i = 0; i < s.size(); i++) {
    cout << s[i] << " ";
  }
  return 0;
}
