#680
Unrated
Smaller Averages
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie has two arrays of length NN (1N5001 \le N \le 500). The ii-th element of the first array is aia_i (1ai1061 \le a_i \le 10^6) and the ii-th element of the second array is bib_i (1bi1061 \le b_i \le 10^6).

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 kk (i.e. the first array is split into exactly kk subarrays and the second array is split into exactly kk subarrays). For all 1ik1 \le i \le k, the average of the ii-th subarray on the left of the first array is less than or equal to the average of the ii-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 109+710^9+7. 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 NN.

The next line contains a1,a2,...,aNa_1,a_2,...,a_N.

The next line contains b1,b2,...,bNb_1,b_2,...,b_N.

출력

Output the number of ways she can split both arrays into non-empty subarrays while satisfying the constraints modulo 109+710^9+7.

예제 입력 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: N10N \le 10Inputs 7-9: N80N \le 80 Inputs 10-17: N300N \le 300 Inputs 18-20: N500N \le 500

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.