Garden
Time limit3sMemory limit128 MB
Count the number of axis-aligned squares whose four corners are all points from a given set.
- Level
Medium4 of 10
- Topics
- Hash map, Geometry, Brute force
- Solved
- No attempts yet
Problem
Byteen wants to plant a garden next to her house. The garden must be an axis-aligned square, that is, a square whose sides are parallel to the North-South and East-West directions. Each of the square's four corners must coincide with one of the apple-trees growing nearby.
Byteen inspects every possible location before choosing, and checking one location takes exactly one second. Determine how many valid garden locations there are: the number of axis-aligned squares whose four corners are all apple-trees.
Input
The first line contains the number of apple-trees (). Each of the next lines contains two space-separated integers and (), the coordinates of the -th apple-tree. No two trees share the same coordinates.
Output
Print a single integer: the number of axis-aligned squares (sides parallel to the coordinate axes) whose four corners are all apple-trees.