function array_distance (dimension, n, m:integer): array [,] of integer;
begin
var i, j, i1, j1, count, count_row:integer;
var arr: array [,] of integer;
arr := new integer[dimension, dimension];
for i := 0 to n - 1 do begin
for j := 0 to m - 1 do begin
for i1 := 0 to n - 1 do begin
for j1 := 0 to m - 1 do begin
if(count_row = dimension) then begin
break;
end;
if(count < dimension) then begin
arr[count, count_row] := abs(i1 - i) + abs(j1 - j);
count := count + 1;
end;
if(count = dimension) then begin
count := 0;
count_row := count_row + 1;
end;
end;
end;
end;
end;
array_distance:=arr;
end;