#5012. Problem 2. Cowmpetency
Problem 2. Cowmpetency
Problem 2. Cowmpetency
USACO 2024 January Contest, Gold
Farmer John is hiring a new herd leader for his cows. To that end, he has interviewed () cows for the position. After each interview, he assigned an integer "cowmpetency" score to the candidate ranging from to () that is correlated with their leadership abilities.
Because he has interviewed so many cows, Farmer John has forgotten all of their cowmpetency scores. However, he does remembers () pairs of numbers where cow was the first cow with a
strictly greater
cowmpetency score than cows through (so ).
Farmer John now tells you the pairs of . Help him count how many sequences of cowmpetency scores are consistent with this information! It is guaranteed that there is at least one such sequence. Because this number may be very large, output its value modulo .
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains , , and .
The next lines each contain a pair . It is guaranteed that all are distinct.
OUTPUT FORMAT (print output to the terminal / stdout):
The number of sequences of cowmpetency scores consistent with what Farmer John remembers, modulo .
SAMPLE INPUT:
6 2 3 2 3 4 5
SAMPLE OUTPUT:
6
The following six sequences are the only ones consistent with what Farmer John remembers:
1 1 2 1 3 1 1 1 2 1 3 2 1 1 2 1 3 3 1 1 2 2 3 1 1 1 2 2 3 2 1 1 2 2 3 3
SAMPLE INPUT:
10 1 20 1 3
SAMPLE OUTPUT:
399988086
Make sure to output the answer modulo .
SCORING: Inputs 3-4 satisfy and .Inputs 5-7 satisfy .Inputs 8-10 satisfy and .Inputs 11-15 satisfy .Inputs 16-20 satisfy no additional constraints.
Problem credits: Suhas Nagar