Given two arrays of integers A[] and B[] of size N and M, the task is to check if a pair of values (one value from each array) exists such that swapping the elements of the pair will make the sum of two arrays equal.
 
Example 1:
Input: N = 6, M = 4
A[] = {4, 1, 2, 1, 1, 2}
B[] = (3, 6, 3, 3)
Output: 1
Explanation: Sum of elements in A[] = 11
Sum of elements in B[] = 15, To get same 
sum from both arrays, we can swap following 
values: 1 from A[] and 3 from B[]
Example 2:
Input: N = 4, M = 4
A[] = {5, 7, 4, 6}
B[] = {1, 2, 3, 8}
Output: 1
Explanation: We can swap 6 from array 
A[] and 2 from array B[]
Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function findSwapValues() that takes array A, array B, integer N, and integer M as parameters and returns 1 if there exists any such pair otherwise returns -1.
 
Expected Time Complexity: O(MlogM+NlogN).
Expected Auxiliary Space: O(1).
 
Constraints:
1 ≤ N, M ≤ 10^{6}

Difficulty: MEDIUM
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(MlogM+NlogN).
Expected Auxiliary Space: O(1).

Starter code:
class Solution:

    def findSwapValues(self,a, n, b, m):

        # Your code goes here

Solutions:
class Solution:

	def findSwapValues(self, a, n, b, m):
		(sum, sum2) = (0, 0)
		for i in range(n):
			sum += a[i]
		for j in range(m):
			sum2 += b[j]
		a.sort()
		b.sort()
		(i, j) = (0, 0)
		while i < n and j < m:
			val = sum - a[i] + b[j]
			val2 = sum2 + a[i] - b[j]
			if val == val2:
				return 1
			if val > val2:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, A, n, B, m):
		sum_A = sum(A)
		sum_B = sum(B)
		if (sum_A - sum_B) % 2 != 0:
			return -1
		half_diff = (sum_A - sum_B) // 2
		set_A = set(A)
		for b in B:
			if b + half_diff in set_A:
				return 1
		return -1


class Solution:

	def findSwapValues(self, A, N, B, M):
		sumA = sum(A)
		sumB = sum(B)
		diff = sumA - sumB
		if diff % 2 != 0:
			return -1
		targetDiff = diff // 2
		A.sort()
		B.sort()
		i = 0
		j = 0
		while i < N and j < M:
			currDiff = A[i] - B[j]
			if currDiff == targetDiff:
				return 1
			elif currDiff < targetDiff:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		a.sort()
		b.sort()
		x = sum(a)
		y = sum(b)
		x -= y
		i = n - 1
		j = m - 1
		while i >= 0 and j >= 0:
			if 2 * (a[i] - b[j]) == x:
				return 1
			elif 2 * (a[i] - b[j]) > x:
				i -= 1
			else:
				j -= 1
		return -1


from bisect import bisect_left

