[an error occurred while processing this directive]
Listing SOLDATI.PAS 
program Soldati; 
var a:array[1..10000,1..2] of Integer; 
xinit:array[1..10000] of Integer; 
f:Text; 
n,i,j,p,u,xf,yf:Integer; 
sx,sy:Longint; 
procedure sort(poz:Integer); 
var i,b:Integer; 
procedure combin(i,n:Integer); 
var j,b,x,y:Integer; 
begin 
j:=i+i; 
x:=a[i,1]; 
y:=a[i,2]; 
b:=a[i,poz]; 
while j<=n do 
begin 
if (j<n) and (a[j,poz]<a[j+1,poz]) 
then Inc(j); 
if b>=a[j,poz] 
then Break 
else 
begin 
a[j div 2,1]:=a[j,1]; 
a[j div 2,2]:=a[j,2]; 
j:=j+j 
end 
end; 
a[j div 2,1]:=x; 
a[j div 2,2]:=y 
end; 
begin 
{ creez heap-ul } 
for i:=n div 2 downto 1 do combin(i,n); 
{ retrogradez radacina pe } 
{ ultima pozitie curenta i } 
for i:=n downto 2 do 
begin 
b:=a[1,1]; a[1,1]:=a[i,1]; 
a[i,1]:=b; b:=a[1,2]; 
a[1,2]:=a[i,2]; a[i,2]:=b; 
combin(1,i-1) 
end 
end; 
Begin 
Assign(f,'soldiers.in'); Reset(f); 
Readln(f,n); 
for i:=1 to n do Readln(f,a[i,1],a[i,2]); 
Close(f); 
sort(2); { Sortare dupa y } 
sy:=0; p:=1; u:=n; 
while p<u do 
begin 
Inc(sy,a[u,2]-a[p,2]); 
Inc(p); 
Dec(u) 
end; 
Writeln('sy=',sy:4); 
sort(1); { Sortare dupa x } 
for i:=1 to n do 
begin 
xinit[i]:=a[i,1]; 
a[i,1]:=a[i,1]-i 
end; 
sort(1); { Sortare dupa x } 
xf:=a[(n+1) div 2,1]; 
sx:=0; 
for i:=1 to n do 
Inc(sx,abs(xinit[i]-(xf+i))); 
Writeln('sx=',sx:10); 
Writeln('rezultat=',sx+sy:10); 
Assign(f,'soldiers.out'); Rewrite(f); 
Writeln(f,sx+sy); 
Close(f) 
End.