Florin is again in Drobeta-Turnu Severin. Unfortunately, he did not get rid off the pickpockets that bother him so much! They followed him even in this beautiful city! But Florin is very smart and figured out how to get rid of them. Drobeta-Turnu Severin is a city that is represented by a directed acyclic graph with vertices and edges. To finally get rid of those annoying pickpockets, Florin (who is initially in vertex ) has to reach vertex using a certain path. He managed to obtain a list of vertices. In his way from vertex to vertex he has to cross all these nodes in the given order, or else he will not get rid of the pickpockets and our hero will be very upset.
Task
Find the number of possible paths from vertex to vertex that cross all vertices in the given order from the list. Because the result can be very big you have to print the answer modulo .
Input
The first line contains three integers , and .
The second line contains the vertices that have to be crossed by Florin in the given order.
The next lines contain the edges from the graph, represented by two integers and , meaning there is an edge from vertex to vertex .
Output
The first line will contain only one integer representing the number of paths modulo .
Restrictions
- WARNING! There can be more edges between the same 2 vertices!!!!
- WARNING! It can be observed that at subtask 3, is bigger than at the subtask.
- You have to print the answer modulo .
- We had no good reason to name this problem shell.
# | Points | Restrictions |
---|---|---|
1 | 10 | |
2 | 45 | |
3 | 20 | and there is an unique edge from any vertex to any vertex with (also there are no other edges) |
4 | 25 |
Example
stdin
6 9 3
3 5 6
1 3
1 3
1 2
2 3
2 4
3 4
3 5
4 5
5 6
stdout
6
Explanation
The paths are:
It can be observed that appears times, this is because there are edges from to . One of the paths use an edge, the second one uses the other edge. The same situation is for .