CF1662N.Drone Photo

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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\times 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 ai,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 ( 2n15002\le n \le 1500 ).

The next nn lines describe the ages of the contestants. Specifically, the ii -th line contains the integers ai,1,ai,2,,ai,na_{i,1},a_{i,2},\ldots,a_{i,n} ( 1ai,jn21\le a_{i,j}\le n^2 ).

It is guaranteed that ai,jak,la_{i,j}\neq a_{k,l} if iki\neq k or jlj\neq l .

输出格式

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

输入输出样例

  • 输入#1

    2
    1 3
    4 2

    输出#1

    0
  • 输入#2

    2
    3 2
    4 1

    输出#2

    1
  • 输入#3

    3
    9 2 4
    1 5 3
    7 8 6

    输出#3

    6

说明/提示

In the first sample, there are 44 contestants, arranged as follows.

There is only one way to choose four contestants, with one pole held by contestants aged 11 and 22 and the other one by contestants aged 33 and 44 . But then, as we can see in the picture, the poles cross.

Since there is no valid way to choose four contestants, the answer is 00 .

In the second sample, the 44 contestants are arranged as follows.

Once again, there is only one way to choose four contestants, but this time the poles don't cross.

Therefore, the answer is 11 .

In the third sample, the 99 contestants are arranged as follows.

There are 66 ways of choosing four contestants so that the poles don't cross, as shown in the following pictures.

首页