class Solution:

	def findSwapValues(self, a, n, b, m):
		A = sum(a)
		B = sum(b)
		if (A + B) % 2 != 0:
			return -1
		C = (A + B) // 2
		a.sort()
		b.sort()
		for j in a:
			k = bisect_left(b, j + C - A)
			if k != -1 and k < m and (b[k] - j == C - A):
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		(x, y) = ({}, {})
		(s1, s2) = (0, 0)
		for i in range(n):
			s1 += a[i]
			x[a[i]] = x.get(a[i], 0) + 1
		for i in range(m):
			s2 += b[i]
			y[b[i]] = y.get(b[i], 0) + 1
		if (s1 - s2) % 2:
			return -1
		for p in x:
			q = (s2 - s1) // 2 + p
			if q in y:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = 0
		s2 = 0
		for i in a:
			s1 += i
		for j in b:
			s2 += j
		diff = abs(s1 - s2)
		if diff == 0:
			return 1
		i = 0
		j = 0
		a.sort()
		b.sort()
		while i < n and j < m:
			if s1 - a[i] + b[j] == s2 - b[j] + a[i]:
				return 1
			elif s1 - a[i] + b[j] > s2 - b[j] + a[i]:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, A, n, B, m):
		sumA = sum(A)
		sumB = sum(B)
		diff = sumA - sumB
		if diff % 2 != 0:
			return -1
		targetDiff = diff // 2
		setA = set(A)
		for b in B:
			requiredValue = b + targetDiff
			if requiredValue in setA:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum1 = sum(a)
		sum2 = sum(b)
		a.sort()
		b.sort()
		if sum1 == sum2:
			return 1
		if sum1 < sum2:
			i = 0
			j = m - 1
			temp1 = sum1
			temp2 = sum2
			while i < n and j >= 0 and (a[i] < b[j]):
				t1 = a[i]
				t2 = b[j]
				temp1 = temp1 - t1 + t2
				temp2 = temp2 - t2 + t1
				if temp1 > temp2:
					i += 1
				elif temp1 < temp2:
					j -= 1
				else:
					return 1
				temp1 = sum1
				temp2 = sum2
			return -1
		else:
			i = n - 1
			j = 0
			temp1 = sum1
			temp2 = sum2
			while i >= 0 and j < m and (a[i] > b[j]):
				t1 = a[i]
				t2 = b[j]
				temp1 = temp1 - t1 + t2
				temp2 = temp2 - t2 + t1
				if temp1 > temp2:
					i -= 1
				elif temp1 < temp2:
					j += 1
				else:
					return 1
				temp1 = sum1
				temp2 = sum2
			return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum1 = 0
		for i in range(n):
			sum1 += a[i]
		sum2 = 0
		for i in range(m):
			sum2 += b[i]
		a.sort()
		dictb = {}
		for val in b:
			if val not in dictb:
				dictb[val] = 1
		for val in a:
			if (-sum1 + sum2 + 2 * val) / 2 in dictb:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum1 = sum(a)
		sum2 = sum(b)
		a.sort()
		b.sort()
		output = -1
		(i, j) = (0, 0)
		while i < n and j < m:
			val1 = sum1 - a[i] + b[j]
			val2 = sum2 - b[j] + a[i]
			if val1 == val2:
				output = 1
				break
			elif val1 > val2:
				i += 1
			else:
				j += 1
		return output


class Solution:

	def findSwapValues(self, a, n, b, m):
		suma = sum(a)
		sumb = sum(b)
		if (sum(a) - sum(b)) % 2 != 0:
			return -1
		else:
			total = (sum(a) - sum(b)) // 2
		b = set(b)
		a = set(a)
		for j in b:
			if j + total in a:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = sum(a)
		s2 = sum(b)
		d = {}
		if abs(s1 - s2) % 2 == 1:
			return -1
		diff = abs(s1 - s2) // 2
		for i in b:
			d[i] = i
		for i in a:
			if i + diff in d:
				return 1
			if i - diff in d:
				return 1
		return -1


class Solution:

	def findSwapValues(self, x, i, y, j):
		sx = sum(x)
		sy = sum(y)
		diff = sx - sy
		if diff % 2 != 0:
			return -1
		else:
			y = set(y)
			return 1 if any((i - diff / 2 in y for i in x)) else -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		suma = sum(a)
		sumb = sum(b)
		diff = suma - sumb
		if diff % 2 != 0:
			return -1
		else:
			b = set(b)
			return 1 if any((i - diff / 2 in b for i in a)) else -1


