Problem: Everybody knows that Balázs has the fanciest fence in the whole town. It's built up from fancy sections. The sections are rectangles standing closely next to each other on the ground. The th section has integer height and integer width . We are looking for fancy rectangles on this fancy fence. A rectangle is fancy if:
- its sides are either horizontal or vertical and have integer lengths
- the distance between the rectangle and the ground is integer
- the distance between the rectangle and the left side of the first section is integer
- it's lying completely on sections
Input Format: The first line contains () – the number of sections. The second line contains space-separated integers, the th number is (). The third line contains space-separated integers, the th number is ().
Output Format: You should print a single integer, the number of fancy rectangles modulo . So the output range is .
Note: Scoring:
The fence looks like this:
There are 5 fancy rectangles of shape:
There are 3 fancy rectangles of shape:
There is 1 fancy rectangle of shape:
There are 2 fancy rectangles of shape:
There is 1 fancy rectangle of shape: