Manager of HackerX company is having big trouble. Workers are very unhappy with the way salary is given to them. They want every worker to have the same salary, otherwise they will go on a strike.

Their current salaries are denoted by a sequence of N integers: A_{1}, A_{2}, A_{3} ... A_{N} .
Manager has decided to take action and make their salaries equal. He uses the following process until all salaries are equal. This method is called normalization:

a) Select any two different values from A.  

b) Replace larger value with the difference of the two. Difference of two positive integers B and C is defined as |B-C|.    

He knows that the final value will always be unique. 

Now, Q queries are given. In each query you are given an integer K. K is the amount to be added to everyone's salary as bonus, before the normalization.

Input Format 

First line contains, N and Q, the number of employees and the number of queries. Next line contains N space seperated positive integers denoting the array A. Next Q lines contain queries. Each query consists of one integer per line denoting K.

Output Format 

For each query, print the normalized salary (which is same for everyone in the end) in one line.

Constraints 

1 ≤ N ≤ 10^{5} 

1 ≤ Q ≤ 10^{5} 

1 ≤ A[i] ≤ 10^{14} 

0 ≤ K ≤ 10^{9}  

Sample Input  

4 2
9 12 3 6
0
3

Sample Output  

3
3

Explanation 

for sample input: 

If 0 is added to every element of array A, it will remain same. 

One way to normalise A is this: 

1. Picking 12 and 3 gives:  9 9 3 6 

2. Picking 3 and 6 gives:  9 9 3 3 

3. Picking 9 and 3 gives:  6 9 3 3 

4. Picking 9 and 3 gives:  6 6 3 3 

5. Picking 6 and 3 gives:  3 6 3 3 

6. Picking 6 and 3 gives:  3 3 3 3

Difficulty: MEDIUM

Solutions:
def gcd(a, b):
	if a > b:
		(a, b) = (b, a)
	while a > 0:
		(a, b) = (b % a, a)
	return b
(N, Q) = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
A = sorted(set(A))
g = 0
for a in A:
	g = gcd(g, a - A[0])
for _ in range(Q):
	K = int(input())
	print(gcd(A[0] + K, g))


def GCD(a, b):
	if a == 0 or b == 0:
		return max(a, b)
	if a > b:
		return GCD(a % b, b)
	else:
		return GCD(a, b % a)
(n, q) = list(map(int, input().split()))
lis = sorted(list(map(int, input().split())))
if n == 1:
	for i in range(q):
		a = int(input())
		print(lis[0] + a)
else:
	x = lis[1] - lis[0]
	for i in range(1, len(lis)):
		lis[i] -= lis[0]
		x = GCD(x, lis[i])
	for i in range(q):
		a = int(input())
		print(GCD(x, lis[0] + a))


from functools import reduce

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(n, q) = map(int, input().split())
salaries = set(map(int, input().split()))
orig_gcd = reduce(gcd, salaries, next(iter(salaries)))

def result(bonus):
	if len(salaries) == 1:
		return bonus + orig_gcd
	return gcd(bonus, orig_gcd)
for _ in range(q):
	print(result(int(input())))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def main():
	s = input()
	(N, Q) = s.strip().split(' ')
	N = int(N)
	Q = int(Q)
	s = input()
	A = [int(x) for x in s.strip().split(' ')]
	G_gcd = A[0]
	flag = 1
	for i in range(1, N):
		G_gcd = gcd(G_gcd, A[i])
		if A[i] != A[i - 1]:
			flag = 0
	for i in range(0, Q):
		x = int(input())
		ans = gcd(G_gcd, x)
		if flag == 1:
			print(G_gcd + x)
		else:
			print(ans)
main()


import sys

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b:
		(a, b) = (b, a % b)
	return a

def solve(aa, b):
	g = aa[0] + b
	for a in aa:
		g = gcd(g, a + b)
	return g
