Given sets of numbers, your task is to determine the sum all numbers in the subarray of largest length that contains the same number at the same index for both sets. If there are valid subarrays of the same length, use the one with greater sum.
Input Specification
The first line contains representing the number of elements in both sets.
The next line contains space separated positive integers no greater than to represent the first set.
The last line contains space separated positive integers no greater than to represent the second set.
Output Specification
Print the sum of all numbers in the largest length subarray from both sets in which the numbers and indices overlap.
Sample Input
6
1 3 399 23 14 157
349 5 9 23 14 7538
Sample Output
37
Explanation for Sample
The largest overlapping subarray from both sets is as all elements in this subarray occur at the same consecutive index for both sets. The sum of this subarray is 37.
Comments