#include <bits/stdc++.h>
int a[10];
int i;
int convert(int n) {
  for (i = 0; n > 0; i++) {
    a[i] = n % 2;
    n = n / 2;
  }
  return i;
}
int main() {
  int x, j, flag = 0, count = 0, sum = 0, temp, nol = 0, noo = 0, k = 0;
  scanf("%d", &x);
  int arr[40];
  convert(x);
  while (k < 40) {
    if ((pow(2, i) - 1) == x || (pow(2, i + 1) - 1) == x) {
      printf("0");
      return 0;
    }
    flag = 0;
    count = 0;
    sum = 0;
    for (j = 0; j < i; j++) {
      if ((a[j] == 0 && a[j + 1] == 1) && flag != 1) {
        a[j] = 1 - a[j];
        flag = 1;
      } else if (!(a[j] == 0 && a[j + 1] == 1) && flag != 1) {
        a[j] = 1 - a[j];
        count++;
      }
      sum += (pow(2, j)) * a[j];
    }
    noo++;
    arr[k] = count + 1;
    k++;
    if ((pow(2, i) - 1) == sum || (pow(2, i + 1) - 1) == sum) {
      printf("%d\n", noo);
      break;
    } else if ((pow(2, i) - 1) == sum + 1 || (pow(2, i + 1) - 1) == sum + 1) {
      noo++;
      printf("%d\n", noo);
      break;
    } else
      convert(sum + 1);
    noo++;
  }
  for (i = 0; i < k; i++) printf("%d ", arr[i]);
}
