# Cod sursa(job #8062)

Utilizator Data 23 ianuarie 2007 19:40:30 Dame 5 fpc done Arhiva de probleme 2.67 kb
``````program dame;
var n,lv,i:longint;
f,g:text;
v:array[1..1000] of longint;

procedure iofile;
var i,p,aux:longint;
begin
assign(f,'dame.in');
reset(f);
assign(g,'dame.out');
rewrite(g);
if n=0 then writeln(g,'0');
close(f);
if (n=1)or(n=2) then
begin
writeln(g,'1');
writeln(g,'1 1');
close(g);
halt;
end else
if n=3 then
begin
writeln('2');
writeln(g,'1 1');
writeln(g,'3 2');
close(g);
halt;
end;
for i:=1 to n div 2 do
begin
inc(lv);
v[lv]:=i*2;
end;
if n mod 12 in [3,9] then
begin
for i:=1 to lv-1 do
v[i]:=v[i+1];
v[lv]:=2;
end;
for i:=1 to n div 2 do
begin
inc(lv);
v[lv]:=i*2-1;
end;
if n mod 2=1 then
begin
inc(lv);
v[lv]:=n;
end;
if n mod 12=8 then
begin
i:=n div 2+1;
while i+1<=n do
begin
aux:=v[i];
v[i]:=v[i+1];
v[i+1]:=aux;
inc(i,2);
end;
end else
if n mod 12=2 then
begin
aux:=v[n div 2+1];
v[n div  2+1]:=v[n div 2+2];
v[n div 2+2]:=aux;
p:=n div 3+3;
for i:=p to n-1 do
v[i]:=v[i+1];
v[n]:=5;
end else
if n mod 12 in [3,9] then
begin
for i:=n div 2+1 to n-2 do
v[i]:=v[i+2];
v[n-1]:=1;
v[n]:=3;
end;

end;

begin
iofile;
for i:=1 to n do
writeln(g,i,' ',v[i]);
close(g);
end.
``````