Problems
For convenience, colors are represented by numbers from
For each point
Here, point
If there are two or more closest points, choose any one of them.
For each point
Specifically, if there is no other point of the same color on the line for point
For example, when points are represented as ordered pairs (coordinate, color), let
The arrow
The arrows
In the case of point
Therefore, the sum of the lengths of all arrows is
Given the coordinates and colors of the points, write a program that outputs the sum of the lengths of the arrows starting from all points, in other words,
Input
The following information is given as standard input.
The first line contains an integer
Each of the next
Output
Print the sum of the lengths of the arrows starting from all points to standard output.
[Constraints]
In all subtasks, the coordinates x and colors y of the points satisfy
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 21 | The colors of the points are all the same, and the number of points satisfies |
| #2 | 12 | There are exactly two colors of points, and the number of points satisfies |
| #3 | 29 | The number of points satisfies |
| #4 | 38 | The number of points satisfies |
Example #1
4
0 1
1 2
3 1
4 1
5
Example #2
4
1 1
0 2
4 3
3 4
0
Example #3
9
10 2
11 3
20 2
22 1
25 1
0 1
4 2
5 2
7 2
45