Why error on test 2? Where is mistake?
var a:array[1..100,1..100]of longint;
k,cc,ii,jj,ic,n,i,j,numb:longint;
begin
readln(n);
for i:=1 to n do
begin
for j:=1 to n-1 do
read(a[i,j]);
readln(a[i,j+1]);
end;
cc:=1;ic:=1;i:=1;j:=1;numb:=1;
while numb<=n*n do
begin
ii:=i;jj:=j;
for k:=1 to cc do
begin
write(a[ii,jj],' ');
inc(numb);
dec(ii);
inc(jj);
end;
inc(i);
if i>n then
begin
i:=n;
inc(j);
end;
if cc> (N*2-1) div 2
then ic:=-1;
inc(cc,ic);
end;
end.