const n = 3; a: array[1 .. n, 1 .. n] of integer = ((1, 2, 3), (4, 5, 6), (7, 8, 9)); var steps: array[1 .. 2*n - 1] of byte; var i, j, ii, jj: integer; begin j := 0; for i := 2*n-1 downto 1 do begin if odd(i) then inc(j); steps[i] := j end; j := 0; ii := 1; jj := 0; repeat if j < 2*n-1 then begin inc(j); for i := 1 to steps[j] do begin inc(jj); write(a[ii, jj]:5); end; end; if j < 2*n-1 then begin inc(j); for i := 1 to steps[j] do begin inc(ii); write(a[ii, jj]:5); end; end; if j < 2*n-1 then begin inc(j); for i := 1 to steps[j] do begin dec(jj); write(a[ii, jj]:5); end; end; if j < 2*n-1 then begin inc(j); for i := 1 to steps[j] do begin dec(ii); write(a[ii, jj]:5); end; end; until j = (2*n - 1); writeln; end.