It was told by Scheherazade that far away, in the middle of the desert,
there is a lake. Originally this lake had
As time went by, some fish ate some of the other fish. One fish can eat
another if and only if it is at least twice as long (fish
Scheherazade has said that if you are able to find the lake, you will be allowed to take out one fish and keep all the gems in its stomach for yourself. You are willing to try your luck, but before you head out on the long journey, you want to know how many different combinations of gems you could obtain by catching a single fish.
Task
Write a program that given the length of each fish and the kind of
gemstone originally swallowed by each fish, finds the number of
different combinations of gems that can end up in the stomach of any
fish, modulo some given integer
Constraints
, The original number of fish in the lake. , The number of different gemstone kinds. , The length of fish .
Input Specification
Your program must read from the standard input the following data:
- Line
contains the integer , the original number of fish in the lake. - Line
contains the integer , the number of kinds of gemstones.
The kinds of gemstones are represented by integers
- Line
contains the integer . - Each of the following
lines describes one fish using integers separated by a single space: the length of the fish followed by the kind of gemstone originally swallowed by that fish.
Note: For all test cases used for evaluation, it is guaranteed that
there is at least one gemstone from each of the
Output Specification
Your program must write to the standard output a single line containing
one integer between
Note that for solving the task, the value of
Subtasks
- (
points) will not exceed . - (
points) will not exceed . - (
points) No additional constraints.
Sample Input
5
3
7
2 2
5 1
8 3
4 1
2 3
Sample Output
4
There are
The possible combinations are:
(For each combination, we list the gems it contains. For example,
These combinations can be achieved in the following ways:
: It is possible that you catch the second (or the fourth) fish before it eats any other fish. : If the second fish eats the first fish, then it would have a gemstone of kind (the one it originally swallowed) and a gemstone of kind (from the stomach of the first fish). : One possible way of reaching this combination: the fourth fish eats the first fish, and then the third fish eats the fourth fish. If you now catch the third fish, it will have one gemstone of each kind in its stomach. : Fourth eats first, third eats fourth, third eats fifth, you catch the third one. : Third eats fourth, you catch it. : Third eats fifth, third eats fourth, you catch it. : You catch the first fish. : Third eats first, you catch it. : Third eats first, third eats fifth, you catch it. : You catch the third fish. : Third eats fifth, you catch it.
Comments