Как это уменьшить?
program hello;
var a: array of array of array of integer;
p: array of integer;
i, j,t,cnt, sum, w: integer;
m,n,k : integer;
begin
//writeln ('m=');
read (m);
//writeln (' n = ');
read (n);
//writeln ('k=');
read (k);
setlength (p, m+1);
for i: =1 to m do
read (p[i]);
setlength (a, n+1);
for i: =0 to n do
setlength (a[i], m+1);
for i: =0 to n do
for j: =0 to m do
setlength (a[i,j], k+1);
//for j: =1 to p[i]+1);
cnt: =0;
for i: =1 to n do
for j: =1 to m do
for t: =1 to p[j] do
begin
// writeln ('a[',i,j,t,']=');
read (a[i,j,t]);
end;
w: =0;
for i: =n downto 1 do
for j: =1 to m do
begin
cnt: =cnt+1;
sum: =0;
for t: =1 to p[j] do
//writeln (a[i,j,t]);
sum: =sum+(a[i,j,t]);
if sum=0 then begin w: =w+1; end;
end;
writeln (w); cnt: =0;
for i: =n downto 1 do
for j: =1 to m do
begin
cnt: =cnt+1;
sum: =0;
for t: =1 to p[j] do
//writeln (a[i,j,t]);
sum: =sum+(a[i,j,t]);
if sum=0 then begin w: =w+1; writeln (cnt); end;
end;
end.