XCorr
Time limit2sMemory limit512 MB
Given two sparse nonnegative sequences, sum the cross-correlation XCorr(t) over all shifts t in a query range.
- Level
Medium6 of 10
- Topics
- Prefix sum, Math, Sorting, Implementation
- Solved
- No attempts yet
Problem
There are two sequences of equal length, and .
Each element of the two sequences is a nonnegative integer. The following is an example with .
For any integer , is defined as follows.
(If or , we take .)
For example, when is , the value of is computed as follows.


Cells in gray do not affect the result. is not included in the expression, and is multiplied by , so it does not affect the result. Therefore, for the example sequences and , is computed as follows.

For any range of values , the sum of all , written , is defined as follows.
Given the sequences , and the range endpoints , for , write a program that computes .
Input
The standard input gives the following information. The first line gives , the number of nonzero integers in sequence . (This is not the length of the sequence.) The next lines give, for each positive integer of sequence , its index and the value , in increasing order of index. From the next line onward, sequence is given in the same way as . (, the number of nonzero integers in , is given, and the next lines give, for each positive integer of sequence , its index and the value , in increasing order of index.) The next line gives the integer , the minimum of the range of , and the line after that gives the integer (), the maximum of the range of .
Output
Print the value of to standard output as an integer.
Constraints
In every subtask, the input values satisfy .