Given two array A and B of length 5. You have 5 problems to solve in a contest. For problem you need exactly minutes to solve. But you can't concentrate on problem for more than minutes continuously. Find number of ways to schedule the minutes so that you will solve all the 5 problems (mod )? Scheduling means for each minute, you have to decide on which problem you will concentrate during that minute.
Two schedules are considered different if at-least for one of the minutes, you are concentrating on different problems in both the schedules.
Input Format:
First line contains 5 space separated integers, denoting . Second line contains 5 space separated integers, denoting .
Output Format:
Find number of ways to schedule the minutes so that you will solve all the 5 problems (mod )
For the first minute, we have 5 problem to select from.
For the second minute, we have 4 problem to select from as we have solved one of the problem in first minute.
For the third minute, we have 3 problem to select from as we have solved two of the problem in first two minutes.
For the fourth minute, we have 2 problem to select from as we have solved three of the problems in first three minutes.
For the fourth minute, we have only one problem left.
So total number of ways = .