ABC-303-B-Discord

发布时间 2023-07-18 15:02:49作者: 是胡某某啊

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200 points

Problem Statement

N people numbered 1,2,…,�1,2,,N were in M photos. In each of the photos, they stood in a single line. In the i-th photo, the j-th person from the left is person ��,�ai,j.

Two people who did not stand next to each other in any of the photos may be in a bad mood.

How many pairs of people may be in a bad mood? Here, we do not distinguish a pair of person x and person y, and a pair of person y and person x.

Constraints

  • 2≤�≤502N50
  • 1≤�≤501M50
  • 1≤��,�≤�1ai,jN
  • ��,1,…,��,�ai,1,,ai,N contain each of 1,…,�1,,N exactly once.
  • All values in the input are integers.

Input

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

N M
�1,1a1,1  �1,�a1,N

��,1aM,1  ��,�aM,N

Output

Print the answer.