Good Triangle

시간 제한2초메모리 제한1024 MB

요약
주어진 점들 중 세 점에서 맨해튼 거리가 모두 같은 점이 존재하는 삼중항의 개수를 센다.
난이도

어려움10점 중 8점

유형
해시맵, 수학, 기하
정답자
아직 제출이 없습니다

문제

You are given nn distinct points on the two dimensional plane.

We define the distance between two points P=(x_1,y_1)P=(x\_1, y\_1) and Q=(x_2,y_2)Q=(x\_2, y\_2) as d(P,Q)=∣x_1−x_2∣+∣y_1−y_2∣d(P, Q)=|x\_1-x\_2|+|y\_1-y\_2|.

Let's say that three distinct points U,V,WU, V, W form a good triangle if there exists a point TT such that d(U,T)=d(V,T)=d(W,T)d(U, T)=d(V, T)=d(W, T). Note that TT does not have to be a lattice point.

Find the number of good triangles that can be formed by the given points.

입력

The first line of input contains NN.

The ii-th line of the next NN lines contains two space-separated integers x_i,y_ix\_i, y\_i, meaning that the coordinate of the ii-th point is (x_i,y_i)(x\_i, y\_i).

출력

Print one integer, the number of good triangles that can be formed by the given points.

제한

  • 3≤N≤500,0003 \leq N \leq 500\\,000
  • −109≤x_i,y_i≤109-10^9 \leq x\_i, y\_i \leq 10^9 (1≤i≤N1 \leq i \leq N)
  • (x_i,y_i)≠(x_j,y_j)(x\_i, y\_i) \neq (x\_j, y\_j) if i≠ji\ne j (1≤i,j≤N1 \leq i, j \leq N)
  • All values in the input are integers.

예제2

  1. 예제 1

    입력
    5
    1 -1
    1 5
    5 7
    1 3
    4 2
    
    예상 출력
    9
    
  2. 예제 2

    입력
    10
    -2 -1
    -2 2
    -1 -2
    -1 -1
    -1 1
    0 1
    1 -1
    1 2
    2 -1
    2 1
    
    예상 출력
    108