An orchard has n distinct trees at integer coordinates. A square plot is an axis-aligned square (its sides parallel to the axes) with a strictly positive side length whose four corners are all trees in the orchard. Count how many distinct square plots exist. Two plots are the same only if they use the exact same four corner trees.
Line 1: an integer n, the number of trees.
Next n lines: two integers x y, the position of a tree. All positions are distinct.
A single integer: the number of axis-aligned square plots.
Example 1
Input
4 0 0 1 0 0 1 1 1
Expected
1
Explanation
The four trees are exactly the corners of one unit square, so the count is 1.
Example 2
Input
5 0 0 2 0 0 2 2 2 1 1
Expected
1
Explanation
The four outer trees form one 2 by 2 square; the center tree completes no additional square, so the count is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →