#include<cstdio>
#include<vector>
int main() {
int n;
scanf("%d", &n);
int bits = 1;
int pow_bits = 1;
int moc = 1;
int x = 1;
while (moc < n) {
pow_bits *= 2;
moc += pow_bits + moc;
bits += 1;
x <<= 1;
x += 1;
// printf(">> bits:%d moc:%d x:%d\n", bits, moc, x);
}
std::vector<int> ret;
while (n > 0) {
while (moc - __builtin_popcount(x) >= n) {
moc -= __builtin_popcount(x);
--x;
// printf("<< bits:%d moc:%d x:%d\n", bits, moc, x);
}
//printf("%d\n", x);
ret.push_back(x);
n -= __builtin_popcount(x);
moc -= __builtin_popcount(x);
x--;
// printf("\t n:%d moc:%d x:%d\n", n, moc, x);
}
printf("%zu\n", ret.size());
for (auto x : ret)
printf("%d ", x);
printf("\n");
return 0;
}