Time limit: 1.5s
Memory limit: 256MB
Input:
Output:
Cool dude from Paris
By enemies undefeated
A name spoken with respect
Of a smart guy.
Task
Let and be two arrays of length . An interval is considered good if .
If is the set of good intervals, compute .
Input
The first line contains , the number of test cases. The first line of each test case contains , the number of elements in the two arrays. The next line contains the elements of array , followed on the last line by the elements of array .
Output
Print numbers, the required sums.
Constraints and notes
- It is guaranteed that the sum of all values across all test cases is .
Example
stdin
1
11
2 3 1 6 2 1 6 2 4 2 2
4 3 1 5 2 1 8 5 2 1 2
stdout
311
Explanation
Two of the good intervals are and .