function solve($num, $count)
{
$a = [
"111" => "a",
"11" => "b",
"1" => "c",
"222" => "d",
"22" => "e",
"2" => "f",
"333" => "g",
"33" => "h",
"3" => "i",
];
$b = [
"a" => "31",
"b" => "21",
"c" => "11",
"d" => "32",
"e" => "22",
"f" => "12",
"g" => "33",
"h" => "23",
"i" => "13",
];
for ($i = 0; $i < $count; $i++) {
$c = str_replace(array_keys($a), array_values($a), $num);
$num = str_replace(array_keys($b), array_values($b), $c);
}
return strlen($num);
}
$solution_1 = solve((string) $input, 40);
$solution_2 = solve((string) $input, 50);