cswork / OA打开练习工作台

MetaOA #6

Count Colliding Object Pairs

估计简单可在线判题

考点(AI 标注)原地数组位运算

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.

输入格式

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

输出格式

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

样例 1

输入:

4
0 0
1 1
2 0
0 2

输出:

3

样例 2

输入:

3
0 0
0 0
0 0

输出:

3

样例 3

输入:

2
0 0
2 0

输出:

0

样例说明

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.