atcoder#ABC131F. [ABC131F] Must Be Rectangular!
[ABC131F] Must Be Rectangular!
Score : points
Problem Statement
There are dots in a two-dimensional plane. The coordinates of the -th dot are .
We will repeat the following operation as long as possible:
- Choose four integers , , , such that there are dots at exactly three of the positions , , and , and add a dot at the remaining position.
We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation.
Constraints
- If , or .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum number of times we can do the operation.
3
1 1
5 1
5 5
1
By choosing , , , , we can add a dot at . We cannot do the operation any more, so the maximum number of operations is .
2
10 10
20 20
0
There are only two dots, so we cannot do the operation at all.
9
1 1
2 1
3 1
4 1
5 1
1 2
1 3
1 4
1 5
16
We can do the operation for all choices of the form , , , , and no more. Thus, the maximum number of operations is .