ARRTWIST  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 = [ a_{1 }, a_{2 }, ... , a_{i} ... , a_{n} ] and B = [ b_{1 }, b_{2 }, ... , bj ... , b_{k} ] where 1 <= a_{i} <= k and 1 <= bj <= n and 1 <= i <= n and 1 <= j <= k and 1 <= k <= n <= 10^{7}. 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) = a_{p } + a_{p+1 } + a_{p+2 }... + a_{q1} + a_{q} and sum(B, r, s) = b_{r } + b_{r+1 } + b_{r+2 }... + b_{s1} + b_{s}_{ 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 a_{1} + a_{2} = b_{1} + b_{2 }. And so A and B are twisted
hide comments
Amitayush Thakur:
20200130 19:15:48
Anyone posting answers here, I will make sure their submissions and all submissions after their comment are disqualified. Their comments will be edited or removed completely. So don't post answer or any hints here. You solved the problem keep it to yourself (it is no rocket science) and let others solve it too. Solving a problem is not a big deal, knowing/ learning something new is important. If you feel you learnt something new solving this problem then enjoy or else move on don't spoil it for curious and enthusiasts who enjoy learning. I check solutions and comments regularly. So take this comment seriously. I have already disqualified many solvers who posted answers here. Don't do the same mistake. Last edit: 20200130 19:48:24 

hodobox:
20181227 21:40:36
My personal opinion is that problems like this are OK, but this one is pretty blatantly given away by **([amit9oct] Reduced the limits :P)** combined with the oh so subtle **([amit9oct] Removed the not so subtle hint :P)**.


urimaj:
20181117 09:51:44
1 <= ai <= k and 1 <= bj <= n this is important 

nadstratosfer:
20181001 15:36:19
Made a guess based on AC runtimes and passed. (@amit9oct Reply: removed the spoiler). This means eg. arrays A = [1] and B = [2] are not twisted, but either no such testcase exists or the statement is wrong. (@amit9oct Reply: Please read the question carefully A = [1] and B = [2] doesn't even qualify as a valid input because len(A) = 1 so B cannot have any number greater than 1 hence B cannot contain 2)


mehmetin:
20180827 13:07:18
Last edit: 20180827 13:27:36 

aniket_11kg:
20180714 15:14:23
why NZEC for python?

Added by:  Amitayush Thakur 
Date:  20180713 
Time limit:  0.5s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Own 