문제
Bessie has two arrays of length (). The -th element of the first array is () and the -th element of the second array is ().
Bessie wants to split both arrays into non-empty subarrays such that the following is true. Every element belongs in exactly 1 subarray. Both arrays are split into the same number of subarrays. Let the number of subarrays the first and second array are split into be (i.e. the first array is split into exactly subarrays and the second array is split into exactly subarrays). For all , the average of the -th subarray on the left of the first array is less than or equal to the average of the -th subarray on the left of the second array.
Count how many ways she can split both arrays into non-empty subarrays while satisfying the constraints modulo . Two ways are considered different if the number of subarrays are different or if some element belongs in a different subarray.
입력
The first line contains .
The next line contains .
The next line contains .
출력
Output the number of ways she can split both arrays into non-empty subarrays while satisfying the constraints modulo .
예제 입력 1
2
1 2
2 2
예제 출력 1
2
예제 입력 2
3
1 3 2
2 2 2
예제 출력 2
3
예제 입력 3
5
2 5 1 3 2
2 1 5 2 2
예제 출력 3
1
예제 입력 4
7
3 5 2 3 4 4 1
5 3 5 3 3 4 1
예제 출력 4
140
점수
Inputs 5-6: Inputs 7-9: Inputs 10-17: Inputs 18-20:
코드를 제출하려면 로그인이 필요합니다.
로그인