#include <bits/stdc++.h>
using namespace std;
int dig[1000];
long long ans[1000];
int main() {
  int n;
  cin >> n;
  int nn = n, cnt = 0;
  while (nn) {
    dig[cnt++] = nn % 2;
    nn /= 2;
  }
  int num = 0;
  for (int i = 0; i < cnt; i++)
    if (dig[i]) num++;
  if (num == cnt)
    cout << 0 << endl;
  else {
    int tot = 0;
    int cishu = 0;
    while (1) {
      int pos = -1;
      for (int i = 0; i < cnt; i++) {
        if (!dig[i]) pos = i;
      }
      ans[tot++] = pos + 1;
      for (int i = pos; i >= 0; i--) {
        if (dig[i] == 0)
          dig[i] = 1;
        else
          dig[i] = 0;
      }
      cishu++;
      int nnn = 0;
      for (int i = 0; i < cnt; i++)
        if (dig[i]) nnn++;
      if (nnn == cnt) break;
      if (dig[0] == 0)
        dig[0] = 1;
      else {
        int k = 0;
        while (dig[k]) k++;
        if (k == cnt) {
          ans[tot++] = k;
          cishu++;
          break;
        } else {
          for (int i = 0; i < k; i++) dig[i] = 0;
          dig[k] = 1;
        }
      }
      cishu++;
      nnn = 0;
      for (int i = 0; i < cnt; i++)
        if (dig[i]) nnn++;
      if (nnn == cnt) break;
    }
    cout << cishu << endl;
    for (int i = 0; i < tot; i++) cout << ans[i] << ' ';
  }
}
