#!/usr/bin/perl
use 5.016;
use warnings;
no warnings
qw(recursion
); use List
::Util qw(reduce
);
sub f { $memo[$_[0]] //= 1 + f($_[0] % 2 ? ($_[0] + 1) * 3 : $_[0] / 2) }
say reduce{ f($b) > f($a) ? $b : $a } (1 .. 10000);
IyEvdXNyL2Jpbi9wZXJsCnVzZSA1LjAxNjsKdXNlIHdhcm5pbmdzOwpubyB3YXJuaW5ncyBxdyhyZWN1cnNpb24pOwp1c2UgTGlzdDo6VXRpbCBxdyhyZWR1Y2UpOwoKbXkgQG1lbW8gPSAoMCwgdW5kZWYsIHVuZGVmLCAwKTsKCnN1YiBmIHsgJG1lbW9bJF9bMF1dIC8vPSAxICsgZigkX1swXSAlIDIgPyAoJF9bMF0gKyAxKSAqIDMgOiAkX1swXSAvIDIpIH0KCnNheSByZWR1Y2V7IGYoJGIpID4gZigkYSkgPyAkYiA6ICRhIH0gKDEgLi4gMTAwMDApOwo=