eolymp
bolt
Try our new interface for solving problems
Problems

Cow Gymnastics

Cow Gymnastics

Time limit 1 second
Memory limit 128 MiB

In order to improve their physical fitness, the cows have taken up gymnastics! Farmer John designates his favourite cow Bessie to coach the n other cows and to assess their progress as they learn various gymnastic skills.

In each of k practice sessions, Bessie ranks the n cows according to their performance. Afterward, she is curious about the consistency in these rankings. A pair of two distinct cows is consistent if one cow did better than the other one in every practice session.

Help Bessie compute the total number of consistent pairs.

Input data

The first line contains two positive integers k\:(1 \le k \le 10) and n\:(1 \le n \le 20). The next k lines will each contain the integers 1 ... n in some order, indicating the rankings of the cows (cows are identified by the numbers 1 ... n). If A appears before B in one of these lines, that means cow A did better than cow B.

Output data

Print the number of consistent pairs.

Examples

The consistent pairs of cows are (1, 4), (2, 4), (3, 4) and (1, 3).

Input example #1
3 4
4 1 2 3
4 1 3 2
4 2 1 3
Output example #1
4
Source 2019 USACO December Bronze