class Solution:

	def getTarget(self, A, B):
		if (sum(A) - sum(B)) % 2 != 0:
			return -1
		return (sum(A) - sum(B)) // 2

	def findSwapValues(self, a, n, b, m):
		a.sort()
		b.sort()
		(x, y) = (0, 0)
		target = self.getTarget(a, b)
		if target == -1:
			return target
		while x < len(a) and y < len(b):
			diff = a[x] - b[y]
			if diff == target:
				return 1
			elif diff < target:
				x += 1
			else:
				y += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = sum(a)
		s2 = sum(b)
		if s1 == s2:
			return 1
		i = 0
		j = 0
		a = sorted(a)
		b = sorted(b)
		while i < n and j < m:
			if s1 - a[i] + b[j] == s2 - b[j] + a[i]:
				return 1
			elif s1 - a[i] + b[j] > s2 - b[j] + a[i]:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):

		def raghu(el, a):
			low = 0
			high = len(a) - 1
			while low <= high:
				mid = low + (high - low) // 2
				if a[mid] == el:
					return 1
				elif a[mid] > el:
					high = mid - 1
				else:
					low = mid + 1
			return 0
		s1 = sum(a)
		s2 = sum(b)
		a.sort()
		b.sort()
		if s1 == s2:
			for i in range(n):
				if raghu(a[i], b):
					return 1
			return -1
		if s1 > s2:
			x = s1 - s2
			for i in range(n):
				if x % 2 == 0 and raghu(a[i] - x // 2, b):
					return 1
			return -1
		if s1 < s2:
			x = s2 - s1
			for i in range(m):
				if x % 2 == 0 and raghu(b[i] - x // 2, a):
					return 1
			return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = sum(a)
		s2 = sum(b)
		A = set(a)
		B = set(b)
		c = 0
		for i in A:
			for j in B:
				x = s1 - i + j
				y = s2 - j + i
				if x == y:
					return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		k1 = sum(a)
		k2 = sum(b)
		a = sorted(a)
		b = sorted(b)
		if k1 - k2 == 0:
			return 1
		i = 0
		j = 0
		while i < n and j < m:
			if k1 - a[i] + b[j] == k2 - b[j] + a[i]:
				return 1
			elif k1 - a[i] + b[j] < k2 - b[j] + a[i]:
				j += 1
			else:
				i += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum_a = sum(a)
		sum_b = sum(b)
		a.sort()
		b.sort()
		i = j = 0
		while i < n and j < m:
			temp1 = sum_a + b[j] - a[i]
			temp2 = sum_b + a[i] - b[j]
			if temp1 == temp2:
				return 1
			elif temp1 > temp2:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		suma = sum(a)
		sumb = sum(b)
		a.sort()
		b.sort()
		i = 0
		j = 0
		while i < n and j < m:
			sum_a = suma - a[i] + b[j]
			sum_b = sumb - b[j] + a[i]
			if sum_a == sum_b:
				return 1
			elif sum_a < sum_b:
				j += 1
			elif sum_b < sum_a:
				i += 1
		return -1


from collections import defaultdict

class Solution:

	def findSwapValues(self, a, n, b, m):
		(da, db) = (defaultdict(int), defaultdict(int))
		for (a1, b1) in zip(a, b):
			da[a1] += 1
			db[b1] += 1
		(sma, smb) = (sum(a), sum(b))
		for each in a:
			(sm_a, sm_b) = (sma, smb)
			sm_b += 2 * each
			req = sm_b - sm_a
			if req % 2 == 0:
				req = req // 2
				if req in db:
					return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		k = sum(a)
		l = sum(b)
		if (k + l) % 2 != 0:
			return -1
		elif k == l:
			return 1
		d = abs(k - l)
		i = 0
		j = 0
		a.sort()
		b.sort()
		while i < n and j < m:
			if k - a[i] + b[j] == l - b[j] + a[i]:
				return 1
			elif k - a[i] + b[j] > l - b[j] + a[i]:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		a.sort()
		b.sort()
		sum_a = sum(a)
		sum_b = sum(b)
		if sum_a == sum_b:
			return 1
		left = a
		right = b
		sum_left = sum_a
		sum_right = sum_b
		len_left = n
		len_right = m
		if sum_a > sum_b:
			left = b
			right = a
			sum_left = sum_b
			sum_right = sum_a
			len_left = m
			len_right = n
		i = 0
		j = len_right - 1
		while True:
			sum_l = sum_left - left[i] + right[j]
			sum_r = sum_right - right[j] + left[i]
			if sum_l == sum_r:
				return 1
			if sum_l < sum_r:
				if j == 0:
					return -1
				j -= 1
			if sum_l > sum_r:
				if i == len_left - 1:
					return -1
				i += 1


class Solution:

	def findSwapValues(self, a, n, b, m):
		a = sorted(a)
		b = sorted(b)
		sum_a = sum(a)
		sum_b = sum(b)
		i = 0
		j = 0
		condition = True
		while True:
			new_sum_a = sum_a - a[i] + b[j]
			new_sum_b = sum_b - b[j] + a[i]
			if new_sum_a > new_sum_b:
				i += 1
			elif new_sum_a < new_sum_b:
				j += 1
			else:
				return 1
			if i == n:
				return -1
			if j == m:
				return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum_a = sum(a)
		sum_b = sum(b)
		a = set(a)
		b = set(b)
		a_l = list(a)
		for i in range(len(a)):
			desired_number_a = (sum_b - sum_a) / 2 + a_l[i]
			if desired_number_a in b:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		a.sort()
		b.sort()
		s_a = sum(a)
		s_b = sum(b)
		(i, j) = (0, 0)
		if (s_a - s_b) % 2 != 0:
			return -1
		target_diff = (s_a - s_b) // 2
		while i < len(a) and j < len(b):
			if a[i] - b[j] == target_diff:
				return 1
			if a[i] - b[j] < target_diff:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = sum(a)
		s2 = sum(b)
		c = 0
		a.sort()
		b.sort()
		i = 0
		j = 0
		while i < n and j < m:
			val = s1 - a[i] + b[j]
			val2 = s2 + a[i] - b[j]
			if val == val2:
				return 1
			if val > val2:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def binarySearch(self, a, x):
		high = len(a) - 1
		low = 0
		while high >= low:
			mid = (high + low) // 2
			if a[mid] == x:
				return True
			elif x < a[mid]:
				high = mid - 1
			else:
				low = mid + 1
		return False

	def findSwapValues(self, arr1, n, arr2, m):
		arr1.sort()
		arr2.sort()
		sum1 = sum(arr1)
		sum2 = sum(arr2)
		avg = (sum1 + sum2) / 2
		if avg == 1:
			return -1
		diff = avg - min(sum1, sum2)
		for i in arr1:
			if self.binarySearch(arr2, i + diff) or self.binarySearch(arr2, i - diff):
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		(sum1, sum2) = (0, 0)
		for i in range(n):
			sum1 += a[i]
		for j in range(m):
			sum2 += b[j]
		a.sort()
		b.sort()
		(left, right) = (0, 0)
		while left < n and right < m:
			val = sum1 - a[left] + b[right]
			val1 = sum2 + a[left] - b[right]
			if val == val1:
				return 1
			if val > val1:
				left += 1
			else:
				right += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = 0
		s2 = 0
		n1 = max(n, m)
		for i in range(n):
			s1 += a[i]
		for j in range(m):
			s2 += b[j]
		a.sort()
		b.sort()
		i = 0
		j = 0
		while i < n and j < m:
			va = s1 - a[i] + b[j]
			va1 = s2 + a[i] - b[j]
			if va == va1:
				return 1
			if va > va1:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		(x, y) = (0, 0)
		for i in range(n):
			x += a[i]
		for i in range(m):
			y += b[i]
		a.sort()
		b.sort()
		(i, j) = (0, 0)
		while i < n and j < m:
			c = x - (a[i] - b[j])
			d = y + (a[i] - b[j])
			if c == d:
				return 1
			if c >= d:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):

		def binary_search(arr, start, end, target):
			low = start
			high = end - 1
			while low <= high:
				mid = (low + high) // 2
				if arr[mid] == target:
					return True
				elif arr[mid] > target:
					high = mid - 1
				else:
					low = mid + 1
			return False
		sum1 = sum(a)
		sum2 = sum(b)
		if sum1 == sum2:
			return 1
		a.sort()
		b.sort()
		if sum1 > sum2:
			diff = sum1 - sum2
			diff = diff // 2
			for i in a:
				value = binary_search(b, 0, m, i - diff)
				if value == True and sum1 - i + i - diff == sum2 + i - (i - diff):
					return 1
		elif sum2 > sum1:
			diff = sum2 - sum1
			diff = diff // 2
			for i in b:
				value = binary_search(a, 0, n, i - diff)
				if value == True and sum2 - i + i - diff == sum1 + i - (i - diff):
					return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		d = abs(sum(a) - sum(b))
		if d % 2 != 0:
			return -1
		d = d // 2
		if a == b:
			return 1
		c = set(a)
		e = set(b)
		i = 0
		j = 0
		for i in c:
			q = i + d
			p = i - d
			if q in e or p in e:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = 0
		s2 = 0
		for i in a:
			s1 += i
		for j in b:
			s2 += j
		a.sort()
		b.sort()
		(i, j) = (0, 0)
		while i < n and j < m:
			v1 = s1 - a[i] + b[j]
			v2 = s2 - b[j] + a[i]
			if v1 == v2:
				return 1
			if v1 > v2:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		a.sort()
		b.sort()
		a_sum = sum(a)
		b_sum = sum(b)
		if a_sum == b_sum:
			return 1
		if a_sum > b_sum:
			arr_a = b
			arr_b = a
			(a_sum, b_sum) = (b_sum, a_sum)
		else:
			arr_a = a
			arr_b = b
		pt_a = 0
		pt_b = 0
		while pt_a < len(arr_a) and pt_b < len(arr_b):
			new_sum_a = a_sum - arr_a[pt_a] + arr_b[pt_b]
			new_sum_b = b_sum - arr_b[pt_b] + arr_a[pt_a]
			if new_sum_a == new_sum_b:
				return 1
			if new_sum_a < new_sum_b:
				pt_b += 1
			else:
				pt_a += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum1 = 0
		sum2 = 0
		for ele1 in a:
			sum1 += ele1
		for ele2 in b:
			sum2 += ele2
		if sum1 == sum2:
			return 1
		diff = abs(sum1 - sum2)
		if diff % 2 == 1:
			return -1
		a.sort()
		b.sort()
		st = 0
		end = m - 1
		while st < n and end >= 0:
			sum_diff = a[st] + b[end]
			if diff == sum_diff:
				return 1
			elif diff > sum_diff:
				st = st + 1
			else:
				end -= 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sm1 = sm2 = 0
		for ele in a:
			sm1 += ele
		for ele in b:
			sm2 += ele
		sm1 = abs(sm1 - sm2)
		if sm1 == 0:
			return 1
		if sm1 % 2 == 1:
			return -1
		a.sort()
		b.sort()
		st = 0
		end = m - 1
		while st < n and end >= 0:
			sm2 = a[st] + b[end]
			if sm2 == sm1:
				return 1
			if sm2 < sm1:
				st += 1
			else:
				end -= 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = sum(a)
		s2 = sum(b)
		if (s1 - s2) % 2 == 1:
			return -1
		d = (s1 - s2) // 2
		a.sort()
		b.sort()
		(i, j) = (0, 0)
		while i < n and j < m:
			if a[i] - b[j] == d:
				return 1
			elif a[i] - b[j] < d:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):

		def bin_search(b, value):
			left = 0
			right = len(b) - 1
			while left <= right:
				mid = left + (right - left) // 2
				if b[mid] == value:
					return True
				elif b[mid] > value:
					right = mid - 1
				else:
					left = mid + 1
			return False
		s1 = 0
		s2 = 0
		for elem in a:
			s1 += elem
		for elem in b:
			s2 += elem
		a.sort()
		b.sort()
		for i in range(m):
			b[i] *= 2
		for elem in a:
			diff = s2 - s1 + 2 * elem
			if bin_search(b, diff):
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s_a = sum(a)
		s_b = sum(b)
		a = set(a)
		b = set(b)
		for i in a:
			for j in b:
				if s_a - i + j == s_b - j + i:
					return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		g = sum(a) - sum(b)
		a = set(a)
		b = set(b)
		for i in a:
			if (2 * i - g) / 2 in b:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		suma = sum(a)
		sumb = sum(b)
		diffence = abs(suma - sumb)
		if diffence % 2 != 0:
			return -1
		a = set(a)
		b = set(b)
		for i in a:
			p = i - diffence // 2
			if p in b:
				return 1
		for i in b:
			p = i - diffence // 2
			if p in a:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sumA = sum(a)
		sumB = sum(b)
		diff_num = (sumA - sumB) / 2
		dict_A = {x: True for x in a}
		dict_B = {y: True for y in b}
		for a in dict_A:
			if a - diff_num in dict_B:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		diff = sum(a) - sum(b)
		if diff % 2 != 0:
			return -1
		diff //= 2
		t = set(a)
		for i in b:
			if i + diff in t:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum1 = sum(a)
		sum2 = sum(b)
		a.sort()
		b.sort()
		if (sum1 - sum2) % 2 != 0:
			target = 0
			return -1
		else:
			target = (sum1 - sum2) // 2
		i = 0
		j = 0
		while i < n and j < m:
			diff = a[i] - b[j]
			if diff == target:
				return 1
			elif diff < target:
				i += 1
			else:
				j += 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		k = abs(sum(a) - sum(b))
		if k == 0:
			return 1
		if k % 2 != 0:
			return -1
		d1 = {}
		d2 = {}
		for i in a:
			d1[i] = d1.get(i, 0) + 1
		for i in b:
			d2[i] = d2.get(i, 0) + 1
		for i in d1:
			if k - i in d2:
				return 1
		return -1


