{
TASK:area
LANG:Pascal
}
program area;

type CType = Double;

type TPoint = record
       X, Y: CType;
     end;

type PPoints = ^TPoints;
     TPoints = record
       X, Y: CType;
       Touchable: Boolean;
       Next: PPoints;
     end;


var Points: PPoints;
    T: TPoint;

function Point(const X, Y: CType): TPoint; //Perfect
begin
 Point.X := X;
 Point.Y := Y;
end;

procedure AddPoint_Infront(var aPoints: PPoints; const aX, aY: CType); //Perfect
var Temp: PPoints;
begin
 New(Temp);
 Temp^.X := aX;
 Temp^.Y := aY;
 Temp^.Touchable := True;
 Temp^.Next := aPoints;
 aPoints := Temp;
end;

procedure AddPoint_After(var aPoints: PPoints; const aX, aY: CType); //Perfect
var Temp: PPoints;
begin
 New(Temp);
 Temp^.X := aX;
 Temp^.Y := aY;
 Temp^.Touchable := False;
 Temp^.Next := aPoints^.Next;
 aPoints^.Next := Temp;
end;

procedure RemovePoint(var aPoints: PPoints); //Perfect
var Temp: PPoints;
begin
 If (aPoints^.Next = nil) then begin

  Dispose(aPoints);
  aPoints := nil;

 end else begin

  Temp := aPoints^.Next;
  aPoints^ := Temp^;
  Dispose(Temp);

 end;
end;

procedure FlushPoints(var aPoints: PPoints); //Perfect
var Temp: PPoints;
begin
 while not(aPoints = nil) do begin
  Temp := aPoints^.Next;
  Dispose(aPoints);
  aPoints := Temp;
 end;
end;

function S_abc(const aPoint, bPoint, cPoint: TPoint): CType; //Perfect
var x1, y1, x2, y2, x3, y3: Double;
begin
 x1 := aPoint.X; y1 := aPoint.Y;
 x2 := bPoint.X; y2 := bPoint.Y;
 x3 := cPoint.X; y3 := cPoint.Y;
 S_abc := 0.5 * ((x2 - x1) * (y1 + y2) + (x3 - x2) * (y2 + y3) + (x1 - x3) * (y1 + y3));
end;

function GetCollision(const L_1, L_2, P_1, P_2: TPoint): TPoint; //OK
var S1, S2, h1, h2, L1L2, dist, ratio: CType;
begin
 S1 := S_abc(L_1,P_1,L_2);
 S2 := S_abc(L_1,P_2,L_2);

 If (S1 * S2 > 0) then begin

  GetCollision.X := - 1;
  GetCollision.Y := - 1;

 end else begin

  L1L2 := Sqrt(Sqr(L_2.X - L_1.X) + Sqr(L_2.Y - L_1.Y));
  h1 := abs((2 * S1) / L1L2);
  h2 := abs((2 * S2) / L1L2);
  ratio := h1 / (h1 + h2);
  GetCollision.X := P_1.X + (P_2.X - P_1.X) * ratio;
  GetCollision.Y := P_1.Y + (P_2.Y - P_1.Y) * ratio;

 end;
end;

function CheckPoint(var aPoints: PPoints; x1, y1, x2, y2: CType): Boolean; //Perfect
var S1, S2: CType;
begin
 S1 := S_abc(Point(x1,y1),Point(aPoints^.X,aPoints^.Y),Point(x2,y2));
 S2 := S_abc(Point(x1,y1),T,Point(x2,y2));

 If (S1 * S2 < 0) and (aPoints^.Touchable) then CheckPoint := True
 else CheckPoint := False;
 aPoints^.Touchable := True;
end;

procedure ProcessLine(var aPoints: PPoints; const x1, y1, x2, y2: CType); //Perfect
var p_x1, p_x2, p_y1, p_y2: CType;
    iPoint, Temp: PPoints;
    cPoint: TPoint;
begin
 iPoint := aPoints;
 while not(iPoint^.Next = nil) do begin

  p_x1 := iPoint^.X;
  p_y1 := iPoint^.Y;
  p_x2 := iPoint^.Next^.X;
  p_y2 := iPoint^.Next^.Y;
  cPoint := GetCollision(Point(x1, y1), Point(x2, y2), Point(p_x1,p_y1), Point(p_x2,p_y2));
  If not((cPoint.X = - 1) and (cPoint.Y = - 1)) then begin
    AddPoint_After(iPoint, cPoint.X, cPoint.Y);
    iPoint := iPoint^.Next;
  end;

  iPoint := iPoint^.Next;

 end;

 p_x1 := iPoint^.X;
 p_y1 := iPoint^.Y;
 p_x2 := aPoints^.X;
 p_y2 := aPoints^.Y;
 cPoint := GetCollision(Point(x1, y1), Point(x2, y2), Point(p_x1,p_y1), Point(p_x2,p_y2));
 If not((cPoint.X = - 1) and (cPoint.Y = - 1)) then
   AddPoint_After(iPoint, cPoint.X, cPoint.Y);

 //Remove Unneeded Points;
 iPoint := aPoints;
 while not(iPoint = nil) do begin

  If (CheckPoint(iPoint, x1, y1, x2, y2)) then RemovePoint(iPoint)
  else iPoint := iPoint^.Next;

 end;
end;


procedure Input; //Perfect
var xb, yb, xe, ye: Double;
    iPoint, N: Integer;
begin
 ReadLn(xb, yb, xe, ye);
 AddPoint_Infront(Points, xe, yb);
 AddPoint_Infront(Points, xe, ye);
 AddPoint_Infront(Points, xb, ye);
 AddPoint_Infront(Points, xb, yb);

 with T do ReadLn(X,Y);

 ReadLn(N);
 for iPoint := 1 to N do begin

  ReadLn(xb, yb, xe, ye);
  ProcessLine(Points, xb, yb, xe, ye);

 end;
end;

procedure Output; //Perfect
var Answer, S, x1, x2, y1, y2: CType;
    iPoint: PPoints;
begin
 Answer := 0;

 iPoint := Points;
 while not(iPoint^.Next = nil) do begin

  x1 := iPoint^.X;
  y1 := iPoint^.Y;
  x2 := iPoint^.Next^.X;
  y2 := iPoint^.Next^.Y;
  S := S_abc(T,Point(x1,y1),Point(x2,y2));
  Answer := Answer + S;

  iPoint := iPoint^.Next;

 end;

 x1 := iPoint^.X;
 y1 := iPoint^.Y;
 x2 := Points^.X;
 y2 := Points^.Y;
 S := S_abc(T,Point(x1,y1),Point(x2,y2));
 Answer := Answer + S;

 WriteLn(Trunc(Answer));
end;

begin
 Points := nil;

 Input;
 Output;

 FlushPoints(Points);
end.
