#include <iostream>
#include <vector>
#include <climits>
int main() {
int N;
std::cin >> N;
std::vector<int> steps(N + 1, INT_MAX);
steps[N] = 0;
std::vector<int> next_num(N + 1, -1);
for (int i = N; i > 1; --i) {
int s = steps[i] + 1;
// 3 * x
if (!(i % 3) && steps[i / 3] > s) {
steps[i / 3] = s;
next_num[i / 3] = i;
}
// 2 * x
if (!(i % 2) && steps[i / 2] > s) {
steps[i / 2] = s;
next_num[i / 2] = i;
}
// x + 1
if (steps[i - 1] > s) {
steps[i - 1] = s;
next_num[i - 1] = i;
}
}
std::cout << steps[1] << std::endl;
for (int i = 1; i != -1; i = next_num[i])
std::cout << i << ' ';
std::cout << std::endl;
}
CiAgICAjaW5jbHVkZSA8aW9zdHJlYW0+CiAgICAjaW5jbHVkZSA8dmVjdG9yPgogICAgI2luY2x1ZGUgPGNsaW1pdHM+CiAgICAKICAgIGludCBtYWluKCkgewogICAgICBpbnQgTjsKICAgICAgc3RkOjpjaW4gPj4gTjsKICAgICAgc3RkOjp2ZWN0b3I8aW50PiBzdGVwcyhOICsgMSwgSU5UX01BWCk7CiAgICAgIHN0ZXBzW05dID0gMDsKICAgICAgc3RkOjp2ZWN0b3I8aW50PiBuZXh0X251bShOICsgMSwgLTEpOwogICAgCiAgICAgIGZvciAoaW50IGkgPSBOOyBpID4gMTsgLS1pKSB7CiAgICAgICAgaW50IHMgPSBzdGVwc1tpXSArIDE7CiAgICAgICAgLy8gMyAqIHgKICAgICAgICBpZiAoIShpICUgMykgJiYgc3RlcHNbaSAvIDNdID4gcykgewogICAgICAgICAgc3RlcHNbaSAvIDNdID0gczsKICAgICAgICAgIG5leHRfbnVtW2kgLyAzXSA9IGk7CiAgICAgICAgfQogICAgICAgIC8vIDIgKiB4CiAgICAgICAgaWYgKCEoaSAlIDIpICYmIHN0ZXBzW2kgLyAyXSA+IHMpIHsKICAgICAgICAgIHN0ZXBzW2kgLyAyXSA9IHM7CiAgICAgICAgICBuZXh0X251bVtpIC8gMl0gPSBpOwogICAgICAgIH0KICAgICAgICAvLyB4ICsgMQogICAgICAgIGlmIChzdGVwc1tpIC0gMV0gPiBzKSB7CiAgICAgICAgICBzdGVwc1tpIC0gMV0gPSBzOwogICAgICAgICAgbmV4dF9udW1baSAtIDFdID0gaTsKICAgICAgICB9CiAgICAgIH0KICAgIAogICAgICBzdGQ6OmNvdXQgPDwgc3RlcHNbMV0gPDwgc3RkOjplbmRsOwogICAgICBmb3IgKGludCBpID0gMTsgaSAhPSAtMTsgaSA9IG5leHRfbnVtW2ldKQogICAgICAgIHN0ZDo6Y291dCA8PCBpIDw8ICcgJzsKICAgICAgc3RkOjpjb3V0IDw8IHN0ZDo6ZW5kbDsKICAgIH0=