USACO Bronze division
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.
The first line contains two positive integers k (1 ≤ k ≤ 10) and n (1 ≤ n ≤ 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.
Print the number of consistent pairs.
The consistent pairs of cows are (1, 4), (2, 4), (3, 4) and (1, 3).
3 4 4 1 2 3 4 1 3 2 4 2 1 3