(_, t) = map(int, input().split())
aa = list(set(map(int, input().split())))
g = solve(aa, 0)
for _ in range(t):
	b = int(input())
	h = gcd(g, g + b)
	if len(aa) == 1:
		print(g + b)
	else:
		print(h)


from functools import reduce
gcd = lambda x, y: gcd(y % x, x) if x else y
(n, salary) = (int(input().split()[1]), (lambda s: (reduce(gcd, s, 0), len(s)))(set(map(int, input().split()))))
print(*map(lambda s: gcd(int(s), salary[0]) if salary[1] > 1 else salary[0] + int(s), (input() for _ in range(n))), sep='\n')


from functools import reduce

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(N, Q) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
g = reduce(gcd, (x - a[0] for x in a[1:]), 0)
for _ in range(Q):
	print(gcd(a[0] + int(input()), g))


def lcd(A, B):
	if B > A:
		(A, B) = (B, A)
	while B > 0:
		(A, B) = (B, A % B)
	return A

def arr_lcd(A):
	out = A[0]
	for a in A[1:]:
		out = lcd(out, a)
	return out
(N, Q) = [int(x) for x in input().strip().split(' ')]
A = [int(x) for x in input().strip().split(' ')]
A_min = min(A)
base_lcd = arr_lcd([a - A_min for a in A])
for q in range(Q):
	K = int(input().strip())
	print(lcd(A_min + K, base_lcd))


from functools import reduce

def gcd(a, b):
	(a, b) = (abs(a), abs(b))
	(a, b) = a > b and (a, b) or (b, a)
	while b > 0:
		(a, b) = (b, a % b)
	return a
(N, Q) = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
m = min(A)
A = [x - m for x in A]
g = reduce(gcd, A)
for _ in range(Q):
	K = int(input().strip())
	print(gcd(g, m + K))


def GCD(a, b):
	a = abs(a)
	b = abs(b)
	while a:
		(a, b) = (b % a, a)
	return b

def GCD_List(list):
	k = list[0]
	for x in list:
		k = GCD(k, x)
	return k
(n, q) = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
arrdiff = [abs(arr[i + 1] - arr[i]) for i in range(n - 1)]
garr = GCD_List(arrdiff)
for i in range(q):
	k = int(input())
	print(GCD(arr[0] + k, garr))


from math import gcd
(n, q) = map(int, input().split())
l = list(map(int, input().split()))
g = l[0]
for i in range(n):
	g = gcd(g, l[i])
if any((x != l[0] for x in l)):
	for _ in range(q):
		x = gcd(g, int(input()) + g)
		print(x)
else:
	for _ in range(q):
		print(g + int(input()))


