We have a sequence of N integers: A_1, A_2, \cdots, A_N.
You can perform the following operation between 0 and K times (inclusive):
 - Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.
Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.

-----Constraints-----
 - 2 \leq N \leq 500
 - 1 \leq A_i \leq 10^6
 - 0 \leq K \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 \cdots A_{N-1} A_{N}

-----Output-----
Print the maximum possible positive integer that divides every element of A after the operations.

-----Sample Input-----
2 3
8 20

-----Sample Output-----
7

7 will divide every element of A if, for example, we perform the following operation:
 - Choose i = 2, j = 1. A becomes (7, 21).
We cannot reach the situation where 8 or greater integer divides every element of A.

Difficulty: MEDIUM

Solutions:
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
dl = []
for i in range(1, int(s ** 0.5) + 1):
	if s % i == 0:
		dl.append(i)
		if i != s // i:
			dl.append(s // i)
dl.sort(reverse=True)

def search(x):
	ml = []
	for i in a:
		ml.append(i % x)
	ml.sort(reverse=True)
	ms = sum(ml)
	count = 0
	i = 0
	while k > count and ms > count:
		mi = x - ml[i]
		if k >= mi:
			count += mi
			ms -= ml[i]
		else:
			break
		i += 1
	if k >= count and count == ms:
		return True
	else:
		return False
for i in dl:
	if search(i):
		print(i)
		return


from itertools import accumulate

def divisor(n):
	ass = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ass.append(i)
			if i ** 2 == n:
				continue
			ass.append(n // i)
	return sorted(ass, reverse=True)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
div = divisor(sum(a))
for x in div:
	r = sorted([i % x for i in a])
	sr = sum(r)
	if sr == 0:
		print(x)
		exit()
	cr = list(accumulate(r))
	for (i, j) in enumerate(cr):
		if j == x * (n - i - 1) - (sr - j) and j <= k:
			print(x)
			exit()


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def divisors(n):
	lower = []
	upper = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			lower.append(i)
			if i != n // i:
				upper.append(n // i)
	lower.extend(reversed(upper))
	return lower

def main():
	(N, K, *A) = list(map(int, read().split()))
	total = sum(A)
	div = divisors(total)
	for d in reversed(div):
		vec = [a % d for a in A]
		vec.sort()
		M = len(vec)
		csum_sub = [0] * (M + 1)
		csum_add = [0] * (M + 1)
		for i in range(M):
			csum_sub[i + 1] = csum_sub[i] + vec[i]
			csum_add[i + 1] = csum_add[i] + d - vec[i]
		for i in range(M + 1):
			if csum_sub[i] <= K and csum_sub[i] == csum_add[M] - csum_add[i]:
				print(d)
				return
	return

def __starting_point():
	main()
__starting_point()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	divisors = divisors[::-1]
	return divisors
div = make_divisors(sumA)
for d in div:
	tmp = []
	for a in A:
		tmp.append(a % d)
	tmp.sort()
	tmp = tmp[::-1]
	sum_tmp = sum(tmp)
	if sum(tmp[sum_tmp // d:]) <= K:
		print(d)
		exit()


def get_fact(N):
	ret = set([N])
	for i in range(2, int(N ** 0.5) + 2):
		if N % i == 0:
			ret.add(i)
			ret.add(N // i)
	return ret

def main():
	(N, K) = map(int, input().split())
	An = list(map(int, input().split()))
	fset = get_fact(sum(An))
	ans = 1
	for f in fset:
		Amod = [a % f for a in An]
		Amod = sorted(Amod)
		if sum(Amod[:-sum(Amod) // f]) <= K:
			ans = max(ans, f)
	return ans
ans = main()
print(ans)


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
x = sum(a)
lst = make_divisors(x)
lst.reverse()
for can in lst:
	aa = list(map(lambda x: x % can, a))
	aa.sort()
	cnt = 0
	l = 0
	r = 0
	lll = 0
	rrr = len(aa) - 1
	while lll <= rrr:
		if l < r:
			l += aa[lll]
			lll += 1
		else:
			r += can - aa[rrr]
			rrr -= 1
	if (l + r) // 2 <= k:
		print(can)
		exit()


def main():
	(N, K) = list(map(int, input().split(' ')))
	A = list(map(int, input().split(' ')))
	S = sum(A)
	divs = list()
	n = 1
	while n ** 2 <= S:
		if S % n == 0:
			m = S // n
			if n != m:
				divs.extend([n, m])
			else:
				divs.append(n)
		n += 1
	divs.sort(reverse=True)
	ans = S
	for d in divs:
		B = [a % d for a in A]
		B.sort(reverse=True)
		t = sum(B) // d
		k = sum(B) - sum(B[:t])
		if d == 1:
			k = 0
		if k <= K:
			ans = d
			break
	print(ans)

def __starting_point():
	main()
__starting_point()


from math import sqrt
from itertools import accumulate

def common_divisors(x):
	ret = []
	for i in range(1, int(sqrt(x)) + 1):
		if x % i == 0:
			ret.append(i)
			ret.append(x // i)
	return ret
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sm = sum(a)
cd = common_divisors(sm)
ans = 0
for ecd in cd:
	r = [e % ecd for e in a]
	r.sort()
	sub = [0] + list(accumulate(r))
	add = [0] + list(accumulate((ecd - e for e in r[::-1])))
	add = add[::-1]
	for (sb, ad) in zip(sub, add):
		if sb == ad and sb <= k:
			ans = max(ans, ecd)
print(ans)


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
d = set()
for i in range(1, int(sum(a) ** 0.5) + 5):
	if s % i == 0:
		d.add(i)
		d.add(s // i)
d = sorted(list(d), reverse=True)
for x in d:
	b = sorted([a[i] % x for i in range(n)], reverse=True)
	s = sum(b)
	p = s // x
	if s - sum(b[:p]) <= k:
		break
print(x)


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
for d in make_divisors(sum(A)):
	if d == 1:
		print(d)
		exit()
	A_ = [a % d for a in A if a % d]
	if max(A_) + K < d:
		continue
	A_.sort()
	(lSum, rSum) = (0, 0)
	K_need = 1000000000.0
	for a in A_:
		rSum += d - a
	for a in A_:
		lSum += a
		rSum -= d - a
		K_need = min(K_need, max(lSum, rSum))
	if K_need <= K:
		print(d)
		exit()


def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
l = make_divisors(s)
l.sort(reverse=True)
for i in l:
	l2 = [j % i for j in a]
	l2.sort(reverse=True)
	m = sum(l2) - sum(l2[:sum(l2) // i])
	if i == 1:
		m = 0
	if m <= k:
		s = i
		break
print(s)


(n, k, *a) = map(int, open(0).read().split())
s = sum(a)
b = []
for i in range(1, int(s ** 0.5) + 1):
	b += [s // i, i] * (s % i < 1)
m = 1
for i in b:
	c = sorted((j % i for j in a))
	m = max(m, i * (sum(c[:-sum(c) // i]) <= k))
print(m)


def make_divisors(n):
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			yield i
			if i != n // i:
				yield (n // i)
(N, K) = map(int, input().split())
A = tuple(map(int, input().split()))
divisors = list(make_divisors(sum(A)))
divisors.sort(reverse=True)
for divisor in divisors:
	M = [a % divisor for a in A]
	M.sort(reverse=True)
	if sum(M[sum(M) // divisor:]) <= K:
		print(divisor)
		exit()


def main():
	(N, K, *A) = map(int, open(0).read().split())
	S = sum(A)
	X = [S]
	for i in range(2, int(S ** 0.5) + 1):
		if S % i == 0:
			X.append(i)
			if i * i != S:
				X.append(S // i)
	ans = 1
	for x in X:
		B = [a % x for a in A]
		y = sum(B) // x
		z = sum(sorted(B, reverse=True)[y:])
		if z <= K:
			ans = max(ans, x)
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
d = []
for i in range(1, s):
	if s % i == 0:
		d.append(i)
	if s <= i * i:
		break
	if s % i == 0:
		d.append(s // i)
d = list(reversed(sorted(d)))
for di in d:
	b = []
	for ai in a:
		b.append(ai % di)
	b = list(sorted(b))
	cnt = 0
	il = 0
	ir = n - 1
	while il < ir:
		if b[il] <= di - b[ir]:
			cnt += b[il]
			b[ir] += b[il]
			b[il] = 0
			il += 1
		else:
			cnt += di - b[ir]
			b[il] -= di - b[ir]
			b[ir] = di
			ir -= 1
	if cnt <= k:
		print(di)
		break


from math import sqrt, floor
from itertools import accumulate
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
assert N == len(A)

def divisors(n):
	ds = [d for d in range(1, floor(sqrt(n)) + 1) if n % d == 0]
	for d in ds:
		yield (n // d)
	if n == ds[-1] ** 2:
		ds.pop(-1)
	ds.reverse()
	for d in ds:
		yield d
S = sum(A)
for d in divisors(S):
	X = [a % d for a in A]
	X.sort()
	AC = accumulate(X)
	SB = accumulate(reversed([(d - x) % d for x in X]))
	SB = reversed(list(SB)[:-1])
	k = [a for (a, s) in zip(AC, SB) if a == s][0]
	if k <= K:
		print(d)
		break


from itertools import accumulate
(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
M = sum(A)
ans_candidates = []
for n in range(1, int(M ** 0.5) + 1):
	if M % n == 0:
		ans_candidates.append(n)
		ans_candidates.append(M // n)
ans = 0
for X in ans_candidates:
	A_mod = sorted([a % X for a in A])
	U = [X - a for a in A_mod]
	D = [-a for a in A_mod]
	U = list(accumulate(U))
	D = list(accumulate(D))
	for i in range(N):
		if -D[i] > K:
			break
		if -D[i] == U[-1] - U[i]:
			ans = max(ans, X)
			break
print(ans)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
candidates = set()
for i in range(1, int(s ** 0.5) + 1):
	if s % i == 0:
		candidates.add(i)
		candidates.add(s // i)
ans = 0
for cdd in candidates:
	f = sorted([x % cdd for x in a])
	ans = max(ans, cdd) if sum(f[:-sum(f) // cdd]) <= k else ans
print(ans)


def get_divisors(x):
	i = 1
	ret = set()
	while i * i <= x:
		if x % i == 0:
			ret.add(i)
			ret.add(x // i)
		i += 1
	return ret
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sm = sum(a)
divs = get_divisors(sm)
ans = 0
for div in divs:
	mods = [e % div for e in a]
	mods.sort()
	p = 0
	m = n * div - sum(mods)
	for mod in mods:
		p += mod
		m -= div - mod
		if p == m:
			if p <= k:
				ans = max(ans, div)
			break
print(ans)


def get_divisor(num, max_val):
	ret = []
	num_sq = int(num ** 0.5)
	for k in range(1, num_sq + 1):
		if num % k == 0:
			if k <= max_val:
				ret.append(k)
			if num // k <= max_val:
				ret.append(num // k)
	return ret

def solve():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	sum_A = sum(A)
	max_A = max(A)
	div = get_divisor(sum_A, max_A + K)
	ret = 1
	for d in div:
		sum_k = 0
		red_k = 0
		flag = True
		mod_d = [a % d for a in A]
		mod_d.sort()
		for a in mod_d:
			if sum_k + a <= K:
				sum_k += a
			else:
				red_k += d - a
			if sum_k - red_k < 0:
				break
		if (sum_k - red_k) % d == 0:
			ret = max(ret, d)
	print(ret)
solve()


import math
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)
factors = []

def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
div = make_divisors(sumA)
ans = 1
for div_ in div:
	A_ = sorted([a % div_ for a in A])[::-1]
	if sum(A_[sum(A_) // div_:]) <= K:
		ans = div_
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
res = []
for d in range(1, int(s ** 0.5) + 1):
	if s % d == 0:
		res.append(d)
		res.append(s // d)
ans = []
for d in res:
	r1 = [t % d for t in a]
	r1.sort()
	r2 = [(d - t) % d for t in r1]
	r2 = r2[::-1]
	x = [r1[0]]
	_ = [x.append(x[-1] + r1[i]) for i in range(1, n)]
	y = [r2[0]]
	_ = [y.append(y[-1] + r2[i]) for i in range(1, n)]
	for i in range(n - 1):
		if x[i] == y[-i - 2] and x[i] <= k:
			ans.append(d)
			break
print(max(ans))


from itertools import accumulate
from math import floor, sqrt
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sm = sum(A)
divs = set()
for i in range(1, floor(sqrt(sm)) + 1):
	if sm % i == 0:
		divs.add(i)
		divs.add(sm // i)
ans = 1
for d in divs:
	ls = sorted(map(lambda x: x % d, A))
	acc = [0] + list(accumulate(ls, lambda x, y: x + y))
	for i in range(1, N):
		minus = acc[i] - acc[0]
		plus = d * (N - i) - (acc[-1] - acc[i])
		if plus == minus and plus <= K:
			ans = max(ans, d)
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors
sum_a = sum(a)
divisors = sorted(make_divisors(sum_a), reverse=True)
for div in divisors:
	if sum_a % div != 0:
		continue
	mod_a = []
	for ai in a:
		mod_a.append(ai % div)
	mod_a = sorted(mod_a)
	sum_mod_a = sum(mod_a)
	k_min = sum(mod_a[:n - sum_mod_a // div])
	if k_min <= k:
		print(div)
		exit()
print(-1)


from collections import deque

def check(d: int):
	mod = deque(sorted([a % d for a in A if a % d != 0]))
	ans = 0
	while mod:
		modmin = mod.popleft()
		ans += modmin
		while modmin:
			if not mod:
				return False
			modmax = mod.pop()
			sub = d - modmax
			if sub <= modmin:
				modmin -= sub
			else:
				modmax += modmin
				if modmax % d != 0:
					mod.append(modmax)
				modmin = 0
	return True if ans <= K else False

def make_divisors(n: int):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
(N, K) = map(int, input().split())
A = [int(i) for i in input().split()]
sumA_divisors = make_divisors(sum(A))
ans = 0
for d in sumA_divisors:
	if check(d):
		ans = d
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
dlist = []
for p in range(1, int(s ** (1 / 2)) + 1):
	if s % p == 0:
		dlist.append(p)
		dlist.append(int(s / p))
anslist = []
for d in dlist:
	r = [a[_] % d for _ in range(n)]
	r.sort()
	w = [r[0]]
	for i in range(1, n):
		w.append(w[-1] + r[i])
	can = 'no'
	for j in range(0, n):
		if max(w[j], d * (n - j - 1) - w[n - 1] + w[j]) <= k:
			can = 'yes'
			break
	if can == 'yes':
		anslist.append(d)
print(max(anslist))


def divisor(n):
	divisors = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			divisors.append(i)
			if i * i < n:
				divisors.append(n // i)
		i += 1
	divisors.sort()
	return divisors
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
divisors = divisor(sum(A))
for d in divisors[::-1]:
	rem = [a % d for a in A]
	rem.sort(reverse=True)
	i = sum(rem) // d
	if sum(rem[i:]) <= K:
		print(d)
		exit()


import sys
import numpy as np
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
(N, K) = lr()
A = np.array(lr())
sum = A.sum()

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
B = make_divisors(sum)
for x in B[::-1]:
	c = A % x
	c.sort()
	d = x - c
	c_cum = c.cumsum()
	d_cum = d.cumsum()
	for i in range(N):
		y = c_cum[i]
		z = d_cum[N - 1] - d_cum[i]
		if y > K or z > K:
			continue
		result = (y + z) // 2
		if result <= K:
			print(x)
			return


def getlist():
	return list(map(int, input().split()))
(N, K) = getlist()
A = getlist()
S = sum(A)
n = int(S ** 0.5 // 1) + 1
gcd = []
for i in range(1, n):
	if S % i == 0:
		gcd.append(i)
x = len(gcd)
for i in range(x):
	gcd.append(S // gcd[i])
gcd = sorted(gcd)
ans = 1
for i in gcd:
	P = []
	for j in A:
		x = j % i
		if x != 0:
			P.append([x, i - x])
	P = sorted(P)
	a = 0
	b = 0
	for j in range(len(P)):
		a += P[j][0]
	s = 0
	for j in range(len(P)):
		a -= P[-1 - j][0]
		b += P[-1 - j][1]
		s += P[-1 - j][1]
		if a == b:
			break
	if s <= K:
		ans = i
print(ans)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))

def divisor_all(n):
	l = [1, n]
	for i in range(2, int(pow(n, 1 / 2)) + 1):
		if n % i == 0:
			if i == n // i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	l.sort(reverse=True)
	return l
D = divisor_all(sum(A))

def accumulater1D(A):
	B = [0] * len(A)
	B[0] = A[0]
	for i in range(1, len(B)):
		B[i] = B[i - 1] + A[i]
	return B
import bisect
ans = 0
for d in D:
	R = [A[i] % d for i in range(N) if A[i] % d != 0]
	nr = len(R)
	R.sort()
	if len(R) == 0:
		ans = d
		break
	LR = accumulater1D(R)
	RR = list(reversed(accumulater1D([d - R[nr - 1 - i] for i in range(nr)])))
	for i in range(nr - 1):
		if LR[i] == RR[i + 1]:
			if LR[i] <= K:
				ans = d
				break
	if ans != 0:
		break
print(ans)


import math
(N, K) = map(int, input().split())
A = [int(x) for x in input().split()]
S = sum(A)
P = []
_P = []
for i in range(1, int(math.sqrt(S)) + 1):
	if S % i:
		continue
	P.append(S // i)
	_P.append(i)
P += _P[::-1]
for p in P:
	_A = sorted([a - p * (a // p) for a in A], reverse=True)
	n = sum(_A) // p
	if sum(_A) - sum(_A[:n]) <= K:
		print(p)
		break


import sys
input = sys.stdin.readline

def make_divisors(n):
	lsls = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			lsls.append(i)
			if i != n // i:
				lsls.append(n // i)
	lsls.sort()
	return lsls
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
lst = make_divisors(S)
ans = 1
B = [0] * N
for u in lst:
	for i in range(N):
		B[i] = A[i] % u
	B.sort()
	kkk = 0
	s = 0
	while kkk < N and s + B[kkk] <= K:
		s += B[kkk]
		kkk += 1
	t = 0
	for i in range(kkk, N):
		t += u - B[i]
	if s >= t:
		ans = u
print(ans)


(n, k, *l) = map(int, open(0).read().split())
s = sum(l)
L = []
for i in range(1, int(s ** 0.5) + 1):
	if s % i == 0:
		L += [i, s // i]
for d in sorted(L)[::-1]:
	a = sorted([m % d for m in l])
	if sum(a[:n - sum(a) // d]) <= k:
		print(d)
		exit()


import numpy as np
(N, K) = list(map(int, input().split()))
As_lis = list(map(int, input().split()))
As_arr = np.array(As_lis)
S = np.sum(As_arr)
smaller_factors = []
larger_factors = []
for i in range(1, int(S ** 0.5) + 1):
	if S % i == 0:
		smaller_factors.append(i)
		larger_factors.append(S // i)
for fac in larger_factors:
	mods = As_arr % fac
	k = np.sum(np.sort(mods)[:N - np.sum(mods) // fac])
	if k <= K:
		print(fac)
		return
for fac in reversed(smaller_factors):
	mods = As_arr % fac
	k = np.sum(np.sort(mods)[:N - np.sum(mods) // fac])
	if k <= K:
		print(fac)
		return


(N, K) = map(int, input().split())
A = [int(i) for i in input().split()]

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
lst = make_divisors(sum(A))
for l in lst:
	(cnt_m, cnt_p) = (0, 0)
	ml = sorted([i % l for i in A])
	for m in ml:
		if cnt_m <= K - m:
			cnt_m += m
		else:
			cnt_p += l - m
	if cnt_m <= K and cnt_p <= K:
		print(l)
		exit()
print(1)


import heapq

def divisor(i):
	s = []
	for j in range(1, int(i ** (1 / 2)) + 1):
		if i % j == 0:
			s.append(i // j)
			s.append(j)
	return sorted(set(s))
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
suma = sum(a)
s = divisor(suma)
for i in range(1, len(s) + 1):
	x = s[-i]
	y = suma // x
	h = []
	heapq.heapify(h)
	for j in a:
		y -= j // x
		heapq.heappush(h, -(j % x))
	cnt = 0
	for _ in range(y):
		cnt += heapq.heappop(h) % x
	if cnt <= k:
		print(x)
		return


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
all_sum = sum(A)
divisors = []
for i in range(1, all_sum + 1):
	if i * i > all_sum:
		break
	if all_sum % i != 0:
		continue
	divisors.append(i)
	if all_sum // i != i:
		divisors.append(all_sum // i)
divisors.sort(reverse=True)

def ok(d):
	a = [x % d for x in A]
	move = n - sum(a) // d
	a.sort()
	return sum(a[:move]) <= k
for d in divisors:
	if ok(d):
		print(d)
		break


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
(N, K) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
li = make_divisors(sum(A))
for i in li[::-1]:
	cnt = 0
	B = [x % i for x in A]
	B.sort(reverse=True)
	now_all = sum(B)
	for j in B:
		if now_all == 0:
			break
		if j != 0:
			cnt += i - j
			now_all -= i
	if cnt <= K:
		print(i)
		break


import sys
from itertools import accumulate
(N, K) = map(int, input().split())
(*A,) = map(int, input().split())
S = sum(A)
div_small = []
div_large = []
for p in range(1, int(S ** 0.5) + 1):
	if S % p == 0:
		div_small.append(p)
		if S // p != p:
			div_large.append(S // p)
div_large += div_small[::-1]
for d in div_large:
	R = sorted([a % d for a in A])
	SR = sum(R)
	acc = tuple(accumulate(R))
	for (i, l) in enumerate(acc):
		r = d * (N - i - 1) - (SR - l)
		if l == r:
			if l <= K:
				print(d)
				sys.exit()
			else:
				break


from heapq import heappush, heappop
(N, K) = map(int, input().split())
A = [int(i) for i in input().split()]
x = sum(A)
ls = []
for i in range(1, int(x ** 0.5) + 1):
	if x % i == 0:
		ls += [i]
		if i != x // i:
			ls += [x // i]
ls.sort(reverse=True)
for i in ls:
	B = []
	for j in A:
		heappush(B, -1 * (j % i))
	y = sum(B)
	while y < 0:
		u = heappop(B)
		u += i
		heappush(B, u)
		y += i
	m = 0
	for j in B:
		if j > 0:
			m += j
	if m > K:
		continue
	else:
		print(i)
		break


import sys
import math
input = sys.stdin.readline
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
L = []
for s in range(1, S + 1):
	if s > math.sqrt(S) + 1:
		break
	if S % s == 0:
		L.append(S // s)
		L.append(s)
L.sort(reverse=True)
for l in L:
	T = [a % l for a in A]
	T.sort()
	ans = False
	R = []
	r = 0
	for t in T:
		r += t
		R.append(r)
	for i in range(N):
		if R[i] > K:
			break
		if R[N - 1] == l * (N - i - 1):
			ans = True
			break
	if ans:
		print(l)
		break


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in make_divisors(sum(a)):
	x = [a[j] - a[j] // i * i for j in range(n)]
	x.sort(reverse=True)
	s = sum(x)
	compk = 0
	for j in range(n):
		if s == 0:
			break
		else:
			s -= i
			x[j] -= i
			compk += abs(x[j])
	if compk <= k:
		print(i)
		break


import sys
import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def ok(x):
	b = [i % x for i in a]
	b.sort(reverse=True)
	t = int(sum(b) / x)
	if t == 0:
		return True
	return True if sum(b[t:]) <= k else False
s = sum(a)
sqs = int(math.sqrt(s))
ans = 1
for x in range(1, sqs + 1):
	if s % x != 0:
		continue
	if ok(x):
		ans = max(ans, x)
	if ok(int(s / x)):
		ans = max(ans, int(s / x))
print(ans)


import sys
sys.setrecursionlimit(10 ** 6)

def int1(x):
	return int(x) - 1

def II():
	return int(input())

def MI():
	return list(map(int, input().split()))

def MI1():
	return list(map(int1, input().split()))

def LI():
	return list(map(int, input().split()))

def LI1():
	return list(map(int1, input().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return input().split()

def printlist(lst, k='\n'):
	print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush

def solve():
	(n, k) = MI()
	A = LI()
	sm = sum(A)
	div = []
	for i in range(1, int(pow(sm, 0.5)) + 1):
		if sm % i:
			continue
		div.append(i)
		if i != sm // i:
			div.append(sm // i)
	ans = 1
	for d in div:
		R = [a % d for a in A]
		R.sort()
		plus = 0
		minus = 0
		for r in R:
			plus += d - r
		for r in R:
			minus += r
			plus -= d - r
			if minus == plus and plus <= k:
				ans = max(ans, d)
	print(ans)

def __starting_point():
	solve()
__starting_point()


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
m = sum(a)
s = set()
i = 1
while i * i <= m:
	if m % i == 0:
		s |= set([i, m // i])
	i += 1
ans = 0
for i in s:
	b = [j % i for j in a]
	b.sort()
	c = [0]
	for j in b:
		c.append(c[-1] + j)
	d = [0]
	for j in reversed(b):
		d.append(d[-1] + (i - j))
	d = list(reversed(d))
	for j in range(n + 1):
		if (c[j] - d[j]) % i == 0:
			if max(c[j], d[j]) <= k:
				ans = max(ans, i)
print(ans)


def main():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	m = sum(A)
	d = []
	for i in range(1, int(m ** 0.5) + 1):
		if m % i == 0:
			d.append(i)
			if i != m // i:
				d.append(m // i)
	d.sort(reverse=True)
	for j in d:
		if j > K + max(A):
			continue
		l = []
		for i in A:
			l.append(i % j)
		t = N - sum(l) // j
		l.sort()
		if sum(l[:t]) <= K:
			print(j)
			return
	print(1)
main()


from math import sqrt
from bisect import bisect_left

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	sum_a = sum(a)
	st = set()
	for v in range(1, int(sqrt(sum_a)) + 2):
		if sum_a % v == 0:
			st.add(v)
			st.add(sum_a // v)
	st.remove(1)
	ans = 1
	for target in st:
		a_mod_t = [v % target for v in a]
		a_mod_t.sort()
		for i in range(n - 1):
			a_mod_t[i + 1] += a_mod_t[i]
		for i in range(n):
			(sum_L, sum_R) = (a_mod_t[i], a_mod_t[-1] - a_mod_t[i])
			(len_L, len_R) = (i + 1, n - i - 1)
			if sum_L == target * len_R - sum_R:
				if sum_L <= k:
					if ans < target:
						ans = target
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a_list = list(map(int, input().split()))
total = sum(a_list)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
div_list = make_divisors(total)
for div in div_list:
	b_list = [a % div for a in a_list]
	b_list.sort()
	change = sum(b_list[:-sum(b_list) // div])
	if change <= k:
		print(div)
		break


import math

def facts(n):
	sqrt_n = int(math.sqrt(n))
	fs = []
	fs_rev = []
	for i in range(1, sqrt_n + 1):
		if n % i == 0:
			fs.append(i)
			if n != i ** 2:
				fs_rev.append(n // i)
	fs.reverse()
	return fs_rev + fs
(n, k) = map(int, input().split())
ll = list(map(int, input().split()))
s = sum(ll)
fs = facts(s)
for f in fs:
	ll_f = list(map(lambda x: x % f, ll))
	ll_f.sort(reverse=True)
	ignore = sum(ll_f) // f
	keep = sum(ll_f[ignore:])
	if keep <= k:
		print(f)
		break


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors
input1 = input()
input2 = input()
N = int(input1.split()[0])
K = int(input1.split()[1])
nums = [int(s) for s in input2.split()]
divs = make_divisors(sum(nums))
possible = []
for i in divs:
	nord = [s % i for s in nums]
	nord.sort()
	mt_size = sum(nord) // i
	moves = sum(nord[0:N - mt_size])
	if moves <= K:
		possible.append(i)
print(int(max(possible)))


def main():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	total = sum(A)
	candidate = []
	for i in range(1, int(total ** 0.5) + 1):
		if not total % i:
			candidate.extend([i, total // i])
	ans = 0
	for c in candidate:
		d = sorted([a % c for a in A])
		j = N - sum(d) // c
		if sum(d[:j]) <= K:
			ans = max(ans, c)
	print(ans)
main()


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
L = make_divisors(S)
ans = 0
for i in L:
	D = []
	for a in A:
		if a % i != 0:
			D.append(a % i)
	D.sort()
	L1 = [0]
	L2 = [0]
	for j in range(len(D)):
		L1.append(L1[-1] + D[j])
		L2.append(L2[-1] + i - D[len(D) - 1 - j])
	L2.reverse()
	for j in range(len(D) + 1):
		if K >= max(L1[j], L2[j]):
			ans = max(ans, i)
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors
ans = 1
for div in make_divisors(sum(a)):
	mod_div = []
	for ai in a:
		mod_div.append(ai % div)
	mod_div.sort()
	tmp_p = n * div - sum(mod_div)
	tmp_m = 0
	for (i, x) in enumerate(mod_div):
		tmp_m += x
		tmp_p -= div - x
		if tmp_m == tmp_p and tmp_m <= k:
			ans = max(div, ans)
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
divisor = []
n = 1
while n * n <= s:
	(q, m) = divmod(s, n)
	if m == 0:
		divisor.append(n)
		divisor.append(q)
	n += 1
if n * n == s:
	divisor.pop()
ans = 1
for d in divisor:
	M = []
	for a in A:
		M.append(a % d)
	n = sum(M) // d
	M.sort(reverse=True)
	a = n * d - sum(M[:n])
	if a <= K:
		ans = max(ans, d)
print(ans)


import sys

def MI():
	return map(int, sys.stdin.readline().rstrip().split())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))
(N, K) = MI()
A = LI()
s = sum(A)
divisor = []
for i in range(1, int(s ** 0.5) + 1):
	if s % i == 0:
		divisor.append(i)
		if i != s // i:
			divisor.append(s // i)
divisor.sort(reverse=True)
from itertools import accumulate
for d in divisor:
	B = [a % d for a in A if a % d != 0]
	B.sort()
	C = [0] + list(accumulate(B))
	D = [0] + list(accumulate([d - b for b in B]))
	r = 10 ** 10
	for i in range(len(C)):
		r = min(r, max(C[i], D[-1] - D[i]))
	if r <= K:
		print(d)
		break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def ok(d):
	m = sorted((a % d for a in a))
	(s, e, plus, minus) = (0, len(m) - 1, 0, 0)
	while True:
		if s > e:
			return plus == minus
		if plus <= minus:
			plus += m[s]
			if plus > k:
				return False
			s += 1
		else:
			minus += d - m[e]
			if minus > k:
				return False
			e -= 1
	return False
b = sum(a)
ret = 1
d = 1
while d * d <= b:
	if b % d == 0:
		if ok(d):
			ret = max(ret, d)
		if ok(b // d):
			ret = max(ret, b // d)
	d += 1
print(ret)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = sum(a)

def divisor(n):
	ass = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ass.append(i)
			ass.append(n // i)
	return ass
f = divisor(m)
f.sort(reverse=True)
for p in f:
	b = [x % p for x in a]
	b.sort()
	t = 0
	c = n
	for x in b:
		if x + t > k:
			break
		t += x
		c -= 1
	if c * p - sum(b) + t <= k:
		print(p)
		break


import sys
import numpy as np
sr = lambda : sys.stdin.readline().rstrip()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
(N, K) = lr()
A = np.array(lr())
total = A.sum()
D = make_divisors(total)
for d in D:
	B = A % d
	B.sort()
	inc = d - B
	B_cum = B.cumsum()
	inc_cum = inc.cumsum()
	for i in range(N):
		x = B_cum[i]
		y = inc_cum[N - 1] - inc_cum[i]
		if x > K or y > K:
			continue
		if (x + y) // 2 <= K:
			print(d)
			return


def divi(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			if i != n // i:
				res.append(n // i)
	return res
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
SA = sum(A)
D = divi(SA)
D.sort(reverse=True)
ans = 0
for d in D:
	P = []
	for a in A:
		P.append(-(-a // d) * d - a)
	P.sort()
	ups = sum(P)
	if ups <= K:
		ans = d
		break
	ss = ups
	for i in range(1, N + 1):
		ss -= P.pop()
		if max(ss, i * d - ups + ss) <= K:
			ans = d
			break
	else:
		continue
	break
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)
divisors = []
for i in range(1, int(sumA ** 0.5) + 1):
	if sumA % i == 0:
		divisors.append(i)
		if i != sumA // i:
			divisors.append(sumA // i)
ans = 0
for i in divisors:
	listA = [0] * N
	for j in range(N):
		listA[j] = A[j] % i
	listA.sort()
	sumlist = sum(listA)
	if sum(listA[:-sumlist // i]) <= K:
		ans = max(ans, i)
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
m = sum(A)
ans = 0
for i in range(1, int(m ** 0.5) + 1):
	if m % i != 0:
		continue
	for j in [i, m // i]:
		stg = []
		for a in A:
			stg.append(a % j)
		stg.sort()
		(sm, idx) = (0, 0)
		flag = False
		while sm + stg[idx] <= K:
			sm += stg[idx]
			idx += 1
			if idx >= N:
				flag = True
				break
		if flag or sum([j - x for x in stg[idx:]]) <= K:
			ans = max(ans, j)
print(ans)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
Asum = sum(A)
div = set()
for i in range(1, int(Asum ** 0.5 + 0.5) + 1):
	if Asum % i == 0:
		div.add(i)
		div.add(Asum // i)
ans = 1
for d in div:
	R = [a % d for a in A]
	R.sort()
	r = sum(R) // d
	l = N - r
	need = sum(R[:l])
	if need <= K:
		ans = max(ans, d)
print(ans)


import math

def main():
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	s = sum(A)
	D1 = []
	D2 = []
	for i in range(1, int(math.sqrt(s)) + 1):
		if s % i == 0:
			D1.append(s // i)
			D2.append(i)
	for d in D1 + list(reversed(D2)):
		B = sorted([a % d for a in A])
		x = sum(B[:-sum(B) // d])
		if x <= K:
			print(d)
			return
main()


import numpy as np

def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
asum = sum(a)
adiv = make_divisors(asum)
adiv.reverse()
a = np.array(a)
ans = 1
flg = False
for i in adiv:
	a_ = np.sort(a % i)
	msum = a_.sum()
	msum_ = 0
	for j in range(-1, -n - 1, -1):
		msum -= a_[j]
		msum_ += i - a_[j]
		if msum_ > k:
			break
		if msum < msum_:
			break
		if msum == msum_:
			ans = i
			flg = True
			break
	if flg:
		break
print(ans)


def all_divisor(n):
	small = [1]
	large = [n]
	for i in range(2, int(n ** 0.5) + 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	large.reverse()
	divisor = small + large
	return divisor
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum_a = sum(a)
divisor = all_divisor(sum_a)
ans = 1
for i in reversed(divisor):
	t = 0
	b = []
	d = 0
	for j in a:
		b.append(j % i)
	c = sum(b)
	b.sort()
	for x in reversed(b):
		c -= x
		d += i - x
		if c == d:
			if c <= k:
				print(i)
				exit()
print(ans)


import numpy as np

def make_divisors(n):
	divisors = set()
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.add(i)
			divisors.add(n // i)
	return sorted(list(divisors))
(N, K, *A) = map(int, open(0).read().split())
A = np.array(A, np.int64)
d = make_divisors(A.sum())
for i in d[::-1]:
	r = A % i
	r = r[r != 0]
	l = r.size
	if l == 0:
		print(i)
		return
	else:
		n = np.arange(l - 1, 0, -1)
	r.sort()
	np.cumsum(r, out=r)
	equal = np.where(r[:-1] == i * n - (r[-1] - r[:-1]))[0]
	if np.any(r[equal] <= K):
		print(i)
		return


(n, k) = [int(j) for j in input().split()]
a = [int(j) for j in input().split()]
s = sum(a)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
l = make_divisors(s)
ans = 1
from itertools import accumulate
for i in l[::-1]:
	ll = []
	for j in a:
		ll.append(j % i)
	ll.sort()
	if sum(ll[:n - sum(ll) // i]) <= k:
		print(i)
		exit()


import sys
import numpy as np
input = sys.stdin.readline

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors

def main():
	(n, k) = map(int, input().split())
	a = np.array([int(x) for x in input().split()])
	key = make_divisors(np.sum(a))
	for v in key:
		mod = np.sort(a % v)
		(c1, c2) = (0, np.sum(mod))
		judge = c2
		for i in range(n - 1, -1, -1):
			c1 += v - mod[i]
			c2 -= mod[i]
			judge = min(judge, max(c1, c2))
		if judge <= k:
			print(v)
			return

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
s = sum(a)
divisors = make_divisors(s)
for d in divisors:
	reminders = [ai % d for ai in a]
	reminders.sort()
	for i in range(n - sum(reminders) // d, n):
		reminders[i] -= d
	se = sum((abs(r) for r in reminders))
	if se <= 2 * k:
		print(d)
		break


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
divs = make_divisors(sumA)
for i in divs:
	mod = []
	for j in range(N):
		mod.append(A[j] % i)
	mod.sort(reverse=True)
	tmp = sum(mod) // i
	tmp = tmp * i - sum(mod[:tmp])
	if tmp <= K:
		ans = i
		break
print(ans)


(n, K) = map(int, input().split())
d_ = []
a = [int(i) for i in input().split()]
S = sum(a)
i = 1
while i * i <= S:
	if S % i == 0:
		d_.append(i)
		d_.append(S // i)
	i += 1
d_.sort()
for d in d_[::-1]:
	b = []
	B = 0
	for i in range(n):
		b.append(a[i] - d * (a[i] // d))
		B += b[-1]
	b.sort()
	flag = False
	for k in range(n + 1):
		if sum(b[0:k]) <= min(K, K + B - d * (n - k)):
			flag = True
			break
	if flag:
		break
print(d)


def factors(n):
	a = [1, n]
	x = 2
	while x * x <= n:
		if n % x == 0:
			a.append(x)
			c = n // x
			while (c + 1) * x <= n:
				c += 1
			a.append(c)
		x += 1
	return a
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
candidates = factors(sum(a))
candidates.sort()
candidates.reverse()
for i in candidates:
	b = []
	for j in range(n):
		b.append(a[j] % i)
	b.sort()
	upsum = 0
	downsum = 0
	for j in range(n):
		upsum += i - b[j]
	for j in range(n):
		upsum -= i - b[j]
		downsum += b[j]
		if upsum <= downsum:
			break
	if upsum <= k:
		print(i)
		break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sun = sum(a)
cd = []
rcd = []
for i in range(1, int(sun ** 0.5) + 1):
	if sun % i == 0:
		cd.append(i)
		rcd.append(sun // i)
rcd.reverse()
if cd[-1] == rcd[0]:
	del cd[-1]
gcd = cd + rcd
gcd.reverse()
count = -1
while True:
	count += 1
	g = gcd[count]
	b = list(map(lambda x: x % g, a))
	moon = sum(b)
	luna = moon // g
	b.sort()
	score = sum(b[:n - luna])
	if score <= k:
		print(g)
		break


def divisor(n):
	ass = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ass.append(i)
			if i != n // i:
				ass.append(n // i)
	return ass
(_, k) = map(int, input().split())
a = list(map(int, input().split()))
for ans in sorted(divisor(sum(a)))[::-1]:
	b = [i % ans for i in a if i % ans]
	n = len(b)
	b.sort()
	m = [0] + [i for i in b]
	p = [ans - i for i in b] + [0]
	for i in range(n):
		m[i + 1] += m[i]
		p[-i - 2] += p[-i - 1]
	flag = False
	for i in range(n + 1):
		if max(m[i], p[i]) > k:
			continue
		if abs(m[i] - p[i]) % ans != 0:
			continue
		flag = True
	if flag:
		print(ans)
		exit()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a_sum = sum(a)
rt_sm = int(a_sum ** (1 / 2) + 0.01)
fct = []
fct2 = []
for p in range(1, rt_sm + 1):
	if a_sum % p == 0:
		fct.append(p)
		fct2.append(a_sum // p)
if fct[-1] == fct2[-1]:
	fct.pop()
fct += fct2
fct.sort(reverse=True)
for f in fct:
	tmp = []
	for t in a:
		tmp.append(t % f)
	tmp_sum = sum(tmp)
	cnt = 0
	sb = tmp_sum // f
	tmp.sort()
	for i in range(n - sb, n):
		tmp[i] -= f
	if sum(tmp[:n - sb]) <= k:
		ans = f
		break
print(ans)


import numpy as np

def getDivisor(n):
	divisor = []
	tmp = n
	for i in range(2, int(n ** 0.5) + 1):
		cnt = 1
		d = [1]
		while tmp % i == 0:
			d.append(i ** cnt)
			tmp //= i
			cnt += 1
		if cnt > 1:
			divisor.append(d)
	if tmp != 1:
		divisor.append([1, tmp])
	if divisor == []:
		divisor.append([1, n])
	divisor_mat = np.matrix(1)
	for d in divisor:
		d = np.matrix(d)
		mat = []
		for dcol in divisor_mat:
			mat.append(dcol.T * d)
		divisor_mat = np.concatenate(mat)
	divisor_mat = np.array(divisor_mat.flatten())
	divisor_mat = np.array(divisor_mat[0].tolist())
	divisor_mat.sort()
	return divisor_mat
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = np.array(a)
sum_a = a.sum()
divisor = getDivisor(sum_a)
for d in divisor[::-1]:
	tmp = a % d
	idx = tmp.sum() // d
	tmp.sort()
	num_op = tmp[:-idx].sum()
	if num_op <= k:
		break
print(d)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)
divisors = []
for i in range(1, sumA + 1):
	if i * i > sumA:
		break
	if sumA % i != 0:
		continue
	divisors.append(i)
	if sumA // i != i:
		divisors.append(sumA // i)
divisors.sort(reverse=True)
ans = 0
for d in divisors:
	costs = [a % d for a in A]
	costs.sort(reverse=True)
	plus = sum(costs)
	minus = 0
	for j in range(N):
		if plus == minus:
			break
		else:
			plus -= costs[j]
			minus += d - costs[j]
	if plus <= K:
		print(d)
		break


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sa = sum(A)
m = 1
divs = set()
while m * m <= sa:
	if sa % m == 0:
		divs.add(m)
		divs.add(sa // m)
	m += 1
for d in sorted(divs, reverse=True):
	mods = []
	for a in A:
		mods.append(a % d)
	mods.sort()
	if all((m == 0 for m in mods)):
		print(d)
		exit()
	cump = [0]
	for m in mods:
		cump.append(cump[-1] + m)
	cumm = [0]
	for m in reversed(mods):
		cumm.append(cumm[-1] + (d - m))
	for i in range(1, N):
		if cump[i] == cumm[N - i] and cump[i] <= K:
			print(d)
			exit()


def factor(N):
	arr = []
	for i in range(1, int(N ** 0.5) + 1):
		if N % i == 0:
			arr.append(i)
			if N // i != i:
				arr.append(N // i)
	return arr
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum_ = sum(a)
fac = sorted(factor(sum_), reverse=True)
ans = 1
for x in fac:
	li = sorted((z % x for z in a))
	res = 0
	cum = [0] * (n + 1)
	for i in range(n):
		cum[i + 1] = cum[i] + li[i]
	for i in range(1, n):
		(l, r) = (cum[i], x * (n - i) - (cum[n] - cum[i]))
		if l == r and r <= k:
			ans = max(ans, x)
print(ans)


def make_divisors(n: int) -> list:
	divisors = []
	for k in range(1, int(n ** 0.5) + 1):
		if n % k == 0:
			divisors.append(k)
			if k != n // k:
				divisors.append(n // k)
	divisors = sorted(divisors)
	return divisors

def solve(val):
	res = []
	for i in range(n):
		tmp = a[i] % val
		if tmp == 0:
			continue
		res.append(a[i] % val)
	res = sorted(res)
	if not res:
		return True
	l_val = 0
	for i in range(len(res)):
		l_val += res[i]
		if l_val > k:
			l_pos = i - 1
			break
	else:
		return True
	r_val = 0
	for i in range(l_pos + 1, len(res)):
		r_val += val - res[i]
	return r_val <= k
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum_a = sum(a)
div = make_divisors(sum_a)
ans = 0
for i in div:
	if solve(i):
		ans = max(ans, i)
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
x = sum(l)

def f(m, k, l):
	l = [i % m for i in l]
	l.sort()
	if sum(l[:n - sum(l) // m]) <= k:
		return True
ans = 1
for i in range(1, int(x ** 0.5) + 1):
	if x % i:
		continue
	if f(x // i, k, l):
		print(x // i)
		break
	elif f(i, k, l):
		ans = i
else:
	print(ans)


from math import sqrt

def Divisor_Set(n):
	s = set()
	for i in range(1, int(sqrt(n)) + 2):
		if n % i == 0:
			s.add(i)
			s.add(n // i)
	return s

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a_sum = sum(a)
	s = Divisor_Set(a_sum)
	ans = 1
	for v in s:
		a_mod = [x % v for x in a]
		a_mod.sort()
		for i in range(1, n):
			a_mod[i] += a_mod[i - 1]
		for i in range(n):
			(l, r) = (a_mod[i], v * (n - i - 1) - (a_mod[-1] - a_mod[i]))
			if l == r and r <= k:
				if ans < v:
					ans = v
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)

def md(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
P = md(s)

def test(x):
	L = sorted([a % x for a in A])
	M = sum(L)
	c = M // x
	for _ in range(c):
		M -= L.pop()
	return M <= k
for p in P:
	if test(p):
		print(p)
		break


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
div = make_divisors(sum(a))
for x in div:
	aa = [ai % x for ai in a]
	aa.sort()
	ss = aa[:len(aa) - sum(aa) // x]
	s = sum(ss)
	if 0 <= s <= k:
		print(x)
		break


(N, K) = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

def yaku(N):
	res = []
	for i in range(1, round(N ** (1 / 2)) + 3):
		if N % i == 0:
			res.append(i)
	res2 = [N // i for i in res]
	res = list(set(res + res2))
	return res
ys = yaku(sum(A))
ys.sort(reverse=True)
for y in ys:
	M = [a % y for a in A if a % y]
	ma = 0
	mi = y * len(M) - sum(M)
	M.sort()
	for m in M:
		ma += m
		mi -= y - m
		if ma == mi:
			break
	if ma <= K:
		print(y)
		exit()


INF = float('inf')
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))

def get_divisors(num):
	(f_divs, l_divs) = ([], [])
	for i in range(1, int(num ** 0.5) + 1):
		if not num % i:
			f_divs.append(i)
			if i != num // i:
				l_divs.append(num // i)
	return f_divs + l_divs[::-1]
divs = get_divisors(sum(a))
ans = 1

def evl(d):
	rem = [x % d for x in a]
	rem.sort()
	s = sum(rem)
	c = 0
	for (i, x) in enumerate(rem):
		c += x
		if c == d * (n - i - 1) - (s - c):
			return c <= k
	return False
for d in divs[::-1]:
	if evl(d):
		print(d)
		break


import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
asum = sum(a)
gcdmax = int(math.sqrt(asum))
li = []
for i in range(2, gcdmax + 1):
	if asum % i == 0:
		li.append(i)
for i in range(gcdmax, 0, -1):
	if asum % i == 0:
		li.append(asum // i)
ans = 1
for i in li:
	b = [a[ii] % i for ii in range(n)]
	b.sort()
	l = 0
	r = 0
	x = 0
	y = n - 1
	while x <= y:
		if r >= l:
			l += b[x]
			x += 1
		else:
			r += i - b[y]
			y -= 1
	if max(l, r) <= k and (l - r) % i == 0:
		ans = i
print(ans)


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
l = []

def check(b):
	r1 = [x % b for x in a]
	r1.sort()
	s1 = sum(r1)
	mn = 1000000000.0
	s2 = 0
	for i in range(n):
		s2 += r1[i]
		mn = min(max(s2, (n - 1 - i) * b - (s1 - s2)), mn)
	if mn <= k:
		print(int(b))
		sys.exit(0)
for p in range(1, int((s + 1) ** 0.5 + 1)):
	if s % p != 0:
		continue
	b = s // p
	l.append(b)
	check(b)
l.reverse()
for p in l:
	b = s // p
	check(b)


from collections import deque

def isok(x):
	que = deque(sorted((z % x for z in a)))
	res = 0
	while que:
		l = que[0]
		if l == 0:
			que.popleft()
			continue
		r = que[-1]
		if r == 0:
			que.pop()
			continue
		d = min(l, x - r)
		que[0] -= d
		que[-1] = (que[-1] + d) % x
		res += d
	return res
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum_ = sum(a)
fac = set()
for i in range(1, sum_ + 1):
	if i * i > sum_:
		break
	if sum_ % i == 0:
		fac.add(i)
		fac.add(sum_ // i)
fac = sorted(fac, reverse=True)
ans = 1
for x in fac:
	c = isok(x)
	if c <= k:
		ans = x
		break
print(ans)


from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():

	def ok(f):
		bb = [a % f for a in aa]
		bb.sort()
		(i, j) = (0, n - 1)
		s = t = 0
		while i <= j:
			if s > t:
				t += f - bb[j]
				j -= 1
			else:
				s += bb[i]
				i += 1
		return s <= k
	(n, k) = MI()
	aa = LI()
	s = sum(aa)
	ff = []
	for d in range(1, s + 1):
		if d ** 2 > s:
			break
		if s % d == 0:
			ff.append(d)
			ff.append(s // d)
	if ff[-1] == ff[-2]:
		ff.pop()
	ff.sort(reverse=True)
	for f in ff:
		if ok(f):
			print(f)
			break
main()


from itertools import accumulate
(N, K, *A) = map(int, open(0).read().split())

def check(d):
	r = sorted([v % d for v in A])
	r_inv = [d - v for v in r]
	r_cs = [0] + list(accumulate(r))
	r_inv_cs = list(accumulate(r_inv[::-1]))[::-1] + [0]
	ret = False
	for i in range(N + 1):
		flg1 = r_cs[i] <= K
		flg2 = r_cs[i] == r_inv_cs[i]
		ret = flg1 and flg2 or ret
	return ret
M = sum(A)
ans = 0
for i in reversed(range(1, int(M ** 0.5) + 1)):
	if M % i == 0 and check(i):
		ans = max(ans, i)
	if M % (M // i) == 0 and check(M // i):
		ans = max(ans, M // i)
print(ans)


(N, K) = map(int, input().split())
a_list = list(map(int, input().split()))
total_a = sum(a_list)
candidates = set()
for i in range(1, total_a):
	if i * i > total_a:
		break
	if total_a % i == 0:
		candidates.add(i)
		candidates.add(total_a // i)
ans = 1
for x in candidates:
	remainders = sorted(map(lambda a: a % x, a_list))
	total_r = sum(remainders)
	border = total_r // x
	need = sum(remainders[:N - border])
	if need <= K:
		ans = max(ans, x)
print(ans)


def divisors(N):
	U = int(N ** 0.5) + 1
	L = [i for i in range(1, U) if N % i == 0]
	return L + [N // i for i in reversed(L) if N != i * i]
(N, K, *A) = map(int, open(0).read().split())
for d in reversed(divisors(sum(A))):
	R = sorted((a % d for a in A))
	if sum(R[:-sum(R) // d]) <= K:
		print(d)
		quit()


import numpy as np

def divisor(x):
	div = []
	for i in range(1, int(x ** 0.5) + 1):
		if x % i == 0:
			div.append(i)
			if x != i ** 2:
				div.append(x // i)
	return div

def mincount(a, x):
	minus = np.sort(a % x)
	adj_sum = minus.sum()
	convert = adj_sum // x
	return adj_sum - minus[-convert:].sum()
(N, K) = map(int, input().split())
A = np.array(list(map(int, input().split())))
div = divisor(A.sum())
div.sort(reverse=True)
for d in div:
	if mincount(A, d) <= K:
		print(d)
		break


def divisible(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
(N, K) = map(int, input().split())
xs = list(map(int, input().split()))
divs = divisible(sum(xs))
for div in divs:
	test = [x % div for x in xs]
	test.sort()
	sum_test = sum(test)
	change = sum(test[:-sum_test // div])
	if change <= K:
		ans = div
		break
print(ans)


def yakusu(n):
	results = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			results.append(i)
			results.append(n // i)
	return results
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in yakusu(sum(A)):
	M = sorted(map(lambda x: [x % i, (i - x % i) % i], A), key=lambda x: x[0])
	s = sum(map(lambda x: x[1], M))
	sm = 0
	for (j, (m, m2)) in enumerate(M):
		sm += m
		s -= m2
		if sm == s and s <= K:
			ans = max(ans, i)
print(ans)


import math

def dprint(*args):
	pass
(N, K) = [int(x) for x in input().split()]
As = [int(x) for x in input().split()]
S = sum(As)
Ds = []
for i in range(1, 1 + int(math.sqrt(S))):
	if S % i == 0:
		Ds.append(i)
		Ds.append(S // i)
Ds = sorted(set(Ds))
for d in Ds[::-1]:
	if d == 1:
		print(1)
		exit()
	dprint(d)
	rs = []
	for a in As:
		rs.append(a % d)
	rs = sorted(rs)
	dprint(rs)
	total = sum(rs)
	n = total // d
	num = 0
	for i in range(N - n, N):
		rs[i] -= d
		num -= rs[i]
	dprint(rs)
	dprint(num)
	if num <= K:
		print(d)
		exit()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors
div = make_divisors(sum(A))
ans = 0
for g in div:
	near = [0] * N
	S = 0
	for i in range(N):
		near[i] = a = A[i] % g
		S += near[i]
	near.sort()
	ii = 0
	while S != 0:
		S -= g
		ii -= 1
	temp = sum(near[:ii])
	if temp <= K:
		ans = max(ans, g)
print(ans)


import heapq as h

def partions(M):
	import math
	d = []
	i = 1
	while math.sqrt(M) >= i:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	d.sort()
	return d
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
candidate = partions(s)
ans = 1
for i in range(0, len(candidate)):
	X = [A[j] % candidate[i] for j in range(0, N)]
	s = sum(X) // candidate[i]
	test = 0
	h.heapify(X)
	for j in range(0, N - s):
		test = h.heappop(X)
	test = candidate[i] * s - sum(X)
	if K >= test:
		ans = candidate[i]
print(ans)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
s = sum(A)

def solve():
	ans = 1
	idx = 1
	while idx * idx <= s:
		if s % idx == 0:
			if ok(s // idx):
				return s // idx
			if ok(idx):
				ans = idx
		idx += 1
	return ans

def ok(i):
	D = list([x for x in [a % i for a in A] if x != 0])
	D.sort()
	l = len(D)
	S = [0] * (l + 1)
	for j in range(l):
		S[j + 1] = S[j] + D[j]
	for j in range(l):
		if S[j] == i * (l - j) - (S[l] - S[j]) and S[j] <= K:
			return True
	return False
print(solve())


import numpy as np

def divisors(num):
	array = []
	limit = int(num ** 0.5) + 1
	for i in range(1, limit):
		if num % i == 0:
			div1 = i
			div2 = num // i
			array.append(div1)
			if div1 != div2:
				array.append(div2)
	array.sort(reverse=True)
	return array
(n, k) = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=int)
total = sum(A)
candidates = divisors(total)
for div in candidates:
	mods = A % div
	mods.sort()
	np.cumsum(mods, out=mods)
	idx = mods[n - 1] // div
	count = mods[-1 - idx]
	if count <= k:
		print(div)
		return


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
candidate = set()
result = 0
x = 1
while x ** 2 <= sum(a) + 1:
	if sum(a) % x == 0:
		candidate.add(x)
		candidate.add(int(sum(a) / x))
	x += 1
for i in candidate:
	b = [0] * len(a)
	for j in range(len(a)):
		b[j] = int(a[j] % i)
	b.sort()
	if sum(b[:int(len(b) - sum(b) / i)]) <= k:
		result = max(result, i)
print(result)


(n, k) = map(int, input().split())
an = list(map(int, input().split()))
sa = sum(an)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
div = make_divisors(sa)
for d in div[::-1]:
	if d == 1:
		print(1)
		break
	bn = [a % d for a in an if a % d != 0]
	bn.sort()
	sb = sum(bn)
	sb_l = sum(bn[:-1 * (sb // d)])
	if sb_l <= k:
		print(d)
		break


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = 1
A = sum(a)
l = []
for i in range(1, int(A ** (1 / 2)) + 1):
	if A % i != 0:
		continue
	l.append(i)
	if A // i != i:
		l.append(A // i)
for i in l:
	x = [0] * n
	for j in range(n):
		x[j] = a[j] % i
	s = sum(x)
	l = 0
	x.sort(reverse=True)
	for j in range(n):
		if s <= k and l <= k:
			if (s - l) % i == 0:
				if i > cnt:
					cnt = i
				break
		l += i - x[j]
		s -= x[j]
print(cnt)


(n, k) = map(int, input().split())
l = tuple(map(int, input().split()))
a = sum(l)
ans = 1

def f(i):
	p = []
	for j in l:
		r = j % i
		if r:
			p.append(r)
	p.sort()
	a = i * len(p) - sum(p)
	now = 0
	for j in p:
		now += j
		a -= i - j
		if now <= k and a <= k and (abs(now - a) % i == 0):
			return i
	return 0
from math import floor, sqrt
for i in range(1, floor(sqrt(a)) + 1):
	if a % i == 0:
		ans = max(f(i), ans, f(a // i))
print(ans)


import sys

def solve():
	input = sys.stdin.readline
	(N, K) = map(int, input().split())
	A = [int(a) for a in input().split()]
	sumA = sum(A)
	D = []
	for i in range(1, sumA + 1):
		if i ** 2 > sumA:
			break
		if sumA % i == 0:
			D.append(i)
			if i ** 2 != sumA:
				D.append(sumA // i)
	D.sort(reverse=True)
	for (i, d) in enumerate(D):
		L = []
		count = 0
		for a in A:
			if a % d > 0:
				L.append(a % d)
				count += 1
		L.sort()
		if count > 0:
			(minus, plus) = ([0] * count, [0] * count)
			minus[0] = L[0]
			plus[count - 1] = d - L[count - 1]
			for i in range(1, count):
				minus[i] = minus[i - 1] + L[i]
				plus[count - 1 - i] = plus[count - i] + d - L[count - 1 - i]
			Op = K + 1
			for i in range(count - 1):
				if abs(minus[i] - plus[i + 1]) % d == 0:
					Op = min(Op, max(minus[i], plus[i + 1]))
			if Op <= K:
				print(d)
				break
	else:
		print(1)
	return 0

def __starting_point():
	solve()
__starting_point()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)

def isOk(n):
	B = [a % n for a in A]
	B.sort()
	now = 0
	S = sum(B)
	for (i, b) in enumerate(B[:-1]):
		now += b
		S -= b
		if now == n * (N - i - 1) - S and now <= K:
			return True
	return False
ans = 1
for i in range(1, int(S ** 0.5) + 100):
	if S % i != 0:
		continue
	j = S // i
	if isOk(i):
		ans = max(ans, i)
	if isOk(j):
		ans = max(ans, j)
print(ans)


import sys

def main():
	(n, k) = map(int, input().split())
	alist = list(map(int, input().split()))
	suma = sum(alist)
	i = 1
	yaku = []
	while i * i <= suma:
		if suma % i == 0:
			yaku.append(i)
			if suma // i != i:
				yaku.append(suma // i)
		i += 1
	for d in sorted(yaku, key=lambda x: -x):
		rem = [a % d for a in alist]
		rem = list(sorted(rem))
		sumr = d * len(rem) - sum(rem)
		kc = 0
		for _r in rem:
			kc += _r
			sumr = sumr - (d - _r)
			if max(kc, sumr) <= k:
				print(d)
				sys.exit(0)
main()


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
dl = []
k = 1
while k ** 2 <= s:
	if s % k == 0:
		dl.append(k)
		dl.append(s // k)
	k += 1
cand = []
for d in dl:
	op = 0
	b = [n % d for n in a]
	b.sort()
	b.reverse()
	summod = sum(b)
	for i in range(summod // d):
		op += d - b[i]
	if op <= K:
		cand.append(d)
print(max(cand))


import numpy as np

def divisors(num):
	array = []
	limit = int(num ** 0.5) + 1
	for i in range(1, limit):
		if num % i == 0:
			div1 = i
			div2 = num // i
			array.append(div1)
			if div1 != div2:
				array.append(div2)
	array.sort(reverse=True)
	return array
(n, k) = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=int)
total = sum(A)
candidates = divisors(total)
for div in candidates:
	mods = A % div
	mods.sort()
	add = div - mods
	addcum = np.cumsum(add)
	subcum = np.cumsum(mods)
	for i in range(n):
		addcount = addcum[n - 1] - addcum[i]
		subcount = subcum[i]
		if addcount == subcount and addcount <= k:
			print(div)
			return


import sys
input = sys.stdin.buffer.readline

def divisors(n) -> list:
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			if i != n // i:
				res.append(n // i)
	res = sorted(res)[::-1]
	return res
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
div = divisors(sum(A))
for d in div:
	arr = []
	for a in A:
		if a % d != 0:
			arr.append(d - a % d)
		else:
			arr.append(0)
	arr = sorted(arr)[::-1]
	tmp = sum(arr[sum(arr) // d:])
	if tmp <= K:
		print(d)
		exit()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))

def divisors(n: int) -> dict:
	divs = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divs.append(i)
			if i != n // i:
				divs.append(n // i)
	return divs

def solve(B, f):
	cost = sum(B)
	cost = sum(B[:-cost // f])
	return cost
fct = divisors(sum(A))
for f in sorted(fct, reverse=True):
	B = sorted([b % f for b in A])
	cost = solve(B, f)
	if K >= cost:
		print(f)
		quit()


def get_divisors(n):
	divisors = set()
	i = 1
	while i * i <= n:
		if n % i == 0:
			divisors.add(i)
			divisors.add(n // i)
		i += 1
	return divisors
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
divisor = list(get_divisors(s))
divisor.sort(reverse=True)
for d in divisor:
	r = list(map(lambda x: x % d, a))
	r.sort()
	left = r[:]
	right = [0] * n
	right[-1] = r[-1] - d
	for i in range(1, n):
		left[i] += left[i - 1]
		right[n - i - 1] = right[n - i] + r[n - i - 1] - d
	for i in range(n - 1):
		if left[i] == -right[i + 1] and left[i] <= k:
			print(d)
			quit()
print(1)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)
now = 1
yaku = []
while True:
	if now ** 2 > sumA:
		break
	if sumA % now == 0:
		yaku.append(now)
		yaku.append(sumA // now)
	now += 1
yaku.sort()
nowK = 0
nowX = 0
flag = True
ans = 0
for i in yaku:
	nowK = 0
	nowX = 0
	flag = True
	nlis = []
	for a in A:
		nowK += a % i
		nlis.append(a % i)
	nlis.sort()
	nlis.reverse()
	for j in range(nowK // i):
		nowX += i - nlis[j]
	if nowX > K:
		flag = False
	if flag:
		ans = max(ans, i)
print(ans)


(N, K) = map(int, input().split())
(*A,) = map(int, input().split())
A.sort()

def chk(x):
	D = []
	c = 0
	for a in A:
		y = a % x
		D.append(y)
	D.sort()
	s = sum(D)
	e = 0
	r = N * x - s
	for d in D:
		e += d
		r -= x - d
		if e == r and e <= K:
			return 1
	return 0
ans = 1
S = sum(A)
for x in range(1, int(S ** 0.5) + 1):
	if S % x == 0:
		if chk(x):
			ans = max(ans, x)
		if chk(S // x):
			ans = max(ans, S // x)
print(ans)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
add = sum(arr)

def check(factor):
	mod_factor = [x % factor for x in arr]
	mod_factor.sort(reverse=True)
	p = sum(mod_factor) // factor
	c = sum((factor - mod_factor[i] for i in range(p)))
	return c <= k
ans = i = 1
while i * i <= add:
	if add % i == 0:
		if check(i):
			ans = max(ans, i)
		if check(add // i):
			ans = max(ans, add // i)
	i += 1
print(ans)


import copy
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
fact = []
for i in range(1, int(sum(a) ** 0.5) + 1):
	if sum(a) % i == 0:
		fact.append(i)
		fact.append(sum(a) // i)
fact = list(set(fact))
fact.sort()
fact.reverse()
a.sort()
a.reverse()
for i in range(len(fact)):
	a2 = copy.copy(a)
	for j in range(n):
		a2[j] %= fact[i]
	a2.sort()
	a2.reverse()
	ct = 0
	for m in range(sum(a2) // fact[i]):
		ct += a2[m]
	if sum(a2) - ct <= k:
		print(fact[i])
		break


from itertools import accumulate
(N, K) = map(int, input().split())
A = list(map(int, input().split()))

def f(d):
	B = sorted((a % d for a in A))
	C = [d - b for b in B]
	X = list(accumulate(B))
	Y = list(accumulate(C))
	return any((X[j] == Y[-1] - Y[j] <= K for j in range(N)))
S = sum(A)
ans = max((S // d if f(S // d) else d if f(d) else 0 for d in range(1, int(S ** 0.5) + 2) if S % d == 0))
print(ans)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
S = sum(A)

def canMake(n):
	B = [a % n for a in A]
	B.sort()
	left = 0
	right = sum(B)
	for (i, b) in enumerate(B, start=1):
		left += b
		right -= b
		if left == n * (N - i) - right:
			return left <= K
	return False
ans = 1
for i in range(1, int(S ** 0.5) + 100):
	if S % i != 0:
		continue
	k = S // i
	if canMake(i):
		ans = max(ans, i)
	if canMake(k):
		ans = max(ans, k)
		break
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
sumA = sum(A)
candiate = []
tmp = 1
while tmp * tmp <= sumA:
	if sumA % tmp == 0:
		candiate.append(tmp)
		candiate.append(sumA // tmp)
	tmp += 1

def f(x):
	A.sort(key=lambda z: z % x)
	tmp = 0
	judge = True
	for a in A:
		if tmp + a % x <= K and judge:
			tmp += a % x
		else:
			judge = False
			tmp -= x - a % x
		if tmp < 0:
			return False
	return True
ans = -1
for cand in candiate:
	if f(cand):
		ans = max(ans, cand)
print(ans)


(n, k, *l) = map(int, open(0).read().split())

def f(n):
	d = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			d += [i]
			if i != n // i:
				d += [n // i]
	d.sort()
	return d[::-1]
for d in f(sum(l)):
	a = sorted([m % d for m in l])
	if sum(a[:n - sum(a) // d]) <= k:
		print(d)
		exit()


import math
(N, K) = map(int, input().split())
A_s = list(map(int, input().split()))
S = sum(A_s)
divs = []
for i in range(1, round(math.sqrt(S) + 1)):
	if S % i == 0:
		divs.append(i)
		divs.append(S // i)
answer = 1
for div in divs:
	r_s = []
	for A in A_s:
		r_s.append(A % div)
	r_s.sort()
	if sum(r_s[:-sum(r_s) // div]) <= K and answer < div:
		answer = div
print(answer)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
divs = []
maxA = sum(A)
for i in range(1, int(maxA ** 0.5) + 1):
	if maxA % i == 0:
		divs.append(i)
		divs.append(maxA // i)
divs.sort(reverse=True)
for d in divs:
	rest = [a % d for a in A]
	rest.sort(reverse=True)
	restSum = sum(rest) // d
	cnt = 0
	for i in range(restSum):
		cnt += d - rest[i]
	if cnt <= K:
		print(d)
		exit()


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
S = sum(A)
ans = 1
div = []
for i in range(1, int(S ** 0.5) + 2):
	if S % i == 0:
		if S // i != i:
			div.append(S // i)
			div.append(i)
		else:
			div.append(i)
div.sort()
L = []
for i in range(len(div)):
	cur = div[i]
	mod = []
	for j in range(n):
		if A[j] % cur != 0:
			mod.append(A[j] % cur)
	if len(mod) == 0:
		ans = max(ans, cur)
	else:
		mod.sort()
		mod_dash = []
		for j in range(len(mod)):
			mod_dash.append(cur - mod[j])
		mod2 = [mod[0]]
		mod3 = [mod_dash[0]]
		for j in range(1, len(mod)):
			t = mod2[j - 1] + mod[j]
			mod2.append(t)
			u = mod3[j - 1] + mod_dash[j]
			mod3.append(u)
		c = 10 ** 10
		for j in range(1, len(mod2)):
			c = min(c, max(mod2[len(mod2) - j - 1], mod3[len(mod3) - 1] - mod3[len(mod3) - j - 1]))
		if c <= k:
			ans = max(ans, cur)
print(ans)


def divisors(n):
	div = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			div.append(i)
			if i ** 2 != n:
				div.append(n // i)
	div.sort()
	return div
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = divisors(sum(a))
d.reverse()
for x in d:
	b = []
	for i in range(n):
		b.append(x - a[i] % x)
	b.sort()
	c = sum(b) // x
	if sum(b[:-c]) <= k:
		print(x)
		exit()


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
S = []
for i in range(1, int(s ** 0.5) + 1):
	if s % i == 0:
		S.append(i)
		if i != s // i:
			S.append(s // i)
S.sort(reverse=True)
for s in S:
	A.sort(key=lambda x: x % s)
	tmp = 0
	judge = True
	for a in A:
		if tmp + a % s <= k and judge:
			tmp += a % s
		else:
			judge = False
			tmp -= s - a % s
		if tmp < 0:
			break
	if tmp >= 0:
		print(s)
		exit()


def divisor(n):
	res = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			res.append(i)
			if i * i != n:
				res.append(n // i)
		i += 1
	res.sort()
	return res
(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
S = sum(A)
ans = 1
for d in divisor(S):
	rs = [a % d for a in A]
	rs.sort()
	Sum = [0] * (N + 1)
	Sum2 = [0] * (N + 1)
	for i in range(1, N + 1):
		Sum[i] = Sum[i - 1] + rs[i - 1]
		Sum2[i] = Sum2[i - 1] + (d - rs[i - 1])
	for i in range(N + 1):
		if Sum[i] == Sum2[N] - Sum2[i]:
			if Sum[i] <= K:
				ans = d
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
ans = 0
for i in range(1, int(S ** 0.5) + 1):
	if S % i != 0:
		continue
	for j in range(2):
		d = i if j else S // i
		B = sorted(map(lambda a: a % d, A))
		C = [0]
		for k in range(N):
			C.append(C[-1] + B[k])
		for k in range(N + 1):
			if ((N - k) * d - (C[-1] - C[k]) - C[k]) % d == 0:
				if max(C[k], (N - k) * d - (C[-1] - C[k])) <= K:
					ans = max(ans, d)
print(ans)


def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
sum_A = sum(A)
div_list = make_divisors(sum_A)
ans = 1
for div in div_list:
	tmp = []
	for a in A:
		tmp.append(a % div)
	tmp.sort()
	cumsum1 = [0]
	cumsum2 = [0]
	for i in tmp:
		cumsum1.append(cumsum1[-1] + i)
		if i != 0:
			cumsum2.append(cumsum2[-1] + (div - i))
		else:
			cumsum2.append(cumsum2[-1])
	for i in range(1, N):
		if cumsum1[i] <= K and cumsum2[N] - cumsum2[i] <= K:
			ans = div
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
from itertools import accumulate

def check(n):
	L = [None] * N
	for i in range(N):
		L[i] = (A[i] % n, n - A[i] % n)
	L.sort(key=lambda x: x[0])
	acc1 = list(accumulate([L[i][0] for i in range(N)]))
	acc2 = list(accumulate([L[i][1] for i in range(N)]))
	for i in range(N):
		if acc1[i] <= K and acc2[N - 1] - acc2[i] <= K:
			return True
	return False
mx = -1
import math
for i in range(math.floor(math.sqrt(S)), 0, -1):
	if S % i == 0:
		if check(i):
			mx = max(i, mx)
		if check(S // i):
			mx = max(S // i, mx)
print(mx)


from itertools import accumulate

def divisors(n):
	lst = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			lst.append(i)
			if i != n // i:
				lst.append(n // i)
	return lst
(N, K) = map(int, input().split())
(*A,) = map(int, input().split())
cands = divisors(sum(A))
for d in sorted(cands, reverse=True):
	rems = sorted([a % d for a in A])
	cumsum_rems = [0] + list(accumulate(rems))
	for i in range(1, N):
		minus = cumsum_rems[i]
		plus = d * (N - i) - (cumsum_rems[N] - minus)
		if max(minus, plus) <= K:
			break
	else:
		continue
	break
print(d)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = sum(a)
r = set()
r.add(t)
for i in range(2, int(t ** 0.5) + 2):
	if t % i == 0:
		r.add(i)
		r.add(t // i)
ans = 1
for i in r:
	f = [x % i for x in a]
	f.sort()
	if sum(f[:-sum(f) // i]) <= k:
		ans = max(ans, i)
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sm = sum(a)
div = []
for i in range(1, int(sm ** 0.5) + 1):
	if sm % i == 0:
		div.append(i)
		if i != sm // i:
			div.append(sm // i)
div.sort()
answer = 1
for _ in range(len(div)):
	ans = div.pop()
	b = sorted(list(map(lambda x: x % ans, a)))
	lenb = len(b)
	l = 0
	r = ans * len(b) - sum(b)
	for i in range(lenb):
		l += b[i]
		r -= ans - b[i]
		if l <= k and l >= r and ((l - r) % 2 == 0):
			print(ans)
			exit()


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
L = [int(v) for v in input().split()]
L.sort()
s = sum(L)
d = set()
for i in range(1, int(s ** 0.5) + 1):
	if s % i == 0:
		d.add(i)
		d.add(s // i)
d = list(d)
d.sort(reverse=True)
ans = 1
for n in d:
	p = [v % n for v in L]
	p.sort()
	pc = n * N - sum(p)
	mc = 0
	for v in p:
		pc -= n - v
		mc += v
		if pc == mc:
			break
	if pc <= M:
		ans = max(ans, n)
print(ans)


(N, K) = map(int, input().split())
AL = list(map(int, input().split()))
summ = 0
for i in range(N):
	summ += AL[i]
candidate = set()
for i in range(1, int(summ ** 0.5) + 1):
	if summ % i == 0:
		candidate.add(i)
		candidate.add(summ / i)
ans = 0
for x in candidate:
	need = 0
	r = [0] * N
	for i in range(N):
		r[i] = AL[i] % x
	r.sort()
	rsum = 0
	for i in range(N):
		rsum = rsum + r[i]
	rindex = int(rsum / x)
	lindex = N - int(rsum / x)
	for i in range(lindex):
		need += r[i]
	if need <= K:
		ans = max(ans, x)
print(int(ans))


def div(n):
	ret = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ret.append(i)
			if i != n // i:
				ret.append(n // i)
	return ret
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
s = sum(arr)
ans = 1
d = div(s)
for val in d:
	arr = sorted(arr, key=lambda x: x % val)
	parr = []
	narr = []
	for num in arr:
		narr.append(num % val)
		parr.append(val - num % val)
	for i in range(n - 1):
		parr[i + 1] += parr[i]
		narr[i + 1] += narr[i]
	for i in range(n - 1):
		ncnt = narr[i]
		pcnt = parr[-1] - parr[i]
		if ncnt != pcnt:
			continue
		elif pcnt <= k:
			ans = max(ans, val)
print(ans)


from itertools import accumulate
(N, K, *A) = map(int, open(0).read().split())
s = sum(A)
divisor = []
for i in range(1, int(s ** 0.5) + 1):
	if s % i == 0:
		divisor.append(i)
		if i != s // i:
			divisor.append(s // i)
ans = 0
for d in divisor:
	x = sorted((v % d for v in A))
	y = [d - r for r in x]
	x_s = [0] + list(accumulate(x))
	y_s = list(accumulate(y[::-1]))[::-1] + [0]
	for i in range(N + 1):
		if x_s[i] <= K and x_s[i] == y_s[i]:
			ans = max(ans, d)
			break
print(ans)


from collections import defaultdict, deque
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
x = []
for i in range(1, s + 1):
	if i * i > s:
		break
	if s % i == 0:
		x.append(i)
		x.append(s // i)
ans = 0
for xi in x:
	b = []
	for i in range(n):
		if a[i] % xi != 0:
			b.append(a[i] % xi)
	b.sort()
	b = deque(b)
	c = 0
	r = 0
	while b:
		q = b.pop() + r
		while q < xi:
			p = b.popleft()
			q += p
			c += p
		r = q - xi
	if c <= k:
		ans = max(ans, xi)
print(ans)


from math import sqrt

def Divisor_Set(n):
	s = set()
	for i in range(1, int(sqrt(n)) + 2):
		if n % i == 0:
			s.add(i)
			s.add(n // i)
	return s

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a_sum = sum(a)
	st = Divisor_Set(a_sum)
	ans = 1
	st.remove(1)
	for v in st:
		b = [x % v for x in a]
		b.sort()
		for i in range(n - 1):
			b[i + 1] += b[i]
		for i in range(n - 1):
			if b[i] == v * (n - i - 1) - (b[-1] - b[i]):
				if b[i] <= k and ans < v:
					ans = v
	print(ans)
main()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
S_div = make_divisors(S)
mod = []
for _ in range(N):
	mod.append(0)
ans = 1
for i in range(1, len(S_div)):
	for j in range(N):
		mod[j] = A[j] % S_div[i]
	group = sum(mod) // S_div[i]
	mod.sort(reverse=True)
	Ktmp = S_div[i] * group - sum(mod[:group])
	if Ktmp <= K:
		ans = max(ans, S_div[i])
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a_sum = sum(a)

def devisor(x):
	lst = []
	i = 1
	y = x
	while i ** 2 <= y:
		if x % i == 0:
			lst.append(i)
			if i != x // i:
				lst.append(x // i)
		i += 1
	lst.sort()
	return lst
re = devisor(a_sum)
re.sort(reverse=True)
for u in re:
	w = []
	for v in a:
		w.append(v % u)
	w.sort()
	b = sum(w)
	count = 0
	for i in range(b // u):
		w[-i - 1] -= u
	for i in w:
		if i >= 0:
			count += i
		else:
			break
	if count <= k:
		print(u)
		break


import itertools
(n, k) = map(int, input().split())
A = [int(i) for i in input().split()]

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
divlis = make_divisors(sum(A))
for res in divlis:
	tmp = [i % res for i in A]
	tmp.sort()
	tmp_l = [0] + list(itertools.accumulate(tmp))
	tmp_r = [0] * (n + 1)
	for i in range(n - 1, -1, -1):
		tmp_r[i] = tmp_r[i + 1] + res - tmp[i]
	for i in range(n + 1):
		if tmp_l[i] == tmp_r[i] and tmp_l[i] <= k:
			print(res)
			exit()


def max2(x, y):
	return x if x > y else y

def divisors(n):
	i = 1
	table = set()
	while i * i <= n:
		if not n % i:
			table.add(i)
			table.add(n // i)
		i += 1
	table = list(table)
	return table
import numpy as np
import sys
input = sys.stdin.readline
(N, K) = map(int, input().split())
A = np.array(list(map(int, input().split())))
S = sum(A)
D = divisors(S)
D.sort()
res = 0
for k in D:
	B = A % k
	B.sort()
	cnt = sum(B) // k
	if k * cnt - sum(B[-cnt:]) <= K:
		res = max2(res, k)
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
m = sum(a)
cd = set(())
for i in range(1, int(m ** 0.5) + 2):
	if m % i == 0:
		cd.add(i)
		cd.add(m // i)
cd = list(cd)
cd.sort(reverse=True)

def func(x):
	r = [ai % x for ai in a]
	r.sort()
	tmp = 0
	sr = [0]
	for ri in r:
		tmp += ri
		sr.append(tmp)
	for i in range(n + 1):
		tmp0 = sr[i]
		tmp1 = (n - i) * x - (sr[-1] - sr[i])
		if tmp0 == tmp1 and tmp0 <= k:
			return True
	return False
for x in cd:
	if x == 1:
		print(1)
		return
	if func(x):
		print(x)
		return


def make_divisor_list(n):
	result = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			result.append(i)
			result.append(n // i)
	return result

def calc_min_ops(r, d):
	(i, j) = (0, len(r))
	while i < j and r[i] == 0:
		i += 1
	i -= 1
	(a, b) = (0, 0)
	while j - i != 1:
		if a <= b:
			i += 1
			a += r[i]
		else:
			j -= 1
			b += d - r[j]
	return a
(N, K, *A) = list(map(int, open(0).read().split()))
c = sum(A)
divisors = make_divisor_list(c)
divisors.sort(reverse=True)
r = [None] * N
for d in divisors:
	for i in range(N):
		r[i] = A[i] % d
	r.sort()
	if calc_min_ops(r, d) <= K:
		print(d)
		break


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors

def checker(A, k):
	A.sort(reverse=True)
	if sum(A[sum(A) // d:]) <= k:
		return True
	return False
(n, k) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
for d in make_divisors(sum(A)):
	buf = []
	for a in A:
		buf.append(a % d)
	if checker(buf, k):
		print(d)
		break


(n, k, *a) = map(int, open(0).read().split())
(s, m) = (sum(a), 1)
for i in sum([[s // i, i] for i in range(1, int(s ** 0.5) + 1) if s % i < 1], []):
	p = [0] + sorted((j % i for j in a))
	for j in range(n):
		p[j + 1] += p[j]
	f = t = 0
	for j in range(n):
		f |= t == p[~j] <= k
		t += i - p[~j] + p[-j - 2]
	m = max(m, i * f)
print(m)


import sys
sys.setrecursionlimit(10 ** 9)

def int1(x):
	return int(x) - 1

def II():
	return int(input())

def MI():
	return list(map(int, input().split()))

def MI1():
	return list(map(int1, input().split()))

def LI():
	return list(map(int, input().split()))

def LI1():
	return list(map(int1, input().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def MS():
	return input().split()

def LS():
	return list(input())

def LLS(rows_number):
	return [LS() for _ in range(rows_number)]

def printlist(lst, k=' '):
	print(k.join(list(map(str, lst))))
INF = float('inf')
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations

def solve():
	(N, K) = MI()
	A = LI()
	M = sum(A)
	divs = []
	for i in range(1, int(pow(M, 0.5)) + 1):
		if M % i:
			continue
		divs.append(i)
		if i != M // i:
			divs.append(M // i)
	divs.sort(reverse=True)
	for d in divs:
		B = list([x % d for x in A])
		B.sort()
		C = list([d - x for x in B])
		Ba = list(accumulate(B))
		Ca = list(accumulate(C))
		for i in range(0, N - 1):
			b = Ba[i]
			c = Ca[-1] - Ca[i]
			if b == c and b <= K:
				print(d)
				return
	print(1)

def __starting_point():
	solve()
__starting_point()


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
sA = sum(A)
div_list = []
for i in range(1, int(sA ** 0.5) + 1):
	if sA % i == 0:
		if i != sA ** 0.5:
			div_list.append(i)
			div_list.append(sA // i)
		else:
			div_list.append(i)
div_list.sort(reverse=True)
for d in div_list:
	count = 0
	count_list = []
	l = 0
	for a in A:
		n = a % d
		if n != 0:
			l += 1
			count += n
			count_list.append(n)
	if count % d == 0:
		if count // d < l:
			count_list.sort()
			if sum(count_list[:l - count // d]) <= K:
				break
print(d)


from itertools import accumulate
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
M = sum(A)
ans_candidates = []
for n in range(1, int(M ** 0.5) + 1):
	if M % n == 0:
		ans_candidates.append(n)
		ans_candidates.append(M // n)
ans = 0
for X in ans_candidates:
	need_plus = sorted([(X - a % X) % X for a in A])
	need_minus = [X - nm for nm in need_plus]
	need_plus = list(accumulate(need_plus))
	need_minus = list(accumulate(need_minus))
	for i in range(N):
		if need_plus[i] > K:
			break
		if need_plus[i] == need_minus[-1] - need_minus[i]:
			ans = max(ans, X)
			break
print(ans)


import sys
readline = sys.stdin.readline
(N, K) = map(int, readline().split())
A = list(map(int, readline().split()))
all = sum(A)
divisors = []
for i in range(1, int(all ** 0.5) + 1):
	if all % i == 0:
		divisors.append(i)
		divisors.append(all // i)
divisors = sorted(divisors, reverse=True)
for d in divisors:
	mods = [0] * N
	for i in range(len(A)):
		mods[i] = A[i] % d
	mods = sorted(mods)
	mods_front = [0] * N
	mods_front[0] = mods[0]
	for i in range(1, N):
		mods_front[i] = mods_front[i - 1] + mods[i]
	mods_back = [0] * N
	mods_back[-1] = d - mods[-1]
	for i in range(N - 2, -1, -1):
		mods_back[i] = mods_back[i + 1] + (d - mods[i])
	for i in range(N - 1):
		if mods_front[i] == mods_back[i + 1]:
			if K >= mods_front[i]:
				print(d)
				return
else:
	print(1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import time, random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	(n, k) = LI()
	a = LI()
	s = sum(a)
	dv = set([1, s])
	for i in range(2, int(s ** 0.5) + 5):
		if s % i == 0:
			dv.add(i)
			dv.add(s // i)

	def f(i):
		pm = []
		for c in a:
			t = c % i
			if t == 0:
				continue
			pm.append((i - t, t))
		pm.sort()
		p = pi = m = 0
		mi = len(pm) - 1
		while pi <= mi:
			if p < m:
				p += pm[pi][0]
				pi += 1
			else:
				m += pm[mi][1]
				mi -= 1
		return max(p, m) <= k
	r = 1
	for c in dv:
		if f(c):
			if r < c:
				r = c
	return r
print(main())


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
Asum = sum(A)
div = set()
for i in range(1, int(Asum ** 0.5 + 0.5) + 1):
	if Asum % i == 0:
		div.add(i)
		div.add(Asum // i)
ans = 1
for d in div:
	now = 10 ** 18
	R = [a % d for a in A]
	R.sort()
	Rsum = sum((d - r for r in R))
	Lsum = 0
	for r in R:
		Lsum += r
		Rsum -= d - r
		now = min(now, max(Lsum, Rsum))
	if now <= K:
		ans = max(ans, d)
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
max_div = int(S ** 0.5)
small_div = []
large_div = []
for i in range(1, max_div + 1):
	if S % i == 0:
		small_div.append(i)
		large_div.append(S // i)
div = large_div + small_div[::-1]
ans = 1
for d in div:
	r = []
	for a in A:
		r.append(a % d)
	r.sort()
	minus = [0] * (N + 1)
	plus = [0] * (N + 1)
	for (i, ri) in enumerate(r, 1):
		minus[i] = minus[i - 1] + ri
	for (i, ri) in enumerate(r[::-1], 1):
		plus[i] = plus[i - 1] + (d - ri)
	plus = plus[::-1]
	for (m, p) in zip(minus, plus):
		if m == p and m <= K:
			ans = d
			break
	else:
		continue
	break
print(ans)


def divisible(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
divs = divisible(sum(arr))
for div in divs:
	test_arr = [x % div for x in arr]
	test_arr.sort()
	sum_test_arr = sum(test_arr)
	change = sum(test_arr[:-sum_test_arr // div])
	if change <= k:
		print(div)
		exit()


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return sorted(divisors, reverse=True)
(n, k) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
divisors = make_divisors(sum(A))
for divisor in divisors:
	remainders = sorted(map(lambda x: x % divisor, A))
	idx = n - sum(remainders) // divisor
	ope_num = sum(remainders[:idx])
	if ope_num <= k:
		print(divisor)
		break


def divisors(n):
	i = 1
	table = set()
	while i * i <= n:
		if not n % i:
			table.add(i)
			table.add(n // i)
		i += 1
	table = list(table)
	return table

def binary_search_int(ok, ng, test):
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if test(mid):
			ok = mid
		else:
			ng = mid
	return ok
import numpy as np
import sys
input = sys.stdin.readline
(N, K) = map(int, input().split())
A = np.array(list(map(int, input().split())))
S = sum(A)
D = divisors(S)
D.sort()

def test(x):
	k = D[x]
	B = A % k
	B.sort()
	cnt = sum(B) // k
	return k * cnt - sum(B[-cnt:]) <= K
p = binary_search_int(0, len(D), test)
q = binary_search_int(p + 1, len(D), test)
print(max(D[p], D[q]) if q != p + 1 else D[p])


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
ans = 1
C = []
for i in range(1, int(S ** 0.5 + 1)):
	if S % i == 0:
		C.append(i)
		C.append(S // i)
for c in C:
	B = []
	for i in A:
		B.append(i % c)
	B.sort()
	hoge = 0
	sum_b = sum(B)
	for i in range(N):
		hoge += B[i]
		sum_b -= B[i]
		if hoge <= K and hoge == c * (N - i - 1) - sum_b:
			ans = max(ans, c)
print(ans)


def divisor(n):
	ans = [1, n]
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			ans.append(i)
			if i ** 2 < n:
				ans.append(n // i)
		i += 1
	ans.sort()
	return ans
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
d_max = sum(A)
div = divisor(d_max)[::-1]
for ans in div:
	b = [a % ans for a in A]
	b.sort()
	s = sum(b)
	if sum(b[:-s // ans]) <= k:
		print(ans)
		exit()


(N, K) = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
sum_A = sum(A)
d_candidate = make_divisors(sum_A)
for d in d_candidate:
	R = [a % d for a in A]
	R.sort()
	sum_R = sum(R)
	(X, mod) = divmod(sum_R, d)
	if mod != 0:
		continue
	if sum(R[:N - X]) <= K and X * d - sum(R[-X:]) <= K:
		print(d)
		break


(n, k, *l) = map(int, open(0).read().split())
s = sum(l)
L = []
for i in range(1, 30000):
	L += [i, s // i] * (s % i < 1)
t = 1
for d in L:
	a = sorted([m % d for m in l])
	t = max(t, d * (sum(a[:-sum(a) // d]) <= k))
print(t)


(N, K) = list(map(int, input().split()))
As = list(map(int, input().split()))
rs = []
a = sum(As)
for i in range(a):
	i += 1
	if a % i == 0:
		rs.append(i)
		rs.append(a // i)
	if a < i ** 2:
		break
rs = sorted(rs)[::-1]
for r in rs:
	Bs = sorted([A % r for A in As])
	sum1 = 0
	sum2 = r * N - sum(Bs)
	R = None
	for b in Bs:
		sum1 += b
		sum2 -= r - b
		if abs(sum1 - sum2) % r == 0:
			if max(sum1, sum2) > K:
				continue
			R = r
			break
	if R:
		break
print(R)


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

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

def isPrime(x):
	if x < 2 or x % 2 == 0:
		return False
	if x == 2:
		return True
	i = 3
	while i * i <= x:
		if x % i == 0:
			return False
		i += 2
	return True

def divisor(x):
	res = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			res.append(i)
			if i * i != x:
				res.append(x // i)
		i += 1
	res = sorted(res)
	return res

def factor(x):
	res = []
	if x == 1:
		res.push_back(1)
		return res
	i = 2
	while i * i <= x:
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	res = sorted(res)
	return res

def __starting_point():
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A = sorted(A)
	sum_v = sum(A)
	div = divisor(sum_v)
	div = sorted(div, reverse=True)
	for e in div:
		ok = True
		b = [int(a % e) for a in A]
		b = sorted(b)
		v = sum(b)
		v //= e
		ans = 0
		for i in range(N - v):
			ans += b[i]
		if ans <= K:
			print(e)
			return
__starting_point()


from math import sqrt
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
div = []
for i in range(1, int(sqrt(s) + 1)):
	if s % i == 0:
		if i * i != s:
			div.append(s // i)
		div.append(i)
div.sort(reverse=True)
for d in div:
	b = [x % d for x in a if x % d != 0]
	if not b:
		print(d)
		break
	b.sort(key=lambda x: x % d)
	(y, z) = (0, d * len(b) - sum(b))
	res = 10 ** 30
	for x in b:
		y += x
		z -= d - x
		res = min(res, max(y, z))
	if res <= k:
		print(d)
		break


import heapq
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
x = sum(a)
search = []
i = 1
while i ** 2 <= x:
	if x % i == 0:
		heapq.heappush(search, -i)
		heapq.heappush(search, -x // i)
	i += 1
while search:
	ans = -heapq.heappop(search)
	u = [a[i] % ans for i in range(n)]
	u.sort()
	plus = [0]
	minus = [0]
	for i in range(n):
		plus.append(plus[-1] + ans - u[i])
		minus.append(minus[-1] + u[i])
	for i in reversed(list(range(n + 1))):
		m = minus[i]
		p = plus[-1] - plus[i]
		if m == p and m <= k:
			print(ans)
			return


def make_divs(n):
	divs = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divs.append(i)
			if i != n // i:
				divs.append(n // i)
	return divs
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
divs = make_divs(S)
ans = 0
for d in divs:
	B = [Ai % d for Ai in A]
	B.sort()
	(l, r) = (0, N - 1)
	cnt = 0
	while l != r:
		t = min(B[l], d - B[r])
		B[l] -= t
		B[r] += t
		cnt += t
		if B[l] == 0:
			l += 1
		else:
			r -= 1
	if cnt <= K:
		ans = max(ans, d)
print(ans)


def yakusu(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
(N, K) = map(int, input().split())
L = list(map(int, input().split()))
a = sum(L)
R = yakusu(a)[::-1]
for i in range(len(R)):
	add = 0
	minus = 0
	s = R[i]
	A = list()
	B = list()
	for j in range(N):
		k = L[j]
		a = k % s
		b = s - a
		if a > b:
			add += b
			B.append(b)
		elif a < b:
			minus += a
			A.append(a)
		else:
			add += a
			B.append(a)
	A = sorted(A)
	B = sorted(B)
	if minus == add:
		d = minus
		if d <= K:
			print(s)
			return
	elif minus > add:
		q = (minus - add) // s
		d = sum(A[:len(A) - q])
		if d <= K:
			print(s)
			return
	else:
		q = (add - minus) // s
		d = sum(B[:len(B) - q])
		if d <= K:
			print(s)
			return


import math
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
x = sum(A)
X = []
for i in range(1, int(math.sqrt(x)) + 1):
	if x % i == 0:
		X.append(i)
		X.append(x // i)
X.sort(reverse=True)
for i in X:
	B = []
	for j in range(n):
		B.append(A[j] % i)
	B.sort()
	if sum(B[:-1 * (sum(B) // i)]) <= k:
		print(i)
		break


import math
(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
li = []
num = sum(lis)
for i in range(1, math.ceil(math.sqrt(num)) + 1):
	if num % i == 0:
		li.append(i)
		li.append(num // i)
li.sort(reverse=True)
for numb in li:
	liss = []
	for i in lis:
		if i % numb == 0:
			liss.append(numb)
		else:
			liss.append(i % numb)
	liss.sort(reverse=True)
	co = 0
	numm = sum(liss)
	for i in range(numm // numb):
		co += numb - liss[i]
	if co <= k:
		print(numb)
		exit()


import math
(N, K) = map(int, input().split(' '))
As = list(map(int, input().split(' ')))
S = sum(As)
l = []
i = 1
ans = 1
while i * i <= S:
	if S % i == 0:
		l.append(i)
		l.append(S // i)
	i += 1
l.sort(reverse=True)
for i in l:
	ext = 0
	exts = []
	for j in As:
		exts.append(j % i)
		ext += j % i
	if ext % i != 0:
		continue
	else:
		p = 0
		exts.sort()
		cnt = ext // i
		for k in range(0, N - cnt):
			p += exts[k]
		if p <= K:
			ans = i
			break
print(ans)


def main():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	sA = sum(A)
	divs = []
	i = 1
	while i * i < sA:
		if sA % i == 0:
			divs.append(i)
			divs.append(sA // i)
		i += 1
	if i * i == sA:
		divs.append(i)
	divs.sort()
	for d in reversed(divs):
		t = [i % d for i in A]
		t.sort()
		k = sum(t[:-sum(t) // d])
		if k <= K:
			return d
print(main())


def divisors(N):
	return sorted(sum((list({n, N // n}) for n in range(1, int(N ** 0.5) + 1) if not N % n), []), reverse=True)
(N, K) = map(int, input().split())
A = tuple(map(int, input().split()))
D = divisors(sum(A))
for d in D:
	L = sorted((a % d for a in A))
	if not sum(L):
		print(d)
		break
	(left, right) = (0, N - 1)
	count = 0
	while left < right:
		if L[left] + L[right] <= d:
			next_right = right - (L[right] + L[left] == d)
			next_left = left + 1
			L[right] += L[left]
			count += L[left]
			L[left] = 0
		else:
			next_left = left
			next_right = right - 1
			m = d - L[right]
			count += m
			L[right] += m
			L[left] -= m
		(left, right) = (next_left, next_right)
	if count <= K:
		print(d)
		break


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors

def main():
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	asum = sum(a)
	divs = make_divisors(asum)
	ans = 1
	for d in divs:
		r = sorted([aa % d for aa in a])
		j = n - 1 - sum(r) // d
		if sum(r[:j + 1]) <= k:
			ans = max(ans, d)
	print(ans)
main()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))

def divisor(n):
	d0 = []
	d1 = []
	for i in range(1, int(n ** 0.5) + 1):
		(x, y) = divmod(n, i)
		if y == 0:
			d0.append(i)
			d1.append(x)
	if d1[-1] == d0[-1]:
		d1 = d1[:-1]
	return d0 + d1[::-1]
D = divisor(sum(A))
r = 1
for d in D[::-1]:
	x = sorted([a % d for a in A])
	for i in range(len(A) - 1):
		x[i + 1] += x[i]
	if x[-1] % d == 0 and x[-1 - x[-1] // d] <= K:
		r = d
		break
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
ii = []
for i in range(1, int(s ** 0.5) + 1):
	if s % i > 0:
		continue
	ii += [i, s // i]
ii.sort(reverse=True)
for i in ii:
	r = []
	for j in range(n):
		r += [a[j] % i]
	r.sort()
	b = 0
	l = 0
	while l < n and b + r[l] <= k:
		b += r[l]
		l += 1
	if sum([i - x for x in r[l:]]) <= k:
		print(i)
		break


def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	sum_a = sum(a)
	anskoho = []
	for i in range(1, int(sum_a ** 0.5) + 1):
		if sum_a % i == 0:
			anskoho += [i, sum_a // i]
	anskoho.sort(reverse=True)
	for i in anskoho:
		a_sub = [j % i for j in a]
		a_sub.sort()
		(sum_L, sum_R) = (sum(a_sub), 0)
		sakai = n - 1
		while sum_L != sum_R:
			sum_L -= a_sub[sakai]
			sum_R += i - a_sub[sakai]
			sakai -= 1
		if sum_L <= k:
			print(i)
			break
main()


(N, K) = map(int, input().split())
(*A,) = map(int, input().split())
A.sort()
S = sum(A)
candidates = []
for i in range(1, int(S ** 0.5) + 1):
	if S % i:
		continue
	(a, b) = (i, S // i)
	candidates.append(a)
	if a != b:
		candidates.append(b)
candidates.sort()
ans = 0
for d in candidates:
	rems = []
	(rems_size, rems_sum) = (0, 0)
	for i in A:
		if i % d:
			rems.append(i % d)
			rems_size += 1
			rems_sum += i % d
	rems.sort()
	a = 0
	for (i, j) in enumerate(rems[:-1], start=1):
		a += j
		b = d * (rems_size - i) - (rems_sum - a)
		if max(a, b) <= K:
			ans = max(ans, d)
	if not rems:
		ans = max(ans, d)
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
cands = []
for x in range(1, int(s ** 0.5) + 1):
	if s % x == 0:
		cands.append(x)
		if x != s // x:
			cands.append(s // x)
cands.sort(reverse=True)
ans = 0
for cand in cands:
	b = [a[i] % cand for i in range(n)]
	b.sort()
	sb = [0 for _ in range(n + 1)]
	for i in range(n):
		sb[i + 1] = sb[i] + b[i]
	flg = False
	for i in range(n + 1):
		x = max(sb[i], cand * (n - i) - (sb[n] - sb[i]))
		if x <= k:
			flg = True
			break
	if flg:
		print(cand)
		break


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
G = make_divisors(s)
from itertools import accumulate
for g in G:
	B = [a % g for a in A]
	B.sort()
	B = [0] + B
	B = list(accumulate(B))
	p = 0
	q = 0
	for i in range(n - 1):
		p = B[i + 1]
		q = g * (n - 1 - i) - (B[-1] - B[i + 1])
		if max(p, q) <= k and (p - q) % g == 0:
			break
	else:
		continue
	break
print(g)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = sum(l)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
d = make_divisors(s)
ans = 0
for i in d:
	m = [0] * n
	for j in range(n):
		m[j] = l[j] % i
	m.sort()
	sm = sum(m)
	sl = 0
	for p in range(n):
		sl += m[p]
		sr = sm - sl
		if sl <= k and (n - p - 1) * i - sr <= k and (sl == (n - p - 1) * i - sr):
			ans = i
			break
print(ans)


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
s = sum(A)
import math

def yakusu(n):
	ans_local = set()
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			ans_local = ans_local | set([i, n // i])
	return list(ans_local)
yaku = sorted(yakusu(s), reverse=1)
for mod in yaku:
	B = [i % mod for i in A if i % mod != 0]
	if B == []:
		print(mod)
		return
	if len(B) == 1:
		q = B[0]
		if 0 <= q <= k or mod - k <= q:
			print(mod)
			return
		else:
			continue
	B.sort()
	r = [B[0]] * len(B)
	for i in range(len(B) - 1):
		r[i + 1] = r[i] + B[i + 1]
	now = float('INF')
	for i in range(1, len(B)):
		if r[i - 1] == mod * (len(B) - i) - (r[-1] - r[i - 1]) and r[i - 1] <= k:
			print(mod)
			return


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
INF = 10 ** 6 * 500
M = sum(A)

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
T = make_divisors(M)
ans = INF
for t in T:
	p = []
	for a in A:
		p.append(a - a // t * t)
	p.sort()
	(s, w) = (0, 0)
	for h in p:
		if s + h <= K:
			s += h
		else:
			w += t - h
	if s >= w:
		ans = t
		break
print(ans)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
candidates = set()
for i in range(1, int(s ** 0.5) + 1):
	if s % i == 0:
		candidates.add(i)
		candidates.add(s // i)
ans = 0
for cdd in candidates:
	div_cdd = [0] * n
	for i in range(n):
		div_cdd[i] = a[i] % cdd
	div_cdd = sorted(div_cdd)
	(pstv, ngtv) = (0, -sum(div_cdd))
	if pstv == -ngtv:
		ans = max(ans, cdd)
		continue
	for i in range(n):
		pstv += cdd - div_cdd[-1 - i]
		ngtv += div_cdd[-1 - i]
		if pstv == -ngtv:
			break
	ans = max(ans, cdd) if pstv <= k else ans
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
D = []
i = 1
while i * i <= S:
	if S % i == 0:
		D.append(i)
		if S // i != i:
			D.append(S // i)
	i += 1
D = sorted(D, reverse=True)
for d in D:
	mod = [a % d for a in A]
	mod = sorted(mod)
	s = sum(mod)
	if sum(mod[:-s // d]) <= K:
		print(d)
		exit()


(N, K) = map(int, input().split())
alist = list(map(int, input().split()))
sum_a = sum(alist)
alist.sort()
divisor_set = set()
for i in range(1, int(sum_a ** 0.5) + 1):
	if sum_a % i == 0:
		divisor_set.add(i)
		divisor_set.add(sum_a // i)
divisor_list = list(divisor_set)
divisor_list.sort()
answer = 0
for d in divisor_list:
	rlist = []
	for a in alist:
		rlist.append((a % d, (d - a % d) % d))
	rlist.sort()
	(s1list, s2list) = ([0], [0])
	for (r1, r2) in rlist:
		s1list.append(s1list[-1] + r1)
		s2list.append(s2list[-1] + r2)
	for i in range(len(rlist)):
		r1sum = s1list[i]
		r2sum = s2list[-1] - s2list[i]
		if r1sum == r2sum and r1sum <= K:
			answer = d
			break
print(answer)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def yakusuu(a):
	yakusuu = set()
	for i in range(1, int(a ** 0.5) + 1):
		if a % i == 0:
			yakusuu.add(i)
			yakusuu.add(a // i)
	yakusuu = sorted(list(yakusuu), reverse=True)
	return yakusuu
y = yakusuu(sum(a))
from itertools import accumulate
flag = 0
for i in y:
	B = [A % i for A in a]
	C = sorted(B, reverse=True)
	B = list(accumulate(sorted(B)))
	C = list(reversed(list(accumulate([(i - c) % i for c in C]))))[1:] + [0]
	for j in range(n):
		if B[j] == C[j]:
			if B[j] <= k:
				print(i)
				flag = 1
				break
			break
	if flag == 1:
		break


(N, K) = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
S = sum(As)
ds = []
for d in range(1, 30000):
	if S % d == 0:
		ds.append(d)
		ds.append(S // d)
ds.sort()
for d in reversed(ds):
	Rs = [a % d for a in As]
	Rs.sort()
	s = sum(Rs)
	count = s // d
	r = 0
	for i in range(N - count):
		r += Rs[i]
	if r <= K:
		print(d)
		exit()


from heapq import heappush, heappop
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
divs = []
maxA = sum(A)
for i in range(1, int(maxA ** 0.5) + 1):
	if maxA % i == 0:
		heappush(divs, -i)
		j = maxA // i
		if i != j:
			heappush(divs, -j)
while True:
	d = -heappop(divs)
	q = []
	asum = 0
	for a in A:
		rest = a % d
		asum += rest
		heappush(q, -rest)
	cnt = 0
	for i in range(asum // d):
		cnt += d - -heappop(q)
	if cnt <= K:
		print(d)
		exit()


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors = sorted(divisors)
	return divisors
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum_a = sum(a)
div = make_divisors(sum_a)
ans = []
for i in div:
	mod_list = sorted([j % i for j in a], reverse=True)
	x = int(sum(mod_list) / i)
	mod_list = mod_list[:x]
	change = sum([i - j for j in mod_list])
	if change <= k:
		ans.append(i)
print(max(ans))


def main():
	(N, K) = list(map(int, input().split()))
	(*A,) = list(map(int, input().split()))

	def divisor_generator(n):
		div = 1
		stock = []
		while div * div <= n:
			if n % div == 0:
				yield (n // div)
				stock.append(div)
			div += 1
		for div in reversed(stock):
			yield div
	tot = sum(A)
	for div in divisor_generator(tot):
		k = tot // div - sum((a // div for a in A))
		R = sorted((a % div for a in A))
		Rc = [div - r for r in R]
		cond = (sr := sum((r for r in R[:N - k]))) == sum((r for r in Rc[N - k:])) and sr <= K
		if cond:
			print(div)
			return

def __starting_point():
	main()
__starting_point()


import math
from itertools import accumulate
(a, b) = map(int, input().split())
c = list(map(int, input().split()))

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort(reverse=True)
	return divisors
d = make_divisors(sum(c))
m = 1
for i in d:
	e = []
	for j in range(a):
		e.append(c[j] % i)
	e.sort()
	acc_m = list(accumulate(e))
	e = [i - e[j] for j in range(a)]
	acc_p = list(accumulate(e))
	for j in range(a):
		k = acc_m[j]
		l = acc_p[-1] - acc_p[j]
		if k == l and k + l <= b * 2:
			print(i)
			exit()


(N, K, *A) = map(int, open(0).read().split())
pls = []
S = sum(A)
for i in range(1, int(S ** 0.5) + 1):
	if S % i == 0:
		pls.append(i)
		pls.append(S // i)
pls.sort()
ans = 0
for p in pls:
	B = [a % p for a in A]
	B.sort()
	i = 0
	j = N - 1
	cnt = K
	while i < N:
		if B[i] != 0:
			break
		i += 1
	else:
		ans = p
		continue
	while True:
		a = B[i]
		b = B[j]
		if a < p - b:
			if cnt < a:
				break
			B[j] += a
			cnt -= a
			i += 1
		elif a > p - b:
			if cnt < p - b:
				break
			B[i] -= p - b
			cnt -= p - b
			j -= 1
		else:
			if cnt < a:
				break
			cnt -= a
			i += 1
			j -= 1
		if i >= j:
			ans = p
			break
print(ans)


from itertools import accumulate
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
A_sum = sum(A)
ans_candidates = []
for n in range(1, int(A_sum ** 0.5) + 1):
	if A_sum % n == 0:
		ans_candidates.append(n)
		ans_candidates.append(A_sum // n)
ans_candidates.sort(reverse=True)
for z in ans_candidates:
	need_add = [(z - a % z) % z for a in A]
	need_add.sort()
	need_minus = [z - na for na in need_add]
	need_add = list(accumulate(need_add))
	need_minus = list(accumulate(need_minus))
	for i in range(N):
		if need_add[i] == need_minus[-1] - need_minus[i] and need_add[i] <= K:
			print(z)
			exit()


from itertools import accumulate
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
ans_candidate = []
for i in range(1, int(S ** 0.5) + 1):
	if S % i == 0:
		ans_candidate.append(i)
		ans_candidate.append(S // i)
ans = 1
for z in ans_candidate:
	modZ_down = sorted([a % z for a in A])
	modZ_up = sorted([z - mzd for mzd in modZ_down], reverse=True)
	modZ_down = list(accumulate(modZ_down))
	modZ_up = list(accumulate(modZ_up[::-1]))[::-1]
	for i in range(N - 1):
		if modZ_down[i] == modZ_up[i + 1] and modZ_down[i] <= K:
			ans = max(ans, z)
print(ans)