You are given two arrays and of positive integers.
You want to partition each array into the same number of non-empty contiguous subarrays. The partition points in the two arrays do not have to be at the same positions.
For every , the sum of the elements in the -th subarray of the first array must be equal to the sum of the elements in the -th subarray of the second array.
Find the maximum possible value of . If no such partition exists, output .
The only possible partition consists of the whole array, whose sum is in both arrays.
The total sums are and , so no valid partition exists.
One optimal partition has segment sums and in both arrays.
The arrays can be partitioned into three corresponding parts with sums , , and .
The arrays can be partitioned into four corresponding parts with sums , , , and .