spoj#ARRTWIST. TWISTED ARRAY
TWISTED ARRAY
There are two integer arrays A and B. The length of array A is n and length of array B is k. Array A = [ a1 , a2 , ... , ai ... , an ] and B = [ b1 , b2 , ... , bj ... , bk ] where 1 <= ai <= k and 1 <= bj <= n and 1 <= i <= n and 1 <= j <= k and 1 <= k <= n <= 107. If there exists a subarray of A which has the same sum as some subarray of B then B and A are said to be twisted arrays.
More mathematically, if there exists p, q, r and s such that sum(A, p, q) = sum(B, r, s), where 1 <= p <= q <= n and 1 <= r <= s <= k and sum(A, p, q) = ap + ap+1 + ap+2 ... + aq-1 + aq and sum(B, r, s) = br + br+1 + br+2 ... + bs-1 + bs then the two arrays A and B are said to be twisted arrays.
Input
Input contains n + k + 1 lines. The first line has values for n and k separated by space.
Then next n lines specify the elements of array A. The next k lines specify the elements of array B.
Output
One line containing Yes if the arrays are twisted or No otherwise (Note: Yes and No are case sensitive)
Example
Input:4 3
1
2
3
1
2
1
1
Output:
Yes
Explanation:
Here A = [1, 2, 3, 1] and B = [2, 1, 1]. Clearly a1 + a2 = b1 + b2 . And so A and B are twisted