#abc361g. G - Go Territory
G - Go Territory
Score : points
问题陈述
在二维平面上有 块石头。第 块石头位于坐标 。所有石头都位于第一象限的格点上(包括坐标轴)。
计算格点 的数量,这些格点上没有放置石头,并且从 到 不可能 通过反复向上、向下、向左或向右移动 个单位而不经过放置石头的坐标。
更精确地说,计算格点 的数量,这些格点上没有放置石头,并且不存在一个有限的整数对序列 满足以下所有四个条件:
- 。
- 。
- 对于所有 ,有 。
- 对于所有 ,在 处没有石头。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There are stones placed on a -dimensional plane. The -th stone is located at coordinates . All stones are located at lattice points in the first quadrant (including the axes).
Count the number of lattice points where no stone is placed and it is impossible to reach from by repeatedly moving up, down, left, or right by without passing through coordinates where a stone is placed.
More precisely, count the number of lattice points where no stone is placed, and there does not exist a finite sequence of integer pairs that satisfies all of the following four conditions:
- .
- .
- for all .
- There is no stone at for all .
Constraints
- The pairs are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the number of lattice points that satisfy the conditions.
Sample Input 1
5
1 0
0 1
2 3
1 2
2 1
Sample Output 1
1
It is impossible to reach from .
Sample Input 2
0
Sample Output 2
0
There may be cases where no stones are placed.
Sample Input 3
22
0 1
0 2
0 3
1 0
1 4
2 0
2 2
2 4
3 0
3 1
3 2
3 4
5 1
5 2
5 3
6 0
6 4
7 0
7 4
8 1
8 2
8 3
Sample Output 3
6
There are six such points: .