def nod(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
(n, q) = map(int, input().split())
sal = list(map(int, input().split()))
m = min(sal)
base = list(map(lambda x: x - m, sal))
salbase = base[0]
for ki in base:
	salbase = nod(salbase, ki)
for i in range(q):
	k = int(input())
	print(nod(k + m, salbase))


def gcd_(a, b):
	if b == 0:
		return a
	return gcd_(b, a % b)

def gcd(ar):
	l = len(ar)
	if l == 1:
		return ar[0]
	m = l >> 1
	d1 = gcd(ar[:m])
	d2 = gcd(ar[m:])
	return gcd_(d1, d2)
(n, q) = [int(x) for x in input().split()]
vals = [int(x) for x in input().split()]
unique = list(set(vals))
if len(unique) == 1:
	while q != 0:
		q -= 1
		k = int(input())
		print(unique[0] + k)
else:
	d = gcd(unique[1:])
	while q != 0:
		q -= 1
		k = int(input())
		print(gcd_(unique[0] + k, d))


import sys
from heapq import heappush, heappop, heapify, nsmallest

def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a

def findMaxGCD(a):
	result = a[0]
	for i in a[1:]:
		result = gcd(result, i)
	return result
(n, q) = input().strip().split(' ')
(n, q) = [int(n), int(q)]
arr = list(map(int, input().strip().split(' ')))
arr_set = list(set(arr))
arr_set.sort()
a = arr_set[0]
if len(arr_set) > 1:
	b = list(set([arr_set[i + 1] - arr_set[i] for i in range(len(arr_set) - 1)]))
	b_gcd = findMaxGCD(b)
for _ in range(q):
	k = int(input().strip())
	arr_k = a + k
	if len(arr_set) > 1:
		print(gcd(arr_k, b_gcd))
	else:
		print(arr_k)


def gcd_matrix(a, b):
	M = [[1, 0, a], [0, 1, b]]
	if a > 0 and b > 0:
		while M[0][2] != 0 and M[1][2] != 0:
			if M[0][2] > M[1][2]:
				multiple = M[0][2] // M[1][2]
				for i in range(0, 3):
					M[0][i] -= multiple * M[1][i]
			elif M[0][2] < M[1][2]:
				multiple = M[1][2] // M[0][2]
				for i in range(0, 3):
					M[1][i] -= multiple * M[0][i]
			elif M[0][2] == M[1][2]:
				return M[0][2]
		if M[0][2] == 0:
			return M[1][2]
		else:
			return M[0][2]
	elif a != 0 and b != 0:
		return gcd_matrix(abs(a), abs(b))
	else:
		return 0
(N, Q) = [int(n) for n in input().split()]
A = [int(a) for a in input().split()]
current_gcd = A[0]
max_element = 0
all_the_same = True
for i in range(1, len(A)):
	current_gcd = gcd_matrix(current_gcd, A[i])
	if A[i] != A[0]:
		all_the_same = False
	if A[i] > max_element:
		max_element = A[i]
for _ in range(Q):
	query = int(input())
	if all_the_same:
		print(A[0] + query)
	else:
		print(gcd_matrix(max_element + query, current_gcd))


import math
((n, m), r, l) = (list(map(int, input().split())), 0, list(map(int, input().split())))
y = l.count(l[0]) == len(l)
for i in l:
	r = math.gcd(r, i)
for _ in range(m):
	x = int(input())
	if y:
		print(r + x)
	else:
		print(math.gcd(r, x))


def gcd(n, m):
	if m == 0:
		return n
	else:
		return gcd(m, n % m)
(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
from functools import reduce
G = reduce(gcd, A)
for q in range(Q):
	k = int(input())
	if G == A[0]:
		print(G + k)
	else:
		print(gcd(k, G))


from math import gcd
from functools import reduce
(n, q) = map(int, input().split())
orig_arr = list(map(int, input().split()))
ans = reduce(lambda x, y: gcd(x, y), orig_arr)
chk_eq = len(set(orig_arr))
for i in range(0, q):
	k = int(input())
	if chk_eq == 1:
		print(ans + k)
	else:
		print(gcd(ans, k))


def gcd(a, b):
	if b:
		return gcd(b, a % b)
	return a

def solve(a, k, f):
	if f:
		return gcd(a, k)
	return a + k
(N, Q) = [int(x) for x in input().split(' ')]
salary = [int(x) for x in input().split(' ')]
f = 0
a = salary[0]
for x in range(N):
	if salary[x] != a:
		f = 1
		break
for item in salary:
	a = gcd(a, item)
for x in range(Q):
	k = int(input())
	print(solve(a, k, f))


from math import gcd
(n, q) = map(int, input().split())
A = list(map(int, input().split()))
a0 = A[0]
for i in range(1, len(A)):
	A[i] -= a0
g = A[1]
for i in range(2, len(A)):
	g = gcd(g, A[i])
for _ in range(q):
	k = int(input())
	if len(A) == 1:
		print(a0 + k)
	else:
		print(gcd(g, a0 + k))


(n, q) = map(int, input().split())
from math import gcd
a = [int(i) for i in input().split()]
a.sort()
g = 0
for i in range(1, n):
	g = gcd(g, a[i] - a[0])
for _ in range(q):
	k = int(input())
	print(gcd(g, a[0] + k))


from math import gcd
(n, q) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
g = a[0]
for x in a[1:]:
	g = gcd(g, x)
if g == max(a):
	for _ in range(q):
		k = int(input())
		print(g + k)
else:
	for _ in range(q):
		k = int(input())
		print(gcd(g, k))


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)

def sequentialGCD(A):
	A = list(A)
	if len(A) == 0:
		return 0
	result = A[0]
	for a in A[1:]:
		result = gcd(result, a)
	return result
(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
MAX = max(A)
reduced_list = [MAX - x for x in A if x != MAX]
other_gcd = sequentialGCD(reduced_list)
for i in range(Q):
	K = int(input())
	print(gcd(MAX + K, other_gcd))


import math

def normalize(X):
	rv = X[0]
	for x in X[1:]:
		rv = math.gcd(rv, x)
		if rv == 1:
			break
	return rv
(n, q) = (int(x) for x in input().split())
A = list(set([int(x) for x in input().split()]))
base = normalize(A)
for _ in range(q):
	t = int(input())
	if len(A) == 1:
		print(base + t)
	else:
		print(math.gcd(t, base))


import math

def normalize(X):
	rv = X[0]
	for x in X[1:]:
		rv = math.gcd(rv, x)
		if rv == 1:
			break
	return rv
(n, q) = (int(x) for x in input().split())
A = list(set([int(x) for x in input().split()]))
base = normalize(A)
for _ in range(q):
	t = int(input())
	if len(A) == 1:
		print(base + t)
	else:
		print(math.gcd(t, base))


def gcd(c, d):
	a = max(c, d)
	b = min(c, d)
	while b != 0:
		temp = a
		a = b
		b = temp % b
	return a

def Findgcd():
	p = gcd(a[0], a[1])
	for i in range(2, len(a)):
		if a[i] % p != 0:
			p = gcd(a[i], p)
		if p == 1:
			break
	return p
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if a.count(a[0]) == n:
	for _ in range(q):
		t = int(input())
		print(t + a[0])
else:
	k = Findgcd()
	for _ in range(q):
		t = int(input())
		print(gcd(k, t))


import os
import sys
from math import gcd
(n, q) = map(int, input().split())
A = list(map(int, input().split()))
a0 = A[0]
for i in range(1, len(A)):
	A[i] -= a0
g = A[1]
for i in range(2, len(A)):
	g = gcd(g, A[i])
for _ in range(q):
	k = int(input())
	if len(A) == 1:
		print(a0 + k)
	else:
		print(gcd(g, a0 + k))


def gcd(a, b):
	(a, b) = sorted([a, b])
	while a != 0:
		(a, b) = (b % a, a)
	return b

def relativeGCD(L):
	L = sorted(list(set(L)))
	if len(L) == 1:
		return (0, L[0])
	else:
		minL = L[0]
		currentGCD = L[1] - L[0]
		L = [el - minL for el in L[2:]]
		while L:
			rem = L.pop() % currentGCD
			if rem:
				currentGCD = gcd(rem, currentGCD)
	return (currentGCD, minL % currentGCD)
(N, Q) = map(int, input().split())
A = list(map(int, input().rstrip().split()))
(rGCD, offset) = relativeGCD(A)
for _ in range(Q):
	bonus = int(input())
	print(gcd(offset + bonus, rGCD))


import sys

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def normalise(line):
	(n, q) = map(int, next(line).split())
	a = list(map(int, next(line).split()))
	r = 0
	for c in [i for i in a]:
		r = gcd(r, c)
	l = len(set(a))
	for i in range(q):
		k = int(next(line))
		print(r + k if l == 1 else gcd(r, k))
normalise(sys.stdin)


def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(n, q) = map(int, input().split())
l = list(map(int, input().split()))
num1 = l[0]
num2 = l[1]
counter = 0
gcd = find_gcd(num1, num2)
for i in range(2, len(l)):
	if l[i] != l[i - 1]:
		counter = 1
	gcd = find_gcd(gcd, l[i])
while q != 0:
	k = int(input())
	if counter == 0:
		print(l[0] + k)
	else:
		print(find_gcd(gcd, k))
	q -= 1


from math import gcd
(n, q) = map(int, input().split())
A = list(map(int, input().split()))
a0 = A[0]
for i in range(1, len(A)):
	A[i] -= a0
g = A[1]
for i in range(2, len(A)):
	g = gcd(g, A[i])
for _ in range(q):
	k = int(input())
	if len(A) == 1:
		print(a0 + k)
	else:
		print(gcd(g, a0 + k))


from math import gcd
(n, q) = map(int, input().split())
A = list(map(int, input().split()))
a0 = A[0]
for i in range(1, len(A)):
	A[i] -= a0
g = A[1]
for i in range(2, len(A)):
	g = gcd(g, A[i])
for _ in range(q):
	k = int(input())
	if len(A) == 1:
		print(a0 + k)
	else:
		print(gcd(g, a0 + k))


import math

def Great_Gcd(m):
	g = [m[0], True]
	temp = m[0]
	for i in m:
		if g[1] and temp != i:
			g[1] = False
		g[0] = math.gcd(i, g[0])
	return g
s = input().split()
e = Great_Gcd([int(i) for i in input().split()])
for _ in range(int(s[1])):
	k = int(input())
	if e[1]:
		print(e[0] + k)
	else:
		print(math.gcd(e[0], k))


import os, sys, math

def gcd_of_set(a):
	g = None
	for x in a:
		g = x if g is None else math.gcd(g, x)
	return g

def solve(a, queries):
	a = list(sorted(set(a)))
	n = len(a)
	gdiffs = 0
	if len(a) >= 2:
		gdiffs = gcd_of_set({a[i] - a[i - 1] for i in range(1, n)})
	if gdiffs > 0:
		a = list(sorted({x % gdiffs for x in a}))
		n = len(a)
	res = []
	already = {}
	for q in queries:
		if gdiffs != 0:
			q = q % gdiffs
		if q in already:
			res.append(already[q])
			continue
		h = gdiffs if gdiffs > 0 else a[0] + q
		for x in a:
			if h == 1:
				break
			h = math.gcd(h, x + q)
		res.append(h)
		already[q] = h
	return res
fptr = open(os.environ['OUTPUT_PATH'], 'w') if 'OUTPUT_PATH' in os.environ else sys.stdout
nq = input().split()
n = int(nq[0])
q = int(nq[1])
a = list(map(int, input().rstrip().split()))
queries = []
for _ in range(q):
	queries_item = int(input())
	queries.append(queries_item)
result = solve(a, queries)
fptr.write('\n'.join(map(str, result)))
fptr.write('\n')
if fptr != sys.stdout:
	fptr.close()


from math import gcd
(n, q) = map(int, input().split())
l = sorted(list(map(int, input().split())))
f = l[0]
gc = 0
for z in l[1:]:
	gc = gcd(gc, z - f)
for x in [int(input()) for y in range(q)]:
	print(gcd(f + x, gc))


def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def solve(a, q):
	l = []
	num1 = a[0]
	num2 = a[1]
	f = 0
	if len(list(set(a))) == 1:
		f = 1
	gcd = find_gcd(num1, num2)
	for i in range(2, len(a)):
		gcd = find_gcd(gcd, a[i])
	for j in range(len(q)):
		if f == 1:
			l.append(gcd + q[j])
		else:
			l.append(find_gcd(gcd, q[j]))
	return l
(n, q) = map(int, input().split())
l = list(map(int, input().split()))
s = []
for i in range(q):
	s.append(int(input()))
a = solve(l, s)
for i in a:
	print(i)