#P5831. [USACO19DEC] Cow Gymnastics B
[USACO19DEC] Cow Gymnastics B
Problem Description
To improve their health, the cows have started doing gymnastics training. Farmer John chose his favorite cow, Bessie, to coach the other cows, while also evaluating their progress in learning different gymnastics skills.
In each of the training sessions, Bessie ranks the cows based on their performance. Later, she became curious about how consistent these rankings are. A pair of different cows is called consistent if one cow performs better than the other in every training session.
Please help Bessie count the number of consistent cow pairs.
Input Format
The first line contains two positive integers and . The next lines each contain a permutation of the integers , representing the rankings of the cows (the cows are identified by numbers ). If in a line appears before , it means cow performed better than cow .
Output Format
Output one line containing the number of consistent cow pairs.
3 4
4 1 2 3
4 1 3 2
4 2 1 3
4
Hint
The consistent cow pairs are , , , and .
, .
Problem by: Nick Wu.
Translated by ChatGPT 5