Const
n = 3;
k = 3;
var
i,j,s1,s2:integer;
a:array[1..n,1..k] of integer;
begin
s1:=0;
s2:=0;
for i:=1 to n do
for j:=1 to k do
begin
Writeln('Введите a[',i,',',j,']:');
readln(a[i,j]);
if (a[i,j]>0) and (i<>j) then s1:=s1+a[i,j];
if (a[i,j]<0) and (i<>j) then s2:=s2+a[i,j];
end;
if s1>s2 then
for j:=1 to k do
begin
a[1,j]:=s1;
a[n,j]:=s1;
end;
if s2>=s1 then
for i:=1 to n do
begin
a[i,1]:=s2;
a[i,k]:=s2;
end;
writeln('Полученный массив:');
for i:=1 to n do
begin
for j:=1 to k do
write('a[':4,i,',',j,']=',a[i,j]);
writeln;
end;
end.