ce e gresit in implementarea asta? la mine in teste merge perfect in borland pascal, dar in free pascal nu afiseaza (acelasi cod). vreau si eu cateva lamuriri...

Cod:
program par;
var s:array[1..3000] of char;
f1,f2:text;
n,x,y,i,j:integer;
sol:real;
BEGIN
assign (f1,'par.in');
assign (f2,'par.out');
reset(f1); rewrite(f2);
readln (f1,n);
x:=0;y:=0;
if (n mod 2=1) then write (f2,'-1')
else
BEGIN
for i:=1 to n do read (f1,s[i]);
for i:=1 to n do
if s[i]='(' then x:=x+1
else y:=y+1;
for i:=1 to (n-1) do begin
j:=i+1;
while j<>n do
if s[j]=')' then j:=n
else j:=j+1;
if (s[i]='(') and (s[j]=')') then begin
x:=x-1;
y:=y-1;
s[j]:='0';
end;
end;
if (x mod 2 = 0) and (y mod 2 = 0)then sol:=(x/2)+(y/2);
if (x mod 2 = 1) and (y mod 2 = 1)then sol:=(x-1)/2+(y-1)/2;
write (f2,trunc(sol));
end;
close (f1); close(f2);
end.
