#include <stdlib.h>
#include <stdio.h>
int main (int argc, char *argv[]) {
int n = 100000;
int *result
= malloc((n
+1) * sizeof(int)); for (int i = 1; i <= n; i++) {
result[i] = -1;
}
for (int i = 1; i <= n; i++) {
int s = 0;
for (long x = i; x != 1; s++) {
if (x <= n && result[x] != -1) {
s += result[x];
break;
}
x = (x % 2 == 0) ? x / 2 : 3 * x + 1;
}
result[i] = s;
}
int max = 0;
for (int i = 1; i <= n; i++) {
if (max < result[i]) {
max = result[i];
}
}
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KCmludCBtYWluIChpbnQgYXJnYywgY2hhciAqYXJndltdKSB7CiAgICBpbnQgbiA9IDEwMDAwMDsKICAgIGludCAqcmVzdWx0ID0gbWFsbG9jKChuKzEpICogc2l6ZW9mKGludCkpOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSB7CiAgICAgICAgcmVzdWx0W2ldID0gLTE7CiAgICB9CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICBpbnQgcyA9IDA7CiAgICAgICAgZm9yIChsb25nIHggPSBpOyB4ICE9IDE7IHMrKykgewogICAgICAgICAgICBpZiAoeCA8PSBuICYmIHJlc3VsdFt4XSAhPSAtMSkgewogICAgICAgICAgICAgICAgcyArPSByZXN1bHRbeF07CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICB4ID0gKHggJSAyID09IDApID8geCAvIDIgOiAzICogeCArIDE7CiAgICAgICAgfQogICAgICAgIHJlc3VsdFtpXSA9IHM7CiAgICB9CiAgICBpbnQgbWF4ID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGlmIChtYXggPCByZXN1bHRbaV0pIHsKICAgICAgICAgICAgbWF4ID0gcmVzdWx0W2ldOwogICAgICAgIH0KICAgIH0KICAgIHByaW50ZigiJWRcbiIsIG1heCk7Cn0=