//Pascal ABC.NET v3.0 сборка 1111
Var
ma:array of array of integer;
n,m,i,j,res:integer;
b:boolean;
begin
randomize;
res:=1;
b:=false;
read(m,n);
setlength(ma,m);
for i:=0 to m-1 do
setlength(ma[i],n);
writeln('First matrix:');
for i:=0 to m-1 do
begin
writeln;
for j:=0 to n-1 do
begin
ma[i,j]:=random(10);
write(ma[i,j]:5);
end;
end;
if n>m then
begin
for i:=0 to m-1 do
for j:=i+1 to n-1 do
if ma[i,j]>0 then
begin;
res:=res*ma[i,j];
b:=true;
end;
end
else
begin
for i:=0 to n-1 do
for j:=i+1 to n-1 do
if ma[i,j]>0 then
begin;
res:=res*ma[i,j];
b:=true;
end;
end;
if b=false then res:=0;
writeln;
writeln('Final array:');
for i:=0 to m-1 do
begin
writeln;
for j:=0 to n-1 do
begin
if ma[i,j]=0 then ma[i,j]:=res;
write(ma[i,j]:5);
end;
end;
writeln;
writeln('res=',res);
end.