atcoder#ABC168F. [ABC168F] . (Single Dot)

[ABC168F] . (Single Dot)

Score: 600600 points

Problem Statement

There is a grass field that stretches infinitely.

In this field, there is a negligibly small cow. Let (x,y)(x, y) denote the point that is x cmx\ \mathrm{cm} south and y cmy\ \mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0,0)(0, 0).

There are also NN north-south lines and MM east-west lines drawn on the field. The ii-th north-south line is the segment connecting the points (Ai,Ci)(A_i, C_i) and (Bi,Ci)(B_i, C_i), and the jj-th east-west line is the segment connecting the points (Dj,Ej)(D_j, E_j) and (Dj,Fj)(D_j, F_j).

What is the area of the region the cow can reach when it can move around as long as it does not cross the segments (including the endpoints)? If this area is infinite, print INF instead.

Constraints

  • All values in input are integers between 109-10^9 and 10910^9 (inclusive).
  • 1N,M10001 \leq N, M \leq 1000
  • Ai<Bi (1iN)A_i < B_i\ (1 \leq i \leq N)
  • Ej<Fj (1jM)E_j < F_j\ (1 \leq j \leq M)
  • The point (0,0)(0, 0) does not lie on any of the given segments.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1 C1C_1

::

ANA_N BNB_N CNC_N

D1D_1 E1E_1 F1F_1

::

DMD_M EME_M FMF_M

Output

If the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in cm2\mathrm{cm^2}.

(Under the constraints, it can be proved that the area of the region is always an integer if it is not infinite.)

5 6
1 2 0
0 1 1
0 2 2
-3 4 -1
-2 6 3
1 0 1
0 1 2
2 0 2
-1 -4 5
3 -2 4
1 2 4
13

The area of the region the cow can reach is 13 cm213\ \mathrm{cm^2}.

Sample 1

6 1
-3 -1 -2
-3 -1 1
-2 -1 2
1 4 -2
1 4 -1
1 4 1
3 1 4
INF

The area of the region the cow can reach is infinite.