Satyam and Counting

Satyam and Counting

Problem

Satyam is given n distinct points on the 2D coordinate plane. It is guaranteed that 0 ≤ y i ≤ 1 0≤y_i≤1 0yi1 for all given points ( x i , y i ) (x_i,y_i) (xi,yi). How many different nondegenerate right triangles∗ can be formed from choosing three different points as its vertices?

Two triangles a and b are different if there is a point v such that v is a vertex of a but not a vertex of b.

A nondegenerate right triangle has positive area and an interior 90∘ angle.

Input

The first line contains an integer t t t ( 1 ≤ t ≤ 1 0 4 ) (1≤t≤10^4) (1t104) — the number of test cases.

The first line of each test case contains an integer n n n ( 3 ≤ n ≤ 2 ⋅ 1 0 5 ) (3≤n≤2⋅10^5) (3n2105) — the number of points.

The following n lines contain two integers x i x_i xi and y i y_i yi ( 0 ≤ x i ≤ n , 0 ≤ y i ≤ 1 ) (0≤x_i≤n, 0≤y_i≤1) (0xin,0yi1) — the i’th point that Satyam can choose from. It is guaranteed that all ( x i , y i ) (x_i,y_i) (xi,yi) are pairwise distinct.

It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 1 0 5 2⋅10^5 2105.

Output

Output an integer for each test case, the number of distinct nondegenerate right triangles that can be formed from choosing three points.

Example

Input
3
5
1 0
1 1
3 0
5 0
2 1
3
0 0
1 0
3 0
9
1 0
2 0
3 0
4 0
5 0
2 1
7 1
8 1
9 1
Output
4
0
8

Note

The four triangles in question for the first test case:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Code

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll N=2e5+10;
bool v[N][2];//0<=x<=n,0<=y<=1

int main()
{
    ll t;
    cin>>t;
    
    while(t--)
    {
        ll n;
        cin>>n;
        for(ll i=0;i<=n;i++)
            v[i][0]=v[i][1]=0;
        
        for(ll i=1;i<=n;i++)
        {
            ll x,y;
            cin>>x>>y;
            v[x][y]=1;
        }

        ll ans=0;
        for(ll i=0;i<=n;i++)
        {
            if(v[i][0]&&v[i][1]) ans+=(n-2);//x=i(2个点)
            if(v[i][0]&&v[i-1][1]&&v[i+1][1]) ans++;//y=1(2个点),y=0(1个点)
            if(v[i][1]&&v[i-1][0]&&v[i+1][0]) ans++;//y=0(2个点),y=1(1个点)
        }
        
        cout<<ans<<endl;
    }
    
    return 0;
}
  • 27
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值