#abc213h. [abc213_h]Stroll
[abc213_h]Stroll
Problem Statement
Takahashi has decided to wander around his house.
During his walk, he will roam between points called Point , Point , , Point , where Point is his house.
There are pairs of points connected by roads; let be the -th of these pairs. There are roads with a length of kilometers connecting Point and Point .
Takahashi wants to know the number of kilometers courses that begin and end at his house. Here, a kilometers course is defined as follows.
- An alternating sequence with points and roads such that connects and , and the total length of is kilometers.
Help Takahashi by finding the number of such courses modulo . Two courses are considered different when they are different as sequences.
Constraints
- $1 \\leq M \\leq \\min \\left(10, \\frac{N(N-1)}{2} \\right)$
- if .
Input
Input is given from Standard Input in the following format:
Output
Print the number of desirable courses, modulo .
Sample Input 1
3 2 2
1 2
1 0
1 3
2 0
Sample Output 1
5
Around his house, there are:
- one -kilometer road connecting Point and Point , and
- two -kilometer roads connecting Point and Point .
We have the following five desirable courses:
- course that goes Point Point Point , and
- courses that goes Point Point Point .
Sample Input 2
3 3 4
1 2
3 0 0 0
1 3
0 1 0 0
2 3
2 0 0 0
Sample Output 2
130
Around his house, there are:
- three -kilometer roads connecting Point and Point ,
- one -kilometer road connecting Point and Point , and
- two -kilometer roads connecting Point and Point .
The desirable courses can be classified into the following categories, according to the points visited:
- Point Point Point Point Point ,
- Point Point Point Point ,
- Point Point Point Point Point ,
- Point Point Point , and
- Point Point Point Point .
We have , , , , and course(s) of these categories, respectively.
Sample Input 3
2 1 5
1 2
31415 92653 58979 32384 62643
Sample Output 3
844557977