Задача Pascal. СРОЧНО!
СРОЧНО! Помогите решить задачу на Pascal, третий день голову ломаю.
Вот условие задачи
Вот мое решение, но оно вылетает на 14 тесте, помогите, пожалуйста, ЗАРАНее спасибо!
var m:array[1..21,1..21]of integer;
k1,k2,k3,k4,k,n,i,j,k5:integer;
f:boolean;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
begin
for j:=1 to 2 do
read(m[i,j]);
readln;
end;
k1:=0;
k2:=0;
k3:=0;
k4:=0;
for i:=1 to n do
begin
f:=true;
if (m[i,1]>0) and (m[i,2]>0) and (m[i,1]=m[i,2]) then begin f:=false; k2:=k2+1;end;
if (m[i,1]<0) and (m[i,2]>0) and (abs(m[i,1])=abs(m[i,2]))then begin f:=false; k1:=k1+1;end;
if (m[i,1]<0) and (m[i,2]<0) and (abs(m[i,1])=abs(m[i,2]))then begin f:=false; k3:=k3+1;end;
if (m[i,1]>0) and (m[i,2]<0) and (abs(m[i,1])=abs(m[i,2]))then begin f:=false; k4:=k4+1;end;
if (f=true) and (m[i,1]<>0) and (m[i,2]<>0) then k:=k+1;
end;
if k1>1 then k1:=1;
if k2>1 then k2:=1;
if k3>1 then k3:=1;
if k4>1 then k4:=1;
k:=k+k1+k2+k3+k4;
k1:=0;
k2:=0;
k3:=0;
k4:=0;
f:=true;
for i:=1 to n do
begin
if (m[i,1]=0) and (m[i,2]>0) then k1:=k1+1;
if (m[i,1]=0) and (m[i,2]<0) then k2:=k2+1;
if (m[i,1]<0) and (m[i,2]=0) then k3:=k3+1;
if (m[i,1]>0) and (m[i,2]=0) then k4:=k4+1;
end;
if k1>1 then k1:=1;
if k2>1 then k2:=1;
if k3>1 then k3:=1;
if k4>1 then k4:=1;
k:=k+k1+k2+k3+k4;
writeln(k);
close(input);
close(output);
end.