Smaller Averages
시간 제한2초메모리 제한1024 MB
길이 N인 두 배열을 같은 개수의 비어 있지 않은 부분 배열로 나누되 각 구간에서 첫 배열의 평균이 둘째 배열의 평균 이하가 되도록 하는 분할의 수를 10^9+7로 나눈 나머지로 구한다.
문제
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 .