Lost in Migration
SQUAWK! You woke up late on the day you're supposed to lead the Great Cockatiel Migration! You scramble out of your nest and see your flock waiting impatiently, but in your groggy state, you can't remember exactly where you're meant to be. Oh, how you wish you had gotten the worm this morning...
To guide the flock properly, you know that your position must be the tip of a north-pointing V-formation, with two flying buddies. Specifically, your position should have integer coordinates, and be at equal distances in front of and to the left/right of two other birds. More formally, you can be at position if there exist two birds at positions
and
, where
,
and
are integers.
Some examples of valid and invalid V-formations are shown below:
You need to greet your flying buddies before setting off. How many unique pairs of birds can meet these criteria?
Input
The first line contains an integer
, the number of birds in your flock.
The next lines contain integers
and
, indicating that there is a bird currently in row
and column
.
Output
Output the number of pairs of birds you can choose, such that the birds are equal distances behind and to your left/right.
Clarifications
- The positions of all birds are distinct.
- Your position can be atop an existing bird.
Example
Input 1
8
6 2
3 3
4 4
6 4
3 5
3 7
6 7
4 8
Output 1
5
There are pairs of birds that can be your flying buddies:
The birds at
and
(you will be at
)
The birds at
and
(you will be at
)
The birds at
and
(you will be at
)
The birds at
and
(you will be at
)
The birds at
and
(you will be at
)
These 4 pairs are highlighted in red below, along with your position, which is highlighted in blue. All other birds are highlighted in grey.
Input 2
7
1 4
2 3
2 5
3 2
3 6
4 1
4 7
Output 2
3
Note that your position can be on top of existing birds.
Input 3
4
1 1
1 3
1 5
1 7
Output 3
6
Note that while your position has to be at integer coordinates, those coordinates don't necessarily need to be positive.
Comments