#include <bits/stdc++.h>
using namespace std;
int F(int x) {
  int mx = 0, i = 1;
  while (x) {
    if (x % 2 == 0) {
      mx = i;
    }
    x = x / 2;
    i++;
  }
  return mx;
}
int P(int t) {
  int sum = 1, i;
  for (i = 1; i <= t; i++) {
    sum = sum * 2;
  }
  return sum;
}
int main() {
  int x, i = 0, j, a, t;
  while (cin >> x) {
    int A[45];
    for (i = 0, j = 0; j <= 40;) {
      A[i] = F(x);
      if (A[i++] == 0) {
        i--;
        break;
      }
      j++;
      t = A[i - 1];
      a = P(t) - 1;
      x = x ^ a;
      a = F(x);
      if (a == 0) {
        break;
      }
      j++;
      x += 1;
    }
    cout << j << endl;
    for (j = 0; j < i; j++) {
      if (j == 0) {
        cout << A[j];
      } else
        cout << " " << A[j];
    }
    cout << endl;
  }
  return 0;
}
