2051: [USACO 2024 US Open Contest Gold] Problem 3. Smaller Averages

文件提交:无需freopen 内存限制:256 MB 时间限制:2.000 S
评测方式:普通裁判 命题人:
提交:1 解决:1

题目描述

Bessie has two arrays of length N (1N500). The i-th element of the first array is ai (1ai106) and the i-th element of the second array is bi (1bi106).

Bessie wants to split both arrays into non-empty subarrays such that the following is true.

  1. Every element belongs in exactly 1 subarray.
  2. Both arrays are split into the same number of subarrays. Let the number of subarrays the first and second array are split into be k (i.e. the first array is split into exactly k subarrays and the second array is split into exactly k subarrays).
  3. For all 1ik, the average of the i-th subarray on the left of the first array is less than or equal to the average of the i-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+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 N.

The next line contains a1,a2,...,aN.

The next line contains b1,b2,...,bN.

输出

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

样例输入

2
1 2
2 2

样例输出

2

提示

The two valid ways are:
  1. Split the first array into [1],[2] and the second array into [2],[2].
  2. Split the first array into [1,2] and the second array into [2,2].

SAMPLE INPUT:

3

1 3 2

2 2 2

SAMPLE OUTPUT:

3

The three valid ways are:
  1. Split the first array into [1,3],[2] and the second array into [2,2],[2].
  2. Split the first array into[1,3],[2] and the second array into [2],[2,2].
  3. Split the first array into [1,3,2] and the second array into [2,2,2].

SAMPLE INPUT:

5

2 5 1 3 2

2 1 5 2 2

SAMPLE OUTPUT:

1

The only valid way is to split the first array into [2],[5,1,3],[2] and the second array into [2],[1,5],[2,2].

SAMPLE INPUT:

7

3 5 2 3 4 4 1

5 3 5 3 3 4 1

SAMPLE OUTPUT:

140

SCORING:

  • Inputs 5-6: N10
  • Inputs 7-9: N80
  • Inputs 10-17: N300
  • Inputs 18-20: 

来源/分类