cswork / OAOpen practice workspace

MetaOA #6

Count Colliding Object Pairs

Estimated EasyJudge-ready

Topics (AI-labelled)In-place ArraysBits & Math

Given the integer center coordinates of n objects. By the criterion stated explicitly in the original problem, two different objects collide if and only if |x₁−x₂|≤1 and |y₁−y₂|≤1. Find the number of unordered colliding pairs; different objects at the same coordinates also form a pair. This distance criterion takes precedence; do not derive it from the side lengths in the figure.

Input

The first line contains n (1..1000), followed by n lines of x y (−10000..10000).

Output

Output the answer as described; separate multiple results with spaces in order, and output an empty line for an empty array.

Example 1

Input:

4
0 0
1 1
2 0
0 2

Output:

3

Example 2

Input:

3
0 0
0 0
0 0

Output:

3

Example 3

Input:

2
0 0
2 0

Output:

0

Example notes

Example 1: (1,1) and each of the other three objects have both coordinate differences at most 1, and no other pair qualifies, so there are 3 pairs in total.

Editorial

Loading solution…