#include <bits/stdc++.h>
using namespace std;
string binary(long long n) {
  string s;
  vector<long long> v;
  while (n >= 2) {
    v.push_back(n % 2);
    n /= 2;
  }
  v.push_back(n);
  for (long long i = v.size() - 1; i >= 0; i--) {
    s += v[i] + '0';
  }
  return s;
}
long long dec(string s) {
  long long dec = 0;
  for (long long i = s.size() - 1; i >= 0; i--) {
    dec += (s[i] - '0') * (pow(2, s.size() - i - 1));
  }
  return dec;
}
bool check_if_possible(string s) {
  long long count = 0;
  for (long long j = s.size() - 1; j >= 0; j--) {
    if (s[j] == '1') count++;
  }
  if (count == s.size()) return false;
  return true;
}
long long reqno(string s) {
  long long max_so_far = 0;
  for (long long i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '0') max_so_far = s.size() - i;
  }
  return max_so_far;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v;
  long long T = 0;
  while (T <= 40) {
    string s = binary(n);
    if (check_if_possible(s) == true) {
      long long req = pow(2, reqno(s)) - 1;
      long long r = reqno(s);
      v.push_back(r);
      n = dec(s) ^ req;
      T++;
    } else
      break;
    s = binary(n);
    if (check_if_possible(s) == true) {
      n++;
      T++;
    } else
      break;
  }
  cout << T << endl;
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
}
