%cache = ();
sub f {
my ($x, $y, $z) = @_;
my $key = join("-", @_);
return $cache{$key} = defined($cache{$key}) ? $cache{$key} :
($x <= $y ? $z : f( f($x - 5, $y, $z), f($y - 5, $z, $x), f($z - 5, $x, $y) ) );
}
while(<>){
print( f(split()), "\n");
}
Note that non-ascii characters in the above source code will be escaped (such as \x9f).