#abc348f. F - Oddly Similar

F - Oddly Similar

Score: 550550 points

问题陈述

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 的两个序列 XXYY 满足满足条件的索引 i(1iM)i (1 \leq i \leq M),使得 Xi=YiX_i = Y_i 的数量为奇数,则称这两个序列是相似的。

找出满足 1i<jN1 \leq i < j \leq NAiA_iAjA_j 相似的整数对 (i,j)(i,j) 的数量。

以上为大语言模型 kimi 翻译,仅供参考。

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 1

3 3
1 2 3
1 3 4
2 3 4

Sample Output 1

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 2

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 2

5