아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Drone Photo

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

요약
서로 다른 나이를 담은 n x n 격자가 주어질 때, 두 어린 모퉁이와 두 나이 많은 모퀶이를 짝지었을 때 두 막대가 교차하지 않는 축 정렬 직사각형의 수를 센다.
난이도

보통10점 중 6점

유형
배열, 정렬, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Today, like every year at SWERC, the n2n^2 contestants have gathered outside the venue to take a drone photo. Jennifer, the social media manager for the event, has arranged them into an n× nn × n square. Being very good at her job, she knows that the contestant standing on the intersection of the ii-th row with the jj-th column is a_i,ja\_{i,j} years old. Coincidentally, she notices that no two contestants have the same age, and that everyone is between 11 and n2n^2 years old.

Jennifer is planning to have some contestants hold a banner with the ICPC logo parallel to the ground, so that it is clearly visible in the aerial picture. Here are the steps that she is going to follow in order to take the perfect SWERC drone photo.

  • First of all, Jennifer is going to select four contestants standing on the vertices of an axis-aligned rectangle.
  • Then, she will have the two younger contestants hold one of the poles, while the two older contestants will hold the other pole.
  • Finally, she will unfold the banner, using the poles to support its two ends. Obviously, this can only be done if the two poles are parallel and do not cross, as shown in the pictures below.

Being very indecisive, Jennifer would like to try out all possible arrangements for the banner, but she is worried that this may cause the contestants to be late for the competition. How many different ways are there to choose the four contestants holding the poles in order to take a perfect photo? Two choices are considered different if at least one contestant is included in one but not the other.

입력

The first line contains a single integer nn (2≤n≤15002 ≤ n ≤ 1500). The next nn lines describe the ages of the contestants. Specifically, the ii-th line contains the integers a_i,1a\_{i,1}, a_i,2a\_{i,2}, …\dots, a_i,na\_{i,n} (1≤a_i,j≤n21 ≤ a\_{i,j} ≤ n^2). It is guaranteed that a_i,j≠ a_k,la\_{i,j} \ne a\_{k,l} if i≠ki \ne k or j≠lj \ne l.

출력

Print the number of ways for Jennifer to choose the four contestants holding the poles.

예제3

  1. 예제 1

    입력
    2
    1 3
    4 2
    
    예상 출력
    0
    
  2. 예제 2

    입력
    2
    3 2
    4 1
    
    예상 출력
    1
    
  3. 예제 3

    입력
    3
    9 2 4
    1 5 3
    7 8 6
    
    예상 출력
    6