The Morning Star晨星

time limit per test

2 seconds

memory limit per test

256 megabytes

A compass points directly toward the morning star. It can only point in one of eight directions: the four cardinal directions (N, S, E, W) or some combination (NW, NE, SW, SE). Otherwise, it will break.

The directions the compass can point.

There are nn distinct points with integer coordinates on a plane. How many ways can you put a compass at one point and the morning star at another so that the compass does not break?

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) --- the number of points.

Then nn lines follow, each line containing two integers xixi, yiyi (−109≤xi,yi≤109−109≤xi,yi≤109) --- the coordinates of each point, all points have distinct coordinates.

It is guaranteed that the sum of nn over all test cases doesn't exceed 2⋅1052⋅105.

Output

For each test case, output a single integer --- the number of pairs of points that don't break the compass.

Example

Input

Copy

复制代码

5

3

0 0

-1 -1

1 1

4

4 5

5 7

6 9

10 13

3

-1000000000 1000000000

0 0

1000000000 -1000000000

5

0 0

2 2

-1 5

-1 10

2 11

3

0 0

-1 2

1 -2

Output

Copy

复制代码
6
2
6
8
0

Note

In the first test case, any pair of points won't break the compass:

  • The compass is at (0,0)(0,0), the morning star is at (−1,−1)(−1,−1): the compass will point SWSW.
  • The compass is at (0,0)(0,0), the morning star is at (1,1)(1,1): the compass will point NENE.
  • The compass is at (−1,−1)(−1,−1), the morning star is at (0,0)(0,0): the compass will point NENE.
  • The compass is at (−1,−1)(−1,−1), the morning star is at (1,1)(1,1): the compass will point NENE.
  • The compass is at (1,1)(1,1), the morning star is at (0,0)(0,0): the compass will point SWSW.
  • The compass is at (1,1)(1,1), the morning star is at (−1,−1)(−1,−1): the compass will point SWSW.

In the second test case, only two pairs of points won't break the compass:

  • The compass is at (6,9)(6,9), the morning star is at (10,13)(10,13): the compass will point NENE.
  • The compass is at (10,13)(10,13), the morning star is at (6,9)(6,9): the compass will point SWSW.

每个测试的时间限制 2 秒

每个测试的内存限制 256 兆字节

指南针直接指向晨星。它只能指向八个方向之一:四个基本方向(N、S、E、W)或某种组合(NW、NE、SW、SE)。否则,它会损坏。

指南针可以指向的方向。

平面上有 n

个具有整数坐标的不同点。有多少种方法可以将指南针放在一个点,将晨星放在另一个点,这样指南针就不会损坏?

输入

每个测试包含多个测试用例。第一行包含测试用例数 t

(1≤t≤104

)。测试用例的描述如下。

每个测试用例的第一行包含一个整数 n

(2≤n≤2⋅105

)--- 点数。

接下来是 n

行,每行包含两个整数 xi

, yi

(−109≤xi,yi≤109

) --- 每个点的坐标,所有点都有不同的坐标。

保证所有测试用例的 n

之和不超过 2⋅105

输出

对于每个测试用例,输出一个整数 --- 不偏离指南针的点对的数量。

示例

输入副本

5

3

0 0

-1 -1

1 1

4

4 5

5 7

6 9

10 13

3

-1000000000 1000000000

0 0

1000000000 -1000000000

5

0 0

2 2

-1 5

-1 10

2 11

3

0 0

-1 2

1 -2

输出副本

6

2

6

8

0

注意

在第一个测试用例中,任何一对点都不会破坏指南针:

指南针位于 (0,0)

,晨星位于 (-1,-1)

:指南针将指向 SW

指南针位于 (0,0)

,晨星位于 (1,1)

:指南针将指向 NE

罗盘位于 (−1,−1)

,晨星位于 (0,0)

:罗盘将指向东北

罗盘位于 (−1,−1)

,晨星位于 (1,1)

:罗盘将指向东北

罗盘位于 (1,1)

,晨星位于 (0,0)

:罗盘将指向西南

罗盘位于 (1,1)

,晨星位于 (−1,−1)

:罗盘将指向西南

在第二个测试案例中,只有两对点不会破坏罗盘:

罗盘位于 (6,9)

,晨星位于 (10,13)

:罗盘将指向东北

罗盘位于 (10,13)

,晨星位于 (6,9)

:罗盘将指向西南

代码:

cpp 复制代码
#include <iostream>
#include <vector>
#include <map>
using namespace std;

#define ll long long

ll A2(ll m) {
    return m * (m - 1);
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<pair<ll, ll>> points(n);
        map<ll, ll> x_count, y_count, x_add_y_count, x_sub_y_count;

        for (int i = 0; i < n; i++) {
            cin >> points[i].first >> points[i].second;
            x_count[points[i].first]++;
            y_count[points[i].second]++;
            x_add_y_count[points[i].first + points[i].second]++;
            x_sub_y_count[points[i].first - points[i].second]++;
        }

        ll ans = 0;

        for (auto& kv : x_count) {
            ans += A2(kv.second);
        }
        for (auto& kv : y_count) {
            ans += A2(kv.second);
        }
        for (auto& kv : x_add_y_count) {
            ans += A2(kv.second);
        }
        for (auto& kv : x_sub_y_count) {
            ans += A2(kv.second);
        }

        cout << ans << endl;
    }
    return 0;
}
相关推荐
姜不吃葱5 分钟前
【力扣热题100】哈希——两数之和
算法·leetcode·哈希算法·力扣热题100
AI4Sci.14 分钟前
在云服务器上基于lora微调Qwen2.5-VL-7b-Instruct模型(下)
人工智能·算法·机器学习·大模型·lora微调·大模型本地部署·qwen2.5-vl-7b
一只小风华~16 分钟前
JavaScript:数组常用操作方法的总结表格
前端·javascript·数据结构·vue.js·算法
mit6.82427 分钟前
[蓝牙通信] 临界区管理 | volatile | 同步(互斥锁与信号量) | handle
c++·物联网
TiAmo zhang40 分钟前
深度学习与图像处理 | 基于PaddlePaddle的梯度下降算法实现(线性回归投资预测)
图像处理·深度学习·算法
一匹电信狗1 小时前
【C++】手搓一个STL风格的vector容器
c语言·数据结构·c++·算法·leetcode·stl·visual studio
生信探索1 小时前
SeuratExtend 可视化教程(1):单细胞分析的高颜值绘图指南
算法
小小小白的编程日记1 小时前
C语言中的数据结构--栈和队列(2)
c语言·数据结构
李永奉1 小时前
C语言-数组:数组(定义、初始化、元素的访问、遍历)内存和内存地址、数组的查找算法和排序算法;
c语言·算法·排序算法
星辰大海的精灵1 小时前
深入解析 CopyOnWriteArrayList
java·后端·算法