const n = 5;
m = 5;
var
a: array[1..n, 1..m] of integer;
i, j, tmp, s_s: integer;
magic: boolean;
begin
magic := true;
for i := 1 to n do begin
for j := 1 to m do begin
a[i, j] := random(50);
write(a[i, j]:4);
if(i = 1) then s_s := s_s + a[i, j];
if(j mod m = 0) then writeln;
end;
end;
for i := 2 to n do begin
tmp := 0;
for j := 1 to m do begin
tmp := tmp + a[i, j];
end;
if(tmp <> s_s) then begin
magic := false;
break;
end;
end;
for i := 1 to n do begin
tmp := 0;
for j := 1 to m do begin
tmp := tmp + a[j, i];
end;
if(tmp <> s_s) then begin
magic := false;
break;
end;
end;
if(magic) then writeln('Матрица является магическим квадратом') else
writeln('Матрица не является магическим квадратом');
end.