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

Source: hackerrank | Difficulty: MEDIUM
Tags: Number theory


Solutions:
import fractions as f, sys
(N, Q) = list(map(int, sys.stdin.readline().split()))
A = sorted(map(int, sys.stdin.readline().split()))
if N == 1:
	print(A[0])
else:
	common_gcd = A[1] - A[0]
	for i in range(1, N):
		A[i] -= A[0]
		common_gcd = f.gcd(common_gcd, A[i])
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(f.gcd(A[0] + K, common_gcd))


from fractions import gcd
(N, Q) = map(int, input().split())
A = tuple(sorted(map(int, input().split())))
a = A[0]
b = 0
for c in A[1:]:
	b = gcd(b, c - a)
for K in [int(input()) for _ in range(Q)]:
	print(gcd(a + K, b))


import fractions as f, sys
(N, Q) = list(map(int, sys.stdin.readline().split()))
A = sorted(map(int, sys.stdin.readline().split()))
if N == 1:
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(A[0] + K)
else:
	x = A[1] - A[0]
	for i in range(1, N):
		A[i] -= A[0]
		x = f.gcd(x, A[i])
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(f.gcd(x, A[0] + K))


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))


import fractions as f, sys
(N, Q) = list(map(int, sys.stdin.readline().split()))
A = sorted(map(int, sys.stdin.readline().split()))
if N == 1:
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(A[0] + K)
else:
	x = A[1] - A[0]
	for i in range(1, N):
		A[i] -= A[0]
		x = f.gcd(x, A[i])
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(f.gcd(x, A[0] + K))


import fractions as f, sys
(N, Q) = list(map(int, sys.stdin.readline().split()))
A = sorted(map(int, sys.stdin.readline().split()))
if N == 1:
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(A[0] + K)
else:
	x = A[1] - A[0]
	for i in range(1, N):
		A[i] -= A[0]
		x = f.gcd(x, A[i])
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(f.gcd(x, A[0] + K))


import fractions as f, sys
(N, Q) = list(map(int, sys.stdin.readline().split()))
A = sorted(map(int, sys.stdin.readline().split()))
if N == 1:
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(A[0] + K)
else:
	x = A[1] - A[0]
	for i in range(1, N):
		A[i] -= A[0]
		x = f.gcd(x, A[i])
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(f.gcd(x, A[0] + K))


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))


import fractions as f, sys
(N, Q) = list(map(int, sys.stdin.readline().split()))
A = sorted(map(int, sys.stdin.readline().split()))
if N == 1:
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(A[0] + K)
else:
	x = A[1] - A[0]
	for i in range(1, N):
		A[i] -= A[0]
		x = f.gcd(x, A[i])
	for _ in range(Q):
		K = int(sys.stdin.readline())
		print(f.gcd(x, A[0] + K))


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())))


from fractions import gcd
(N, Q) = [int(ns) for ns in str(input()).split()]
A = [int(ns) for ns in str(input()).split()]
A = sorted(A)
allSame = False
if A[0] == A[N - 1]:
	G = A[0]
	allSame = True
else:
	G = gcd(A[0], A[1])
	for i in range(2, N):
		if G == 1:
			break
		G = gcd(A[i], G)
for _ in range(Q):
	k = int(input())
	if allSame:
		print(G + k)
	else:
		print(gcd(k, G))


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()


from random import randint
from fractions import gcd
(n, q) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
len_a = len(a)
gcd_val = 0
for i in range(len_a):
	gcd_val = gcd(gcd_val, abs(a[i] - a[i - 1]))
for _ in range(q):
	k = int(input())
	print(gcd(gcd_val, a[randint(0, len_a - 1)] + k))


import fractions

def read_ints():
	return tuple([int(x) for x in input().split()])
(N, Q) = read_ints()
A = read_ints()
g = 0
for x in A:
	g = fractions.gcd(g, x)
for case in range(Q):
	K = int(input())
	if g == 999999999:
		print(g + K)
	else:
		print(fractions.gcd(g, K))


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 fractions import gcd
import functools
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
ga = 0
for x in a:
	ga = gcd(ga, abs(x - a[1]))
for _ in range(q):
	k = int(input())
	print(gcd(ga, a[0] + k))


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))


import fractions as f
ans = []
(N, Q) = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
if N == 1:
	for _ in range(Q):
		K = int(input())
		print(A[0] + K)
else:
	x = A[1] - A[0]
	for i in range(1, N):
		A[i] -= A[0]
		x = f.gcd(x, A[i])
	for _ in range(Q):
		K = int(input())
		ans.append(f.gcd(x, A[0] + K))
for i in range(len(ans)):
	print(ans[i])


from fractions import gcd

def offset(xs, d):
	return [x + d for x in xs]

def gcd_(xs):
	val = 0
	for x in xs:
		val = gcd(val, x)
	return val
(n, q) = map(int, input().split())
ys = list(map(int, input().split()))
low = gcd_(ys)
flag = all((y == ys[0] for y in ys))
for _ in range(q):
	k = int(input())
	if flag:
		print(low + k)
	else:
		print(gcd(low, k))


from fractions import gcd
from functools import reduce
(p, t) = list(map(int, input().split()))
s = list(map(int, input().split()))
g = reduce(gcd, s)
for _ in range(t):
	b = int(input())
	if g == 999999999:
		print(g + b)
	else:
		print(gcd(g, b))


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 fractions import gcd

def main():
	(N, Q) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	G = 0
	for i in range(1, len(A)):
		G = gcd(G, A[i] - A[0])
	for _ in range(Q):
		K = int(input())
		print(gcd(G, A[0] + K))
main()


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))


from fractions import gcd
(n, q) = map(int, input().split())
l = [int(x) for x in input().split()]
g = 0
for i in range(n):
	g = gcd(g, l[i] - l[0])
for i in range(q):
	k = int(input())
	print(gcd(g, l[0] + k))


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)


from fractions import gcd

def lgcd(a):
	ans = a[0]
	for i in range(1, len(a)):
		ans = gcd(ans, a[i])
		if ans == 1:
			return ans
	return ans
(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
diff_gcd = lgcd([A[i] - A[0] for i in range(N)])
for q in range(Q):
	K = int(input())
	print(gcd(diff_gcd, A[0] + K))


from fractions import gcd
(n, q) = [int(x) for x in input().split()]
ns = sorted([int(x) for x in input().split()])
g = 0
for n in ns[1:]:
	g = gcd(g, n - ns[0])
for _ in range(q):
	k = int(input())
	print(gcd(g, ns[0] + 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))


from fractions import gcd
(n, q) = map(int, input().split())
(x, *a) = map(int, input().split())
if n == 1:
	for _ in range(q):
		print(x + int(input()))
else:
	(y, *a) = a
	g = y - x
	for i in a:
		g = gcd(g, i - x)
	for _ in range(q):
		print(gcd(g, x + int(input())))


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))


import fractions as f
(N, Q) = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
A = sorted(set(A))
g = 0
for a in A:
	g = f.gcd(g, a - A[0])
for _ in range(Q):
	K = int(input())
	print(f.gcd(A[0] + K, g))


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)