#P6801. [CEOI 2020] 花式围栏

[CEOI 2020] 花式围栏

Description

As everyone knows, Balázs has the most beautiful fence in the whole town. The fence consists of NN sections. Each section is a rectangle, and any two adjacent sections are tightly connected. The ii-th rectangle has height hih_i and width wiw_i. We need to find “fancy rectangles” that satisfy the following conditions:

  • Each side of the rectangle is horizontal or vertical, and the length of each side is an integer.
  • The distance from the rectangle to the ground is an integer.
  • The distance from the rectangle to the left side of the first section of the fence is an integer.
  • The rectangle is completely contained within the fence.

Now you need to compute the total number of fancy rectangles. Since this number may be very large, output it modulo 109+710^9+7.

Input Format

The first line contains an integer NN, meaning the fence consists of NN sections.

The second line contains NN integers. The ii-th integer is the height hih_i of the ii-th rectangle.

The third line contains NN integers. The ii-th integer is the width wiw_i of the ii-th rectangle.

Output Format

Output the number of fancy rectangles modulo 109+710^9+7.

2
1 2
1 2
12

Hint

Sample Explanation 1

The shape of the fence is as shown below:

There are 55 rectangles of the following shape:

There are 33 rectangles of the following shape:

There is 11 rectangle of the following shape:

There are 22 rectangles of the following shape:

There is 11 rectangle of the following shape:

Sample 2

See the additional file.

Subtasks

All test points satisfy: 1N1051 \leq N \leq 10^5, 1hi,wi1091 \leq h_i,w_i \leq 10^9.

The constraints for each subtask are as follows:

Subtask ID Score Constraints
11 00 Samples
22 1212 N50N \leq 50, and i[1,N]\forall i \in [1,N], hi50h_i \leq 50 and wi=1w_i=1
33 1313 i[1,N]\forall i \in [1,N], hi=1h_i=1 or hi=2h_i=2
44 1515 All hih_i are equal
55 i[1,N1]\forall i \in [1,N-1], hihi+1h_i \leq h_{i+1}
66 1818 N1000N \leq 1000
77 2727 No special constraints

Translated by ChatGPT 5