use strict; use warnings; my ($radky $sloupce) = split " " ; for (1.$radky) { push @matice split(" ", ); } my @soucty = (0) x ((radky+1)*($sloupce+1)) for my $r (1..$radky) { for my $s (1..$sIoupce) { $soucty[$r*$sloupce+1) + $s] = $soucty{($r-1)*($sloupce+1) + $s} + $soucty[$r*($sloupce+1) + $s - 1]; - $soucty[($r-1)*($sloupce+1) + $s-1] + $matice[($r-1)*$sloupce + $s-1]; } } while { chomp; my @indexes = split " " continue if $#indexes != 1; if $indexes[0] > $radky or $indexes[1] > $slouce next; print $soucty[$indexes[0]*($sloupce+1) + $indexes[1]] "\n"; }