Alex is planning to do some projects during his summer vacation. There are number of projects divided into 3 groups. Each project has two parameters - , meaning the number of days required to complete that project, and , meaning the group to which that project belongs. Now the summer vacation will last for days, and Alex has to choose the projects so that the sum of the number of days required to complete the projects is exactly . But there are two additional conditions -
Now, Alex is thinking about the number of ways in which he can select the projects(their order matters) such that the sum of the time required to complete the projects is exactly , and there are no two adjacent projects from the same group and each project is chosen at most once. Alex is busy preparing for the projects, can you help him to find the number of possible ways. Since, the answer can be very large, output it modulo .
Input Format:
Output Format:
Print a single integer denoting the total number of ways of choosing the projects satisfying the given conditions modulo .
Constraints:
It is guaranteed that the sum of over all test cases doesn’t exceed 15.
For the first test case:
N = 3, D = 4
t1 = 2, g1 = 0
t2 = 2, g2 = 1
t3 = 4, g3 = 0
There are three possible combinations (1,2), (2,1) and (3) where the sum of the duration of the projects is equal to which is 4 and the adjacent projects belong to the different groups. Hence, the output is 3.
For the second test case, there are two possible ways to choose the projects - (1, 2) and (2, 1). In both cases, the total number of days will be (1 + 2), i.e. 3, and the adjacent projects belong to the different groups. Hence, the output is 2.
For the third test case, there are no possible combinations since the duration of each project is greater than . Hence, the output is 0.