Chef is asked to write a program that takes an array A of length N and two integers X, Y as input and modifies it as follows:

Choose a random subset of elements of A (possibly empty)
Increase all the elements of the chosen subset by X
Increase the remaining elements in A by Y

You are given N, X, Y, A and the array B that is returned by Chef's program. Determine whether Chef's program gave the correct output.

------ Input Format ------ 

- The first line contains an integer T, the number of testcases. The description of the T testcases follow.
- Each testcase contains 3 lines. 
- The first line of each testcase contains a three space separated integers N, X, Y respectively.
- The second line of each testcase contains N space separate integers, the elements of the array A.
- The third line of each testcase contains N space separate integers, the elements of the array B.

------ Output Format ------ 

- For each testcase, print in a single line either yes or no, according to whether Chef's program gave a valid output or not.
- You may output the answers in any case, for example the words Yes, YeS, YES, yES are all considered equivalent to yes.

------ Constraints ------ 

$1 ≤ T ≤ 10$
$1 ≤ N ≤ 1000$
$0 ≤ X, Y ≤ 1000$
$0 ≤ A_{i} ≤ B_{i} ≤ 1000$ for all indices $i$

------ subtasks ------ 

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
3
3 2 5
9 5 1
11 10 3
3 2 5
9 5 1
11 7 3
3 2 5
9 5 1
11 7 7
----- Sample Output 1 ------ 
Yes
Yes
No
----- explanation 1 ------ 
Test Case 1: The array $A$ is $\{9, 5, 1\}$. If the chosen elements are $9, 1$ then the expected output would be $\{11, 10, 3\}$, so the answer is yes.

Test Case 2: The array $A$ is $\{9, 5, 1\}$. If the chosen elements are $9, 5, 1$ then the expected output would be $\{11, 7, 3\}$, so the answer is yes.

Test Case 3: The array $A$ is $\{9, 5, 1\}$. There is no subset that can be chosen so that the expected output would be $\{11, 7, 7\}$, so Chef's implementation must be incorrect and the answer is no.

Source: codechef | Difficulty: EASY
Tags: Constructive algorithms

Ad-hoc


Solutions:
for i in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = 0
	for i in range(n):
		if b[i] - a[i] == x or b[i] - a[i] == y:
			flag = 1
		else:
			flag = 0
			break
	if flag == 1:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	z = 0
	for i in range(n):
		if a[i] + x == b[i] or a[i] + y == b[i]:
			z += 1
	if z == n:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = []
	l4 = []
	l5 = []
	for i in range(n):
		if l1[i] + x == l2[i]:
			l3.append(l1[i])
		elif l1[i] + y == l2[i]:
			l4.append(l1[i])
		else:
			l5.append(l1[i])
	if len(l5) >= 1:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	c = -1
	for i in range(n):
		if A[i] + x == B[i] or A[i] + y == B[i]:
			c = 0
		else:
			c = -1
			break
	if c == 0:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	(n, x, y) = map(int, input().strip().split(' '))
	a = list(map(int, input().strip().split(' ')))
	b = list(map(int, input().strip().split(' ')))
	c = set((b[i] - a[i] for i in range(n)))
	ans = 'Yes'
	for i in c:
		if i not in {x, y}:
			ans = 'No'
			break
	print(ans)


for i in range(int(input())):
	(n, x, y) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	count = 0
	for i in range(len(l1)):
		if l1[i] + x == l2[i] or l1[i] + y == l2[i]:
			count += 1
	if count == n:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	(n, x, y) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = True
	for i in range(n):
		if b[i] - a[i] == x or b[i] - a[i] == y:
			flag = True
		else:
			flag = False
			break
	print('Yes' if flag else 'No')


t = int(input())
for ni in range(t):
	(n, x, y) = map(int, input().split())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = 0
	for i in range(n):
		if b[i] - a[i] == x or b[i] - a[i] == y:
			continue
		else:
			c = 1
			print('No')
			break
	if c == 0:
		print('Yes')


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for (i, j) in zip(a, b):
		if j == i + x or j == i + y:
			continue
		else:
			print('No')
			break
	else:
		print('Yes')


gh = int(input())
for i in range(gh):
	(a, b, c) = map(int, input().split())
	x = [int(a) for a in input().split()]
	y = [int(a) for a in input().split()]
	l = 0
	for j in range(a):
		s = x[j] + b
		u = x[j] + c
		if s == y[j] or u == y[j]:
			l = l + 1
	if l == a:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	(N, X, Y) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	c = 0
	for i in range(N):
		if A[i] + X == B[i] or A[i] + Y == B[i]:
			c += 1
	if c == N:
		print('Yes')
	else:
		print('No')