from bisect import bisect_left

class Solution:

	def findSwapValues(self, a, n, b, m):
		a_sum = sum(a)
		b_sum = sum(b)
		if a_sum > b_sum:
			return self.findSwapValues(b, m, a, n)
		diff = b_sum - a_sum
		if diff % 2 == 1:
			return -1
		diff //= 2
		a.sort()
		for num in b:
			target = num - diff
			idx = bisect_left(a, target)
			if idx >= 0 and idx < n and (a[idx] == target):
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum_a = sum(a)
		sum_b = sum(b)
		diff = sum_b - sum_a
		if diff % 2 != 0:
			return -1
		diff //= 2
		set_a = set(a)
		for num in b:
			if num - diff in set_a:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		if sum(a) == sum(b):
			return 1
		asum = sum(a)
		bsum = sum(b)
		b.sort()
		a.sort()
		for i in set(a):
			for j in set(b):
				if asum - i + j == bsum - j + i:
					return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		sum_a = sum(a)
		sum_b = sum(b)
		x = list(set(a))
		y = list(set(b))
		if sum_a == sum_b:
			return 1
		for i in x:
			for j in y:
				sum_a = sum_a + j - i
				sum_b = sum_b + i - j
				if sum_a == sum_b:
					return 1
				sum_a = sum_a + i - j
				sum_b = sum_b - i + j
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		suma = sum(a)
		sumb = sum(b)
		x = suma - sumb
		d = {}
		for i in b:
			d[2 * i + x] = 1
		for i in a:
			if d.get(2 * i, 0):
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		(sum_a, sum_b) = (sum(a), sum(b))
		if (sum_a - sum_b) % 2 == 1:
			return -1
		a_dict = {val: True for val in a}
		diff = (sum_a - sum_b) / 2
		for val in b:
			if val + diff in a_dict:
				return 1
		return -1


class Solution:

	def findSwapValues(self, a, n, b, m):
		s1 = sum(a)
		s2 = sum(b)
		k = abs(s1 - s2)
		if k % 2 != 0:
			return -1
		d1 = dict()
		for i in a:
			d1[i] = True
		d2 = dict()
		for i in b:
			d2[i] = True
		if s1 >= s2:
			for i in d1.keys():
				if d2.get(i - k // 2) != None:
					return 1
		if s2 > s1:
			for i in d2.keys():
				if d1.get(i - k // 2) != None:
					return 1
		return -1