6 my @nums = split /\n/, <>;
9 for my $i (0 .. $#nums) {
10 for my $j (0 .. $#nums) {
12 my $r = add($nums[$i], $nums[$j]);
13 $max = $r if ($max < $r);
20 say "\nadd: $n1\nto: $n2";
21 my $res = "[$n1,$n2]";
27 for my $i (0 .. length($res)-1) {
28 $depth++ if substr($res, $i, 1) eq '[';
29 $depth-- if substr($res, $i, 1) eq ']';
33 next if $res !~ /\G\[(\d+),(\d+)\]/;
36 $res =~ s/\G\[(\d+),(\d+)\]/X/;
40 $res =~ s/(\d+)([^\d]*X)/($1+$l).$2/e;
41 $res =~ s/(X[^\d]*)(\d+)/"$1".($2+$r)/e;
48 if ($res =~ s|\d{2,}|'['.int($&/2).','.int(($&+1)/2).']'|e) {
54 1 while $res =~ s/\[(\d+),(\d+)\]/3*$1+2*$2/e;