AtCoder Beginner Contest 168
F
. (Single Dot)
AtCoder
⌀ 2478
原题
← E→
翻译中…

Problem Statement

翻译中…

There is a grass field that stretches infinitely.

翻译中…

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

翻译中…

There are also $N$ north-south lines and $M$ east-west lines drawn on the field. The $i$-th north-south line is the segment connecting the points $(A_i, C_i)$ and $(B_i, C_i)$, and the $j$-th east-west line is the segment connecting the points $(D_j, E_j)$ and $(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 $-10^9$ and $10^9$ (inclusive).
  • $1 \leq N, M \leq 1000$
  • $A_i < B_i\ (1 \leq i \leq N)$
  • $E_j < F_j\ (1 \leq j \leq M)$
  • The point $(0, 0)$ does not lie on any of the given segments.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N M
A_1 B_1 C_1
:
A_N B_N C_N
D_1 E_1 F_1
:
D_M E_M F_M

翻译中…

Output

翻译中…

If the area of the region the cow can reach is infinite, print INF; otherwise, print an integer representing the area in $\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.)

翻译中…

样例

Input #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
Output #1
13
The area of the region the cow can reach is $13\ \mathrm{cm^2}$. ![Sample 1](https://img.atcoder.jp/abc168/education.png)
Input #2
6 1
-3 -1 -2
-3 -1 1
-2 -1 2
1 4 -2
1 4 -1
1 4 1
3 1 4
Output #2
INF
The area of the region the cow can reach is infinite.
题目信息
题号
abc168_f
时间限制
3 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。