#include <bits/stdc++.h>
using namespace std;
int a[100], b[45], c[100];
int main() {
  int x;
  cin >> x;
  int p = 0, ans = 0, q = 0, f = 0;
  while (x) {
    c[p++] = x % 2;
    if (x % 2 == 0) f = 1;
    x = x / 2;
  }
  int pp = 0;
  for (int h = p - 1; h >= 0; h--) {
    a[pp++] = c[h];
  }
  if (f) {
    while (ans + 1) {
      int flag = 0, flag1 = 0, flag2 = 0;
      for (int i = 0; i < p; i++) {
        if (flag) {
          if (a[i] == 1)
            a[i] = 0;
          else if (a[i] == 0)
            a[i] = 1;
        } else if (a[i] == 0) {
          ans++;
          a[i] = 1;
          flag = 1;
          b[q++] = p - i;
        }
      }
      for (int i = 0; i < p; i++) {
        if (a[i] == 0) {
          break;
        }
        if (i == p - 1) {
          flag1 = 1;
        }
      }
      if (flag1) {
        break;
      }
      ans++;
      for (int j = p - 1; j >= 0; j--) {
        a[j]++;
        if (a[j] == 2)
          a[j] = 0;
        else if (a[j] = 1)
          break;
      }
      for (int i = 0; i < p; i++) {
        if (a[i] == 0) {
          break;
        }
        if (i == p - 1) {
          flag2 = 1;
        }
      }
      if (flag2) {
        break;
      }
    }
    cout << ans << endl;
    for (int k = 0; k < q; k++) {
      if (k == 0)
        cout << b[k];
      else
        cout << ' ' << b[k];
    }
    cout << endl;
  } else {
    cout << 0 << endl;
  }
}