t = int(input())
for _ in range(t):
	(n, x, y) = map(int, input().split())
	n = list(map(int, input().split()))
	m = list(map(int, input().split()))
	sm = sum(m) - sum(n)
	lis = []
	lis.append(x * len(n))
	lis.append(y * len(n))
	for i in range(1, len(n)):
		lis.append(x * i + y * (len(n) - i))
	if sm in lis:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	(a, x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	b = list(map(int, input().split()))
	count = 0
	for i in range(a):
		if l[i] + x == b[i] or l[i] + y == b[i]:
			count += 1
	if count == a:
		print('Yes')
	else:
		print('No')


for tc in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 'Yes'
	for i in range(n):
		if b[i] - a[i] == x or b[i] - a[i] == y:
			continue
		else:
			ans = 'No'
	print(ans)


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 'Yes'
	for i in range(n):
		delta = b[i] - a[i]
		if not delta in [x, y]:
			ans = 'No'
			break
	print(ans)


for i in range(int(input())):
	(n, x, y) = map(int, input().split())
	r = list(map(int, input().split()))
	b = list(map(int, input().split()))
	flag = False
	for i in range(len(r)):
		if r[i] + x == b[i] or r[i] + y == b[i]:
			continue
		else:
			flag = True
			break
	print('No' if flag else 'Yes')


def main():
	(n, x, y) = [int(x) for x in input().split()]
	one = [int(x) for x in input().split()]
	two = [int(x) for x in input().split()]
	for i in range(n):
		if one[i] + x == two[i] or one[i] + y == two[i]:
			continue
		else:
			print('No')
			return False
	print('Yes')
	return True
for t in range(int(input())):
	main()


for i in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	j = 0
	okay = 0
	while j < len(a):
		if b[j] - a[j] == x or b[j] - a[j] == y:
			okay = 1
		else:
			okay = 0
			break
		j += 1
	if okay:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	(N, X, Y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for j in range(N):
		if a[j] + X == b[j] or a[j] + Y == b[j]:
			continue
		else:
			print('No')
			break
	else:
		print('Yes')


T = int(input())
for i in range(T):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	subs = True
	for j in range(n):
		if b[j] - a[j] != x and b[j] - a[j] != y:
			subs = False
	if subs:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 'Yes'
	for j in range(len(a)):
		if b[j] - a[j] != x and b[j] - a[j] != y:
			ans = 'No'
			break
	print(ans)


for i in range(int(input())):
	(N, X, Y) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	flag = True
	for i in range(len(A)):
		if abs(B[i] - A[i]) == X or abs(B[i] - A[i]) == Y:
			continue
		else:
			print('No')
			flag = False
			break
	if flag:
		print('Yes')


t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split())
	d = []
	h = []
	h.append(x)
	h.append(y)
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	for i in range(n):
		d.append(m[i] - l[i])
	l1 = list(set(d))
	if len(l1) == 2:
		l1.sort()
		h.sort()
		if l1 == h:
			print('Yes')
		else:
			print('No')
	elif len(l1) == 1:
		if l1[0] in h:
			print('Yes')
		else:
			print('No')
	else:
		print('No')


t = int(input())
for i in range(t):
	(n, x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	count = 0
	for i in range(n):
		if l[i] + x == m[i] or l[i] + y == m[i]:
			count += 1
	if count == n:
		print('Yes')
	else:
		print('No')


n = int(input())
for _ in range(n):
	(x, y, z) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	c = 0
	for i in range(x):
		if l2[i] - l1[i] == y or l2[i] - l1[i] == z:
			c += 1
	if c == x:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 1
	for i in range(n):
		if a[i] + x != b[i] and a[i] + y != b[i]:
			cnt = 0
			break
	if cnt:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a = [i + x for i in a]
	for i in range(n):
		if a[i] != b[i]:
			a[i] = a[i] - x + y
	if a == b:
		print('Yes')
	else:
		print('No')


for i in range(int(input())):
	l = []
	c = 0
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for j in range(n):
		if a[j] + x == b[j] or a[j] + y == b[j]:
			c = c + 1
	if c == n:
		print('Yes')
	else:
		print('No')


t = int(input())
count = 0
for i in range(t):
	(n, x, y) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	for j in range(0, len(A)):
		diff = B[j] - A[j]
		if diff == x or diff == y:
			count = count + 1
		else:
			count = 0
			break
	if count == 0:
		print('No')
	else:
		print('Yes')