#ABC168F. . (Single Dot)

. (Single Dot)

题目描述

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.

有一块无限延伸的草地。

在这片草地上有一头小得可以忽略不计的牛。让 (x,y)(x, y) 表示奶牛现在所站位置的南面 x cmx\ \mathrm{cm} 和东面 y cmy\ \mathrm{cm} 的一点。牛本身站在 (0,0)(0, 0) 处。

田野上还画有 NN 条南北线和 MM 条东西线。南北线 ii 是连接点 (Ai,Ci)(A_i, C_i)(Bi,Ci)(B_i, C_i) 的线段,东西线 jj 是连接点 (Dj,Ej)(D_j, E_j)(Dj,Fj)(D_j, F_j) 的线段。

只要不穿过这些线段(包括端点),奶牛就可以四处走动,那么奶牛可以到达的区域的面积是多少?如果该区域无限大,请打印 INF

输入格式

输入内容按以下格式标准输入:

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

输出格式

如果奶牛能到达的区域面积为无限大,则打印 "INF";否则,打印一个代表该区域面积的整数,单位为 cm2\mathrm{cm^2}

(在约束条件下,可以证明该区域的面积如果不是无限大,则总是一个整数)。

样例 #1

样例输入 #1

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

样例输出 #1

13

样例 #2

样例输入 #2

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

样例输出 #2

INF

说明

数据规模与约定

  • 所有输入值均为介于 109-10^910910^9 之间的整数(含整数)。
  • 1N,M10001 \leq N, M \leq 1000
  • Ai<Bi (1iN)A_i \lt B_i\ (1 \leq i \leq N)
  • Ej<Fj (1jM)E_j \lt F_j\ (1 \leq j \leq M)
  • (0,0)(0, 0) 不在任何给定的线段上。

样例 11 解释

奶牛能到达的区域面积为 13 cm213\ \mathrm{cm^2}

image.png

样例 22 解释

奶牛能到达的区域面积是无限的。