F - Oddly Similar Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 550550

問題文

NN 個の長さ MM の数列 A1,A2,,ANA_1, A_2, \ldots, A_N があります。ii 番目の数列は MM 個の整数 Ai,1,Ai,2,,Ai,MA_{i,1}, A_{i,2}, \ldots, A_{i,M} で表されます。

それぞれの長さが MM の数列 X,YX,Y について、Xi=YiX_i = Y_i となるような i(1iM)i(1 \leq i \leq M) の個数が奇数であるときに、XXYY は似ていると言います。

1i<jN1 \leq i < j \leq N を満たす整数の組 (i,j)(i,j) のうち、AiA_iAjA_j が似ているものの個数を求めてください。

制約

  • 1N20001 \leq N \leq 2000
  • 1M20001 \leq M \leq 2000
  • 1Ai,j9991 \leq A_{i,j} \leq 999
  • 入力は全て整数である。

入力

入力は以下の形式で標準入力から与えられる。

NN MM
A1,1A_{1,1} A1,2A_{1,2} \ldots A1,MA_{1,M}
A2,1A_{2,1} A2,2A_{2,2} \ldots A2,MA_{2,M}
\vdots
AN,1A_{N,1} AN,2A_{N,2} \ldots AN,MA_{N,M}

出力

答えを整数として出力せよ。


入力例 1Copy

Copy
3 3
1 2 3
1 3 4
2 3 4

出力例 1Copy

Copy
1

(i,j)=(1,2)(i,j) = (1,2) は条件を満たします。なぜならば、A1,k=A2,kA_{1,k} = A_{2,k} となるような kkk=1k=111 個だけだからです。

(i,j)=(1,3),(2,3)(i,j) = (1,3) ,(2,3) は条件を満たさないため、条件を満たす (i,j)(i,j) の組は (1,2)(1,2) だけです。


入力例 2Copy

Copy
6 5
8 27 27 10 24
27 8 2 4 5
15 27 26 17 24
27 27 27 27 27
27 7 22 11 27
19 27 27 27 27

出力例 2Copy

Copy
5

Score: 550550 points

Problem Statement

There are NN sequences of length MM, denoted as A1,A2,,ANA_1, A_2, \ldots, A_N. The ii-th sequence is represented by MM integers Ai,1,Ai,2,,Ai,MA_{i,1}, A_{i,2}, \ldots, A_{i,M}.

Two sequences XX and YY of length MM are said to be similar if and only if the number of indices i(1iM)i (1 \leq i \leq M) such that Xi=YiX_i = Y_i is odd.

Find the number of pairs of integers (i,j)(i,j) satisfying 1i<jN1 \leq i < j \leq N such that AiA_i and AjA_j are similar.

Constraints

  • 1N20001 \leq N \leq 2000
  • 1M20001 \leq M \leq 2000
  • 1Ai,j9991 \leq A_{i,j} \leq 999
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM
A1,1A_{1,1} A1,2A_{1,2} \ldots A1,MA_{1,M}
A2,1A_{2,1} A2,2A_{2,2} \ldots A2,MA_{2,M}
\vdots
AN,1A_{N,1} AN,2A_{N,2} \ldots AN,MA_{N,M}

Output

Print the answer as an integer.


Sample Input 1Copy

Copy
3 3
1 2 3
1 3 4
2 3 4

Sample Output 1Copy

Copy
1

The pair (i,j)=(1,2)(i,j) = (1,2) satisfies the condition because there is only one index kk such that A1,k=A2,kA_{1,k} = A_{2,k}, which is k=1k=1.

The pairs (i,j)=(1,3),(2,3)(i,j) = (1,3), (2,3) do not satisfy the condition, making (1,2)(1,2) the only pair that does.


Sample Input 2Copy

Copy
6 5
8 27 27 10 24
27 8 2 4 5
15 27 26 17 24
27 27 27 27 27
27 7 22 11 27
19 27 27 27 27

Sample Output 2Copy

Copy
5


2025-04-21 (Mon)
14:19:36 +00:00