Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

t = 1
for a in A:
    t = a*t//gcd(a, t)

ans = 0
for a in A:
    ans += t//a%mod
    ans %= mod

print(ans)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

t = 1
for a in A:
    t = a*t//gcd(a, t)

ans = 0
for a in A:
    ans += t//a

print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]

from functools import reduce
import fractions
 
mod = 10**9+7
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
num = lcm_list(A)
ans = 0
for i in A:
    ans += num//i
    ans %= mod
    
print(ans)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

t = 1
for a in A:
    t = a*t//gcd(a, t)

ans = 0
for a in A:
    ans += t//a

print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]

from functools import reduce
import fractions
 
mod = 10**9+7
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
num = lcm_list(A)
ans = 0
for i in A:
    ans += num//i
    ans %= mod
    
print(ans)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

t = 1
for a in A:
    t = a*t//gcd(a, t)

ans = 0
for a in A:
    ans += t//a

print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]
 
import fractions
 
mod = 10**9+7
num = 1
for i in range(N):
    num = num*A[i]//fractions.gcd(num, A[i])
    
ans = 0
for i in range(N):
    ans += num//A[i]
    ans %= mod
    
print(ans)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

t = 1
for a in A:
    t = a*t//gcd(a, t)

ans = 0
for a in A:
    ans += t//a

print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]

import fractions

mod = 10**9+7
num = 1
for i in range(N):
    num = num*A[i]//fractions.gcd(num, A[i])

ans = 0
for i in range(N):
    ans += num//A[i]
    ans %= mod

print(ans)


Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

t = 1
for a in A:
    t = a*t//gcd(a, t)

ans = 0
for a in A:
    ans += t//a

print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

N,M = map(int, input().split())
A = [int(a) for a in input().split()]

for i in range(N):
    A[i] //= 2
    
num = 1
for i in range(N):
    num = num*A[i]//fractions.gcd(num, A[i])
    
f = 0
for i in range(N):
    if (num//A[i])%2 == 0:
        f = 1
        break
        
if f == 0 and M >= num:
    ans = 1
    M -= num
    ans += M//(2*num)
    print(ans)
else:
    print(0)

Fixed submission:
import fractions

N,M = map(int, input().split())
A = [int(a) for a in input().split()]

for i in range(N):
    A[i] //= 2
    
num = 1
f = 0
for i in range(N):
    num = num*A[i]//fractions.gcd(num, A[i])
    if num > M:
        f = 1
        break
    
for i in range(N):
    if (num//A[i])%2 == 0:
        f = 1
        break
        
if f == 0 and M >= num:
    ans = 1
    M -= num
    ans += M//(2*num)
    print(ans)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]


L = [0]*61

for i in range(N):
    b = bin(A[i])
    for j in range(2, len(b)):
        if b[j] == "1":
            L[len(b)-j-1] += 1

ans = 0
mod = 10**9+7

for i in range(61):
    c = 2**i*(L[i]*(N-L[i]))
    ans += c
    ans %= mod
    
print(ans)

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]


L = [0]*61

for i in range(N):
    b = bin(A[i])
    for j in range(2, len(b)):
        if b[j] == "1":
            L[len(b)-j-1] += 1

ans = 0
mod = 10**9+7

for i in range(61):
    c = 2**i*(L[i]*(N-L[i]))
    ans += c
    ans %= mod
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = [int(d) for d in input().split()]

D.sort()
mod = 998244353

if D[0] == 0:
    if N == 1:
        ans = 1
    elif D[1] == 1:
        cnt = 0
        num = 1
        ans = 1
        for i in range(1, N):
            if D[i] == num:
                cnt += 1
            elif num == 1:
                prev = cnt
                cnt = 1
                num += 1
            elif D[i] == num+1:
                ans *= prev**cnt
                ans %= mod
                prev = cnt
                cnt = 1
                num += 1
            else:
                ans = 0
                break
        if cnt > 0:
            ans *= prev**cnt
            ans %= mod
    else:
        ans = 0
else:
    ans = 0
    
print(ans)

Fixed submission:
N = int(input())
D = [int(d) for d in input().split()]

f = 0
if D[0] != 0:
    f = -1
mod = 998244353
L = []

num = 0
cnt = 0
D.sort()
for i in range(N):
    if D[i] == num:
        cnt += 1
    elif D[i] == num+1:
        L.append(cnt)
        cnt = 1
        num += 1
    else:
        f = -1
        break
        
L.append(cnt)
ans = 1
if f == 0:
    if D[0] != 0:
        ans = 0
    if N > 1:
        if D[1] != 1:
            ans = 0
    if ans > 0:
        for i in range(1, len(L)):
            ans *= L[i-1]**L[i]
            ans %= mod
else:
    ans = 0
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
E = [[int(e) for e in input().split()] for _ in range(M)]

E.sort()
inf = 10**15
seg = [inf]*(2*N-1)

def update(k, x):
    k += N-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = min(seg[2*k+1], seg[2*k+2])
        
def query(p, q):
    p += N-1
    q += N-2
    res = inf
    while q-p > 1:
        if p&1 == 0:
            res = min(res, seg[p])
        if q&1 == 1:
            res = min(res, seg[q])
            q -= 1
        p //= 2
        q = (q-1)//2
    if p == q:
        res = min(res, seg[q])
    else:
        res = min(res, seg[p], seg[q])
    return res

update(0, 0)
for e in E:
    d = query(e[1]-1, N)
    l = query(e[0]-1, N)
    if l+e[2] < d:
        update(e[1]-1, l+e[2])

if seg[-1] == inf:
    print(-1)
else:
    print(seg[-1])

Fixed submission:
N,M = map(int, input().split())
E = [[int(e) for e in input().split()] for _ in range(M)]

E.sort()
inf = 10**15
seg = [inf]*(2*N-1)

def update(k, x):
    k += N-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = min(seg[2*k+1], seg[2*k+2])
        
def query(p, q):
    p += N-1
    q += N-2
    res = inf
    while q-p > 1:
        if p&1 == 0:
            res = min(res, seg[p])
        if q&1 == 1:
            res = min(res, seg[q])
            q -= 1
        p //= 2
        q = (q-1)//2
    if p == q:
        res = min(res, seg[q])
    else:
        res = min(res, seg[p], seg[q])
    return res

update(0, 0)
for e in E:
    d = query(e[1]-1, N)
    l = query(e[0]-1, N)
    if l+e[2] < d:
        update(e[1]-1, l+e[2])

if seg[-1] == inf:
    print(-1)
else:
    print(seg[-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())

for i in range(2, N):
    if N%i == 0:
        a = i
        b = N//i
        if a <= 9 and b <= 9:
            break

if N <= 2:
    print("Yes")
elif a <= 9 and b <= 9:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())

for i in range(2, N+1):
    if N%i == 0:
        a = i
        b = N//i
        if a <= 9 and b <= 9:
            break

if N <= 2:
    print("Yes")
elif a <= 9 and b <= 9:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N = int(input())

for i in range(2, N):
    if N%i == 0:
        a = i
        b = N//i
        if a <= 9 and b <= 9:
            break

if N == 1:
    print("Yes")
elif a <= 9 and b <= 9:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())

for i in range(2, N+1):
    if N%i == 0:
        a = i
        b = N//i
        if a <= 9 and b <= 9:
            break

if N <= 2:
    print("Yes")
elif a <= 9 and b <= 9:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

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

    
if K >= sum(A):
    ans = 0
else:
    A.sort(reverse=True)
    F.sort()
    h = []
    for i in range(N):
        heapq.heappush(h, [-A[i]*F[i], A[i], F[i]])
    while K > 0:
        temp = heapq.heappop(h)
        temp[0] += temp[2]
        temp[1] -= 1
        heapq.heappush(h, temp)
        K -= 1
    L = heapq.heappop(h)
    ans = -L[0]
print(ans)

Fixed submission:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]
F = [int(f) for f in input().split()]

A.sort()
F.sort(reverse=True)

if K >= sum(A):
    ans = 0
else:
    u = 10**13
    l = 0
    while u-l > 1:
        x = (u+l)//2
        cnt = K
        for i in range(N):
            cnt -= max(0, A[i]-x//F[i])
        if cnt >= 0:
            u = x
        else:
            l = x
    cnt = K
    for i in range(N):
        cnt -= max(0, A[i]-l//F[i])
    if cnt >= 0:
        ans = l
    else:
        ans = u
        
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

L = []
temp = S[0]
c = 1
for i in range(1, len(S)):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
    if i == len(S)-1:
        L.append(c)
        
ans = 0
if S[0] != S[-1]:
    for i in range(len(L)):
        ans += (L[i]//2)
    ans *= K
else:
    if len(L) == 1:
        ans = K*L[0]//2
    else:
        for i in range(1, len(L)-1):
            ans += (L[i]//2)
        ans *= K
        ans += (L[0]+L[-1])//2*K
        
print(ans)

Fixed submission:
S = input()
K = int(input())

L = []
temp = S[0]
c = 1
for i in range(1, len(S)):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
    if i == len(S)-1:
        L.append(c)
        
ans = 0

if S[0] != S[-1]:
    for i in range(len(L)):
        ans += (L[i]//2)
    ans *= K
else:
    if len(L) == 1:
        ans += K*L[0]//2
    elif len(L) == 0:
        ans += K//2
    else:
        for i in range(1, len(L)-1):
            ans += (L[i]//2)
        ans *= K
        ans += L[0]//2
        ans += L[-1]//2
        ans += (L[0]+L[-1])//2*(K-1)
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
L = []
C = []
for i in range(M):
    L.append([int(l) for l in input().split()])
    C.append([int(c) for c in input().split()])
    
dp = [[10**8+1 for j in range(2**N)] for i in range(M+1)]

for i in range(M+1):
    dp[i][0] = 0

    
for i in range(1, M+1):
    temp = 0
    for k in range(len(C[i-1])):
        temp += 2**(C[i-1][k]-1)
    if i == 1:
        for j in range(1, 2**N):
            if j | temp == temp:
                dp[i][j] = L[i-1][0]
                l = i+1
                while l <= M:
                    dp[l][j] = dp[i][j]
                    l += 1

    else:
        for j in range(2**N):
            dp[i][temp | j] = min(dp[i-1][temp | j], dp[i-1][j]+L[i-1][0], dp[i][temp | j])
            l = i+1
            while l <= M:
                dp[l][temp | j] = dp[i][temp | j]
                l += 1


if dp[-1][-1] >= 10**8+1:
    print(-1)
else:
    print(dp[-1][-1])

Fixed submission:
N,M = map(int, input().split())
L = []
C = []
for i in range(M):
    L.append([int(l) for l in input().split()])
    C.append([int(c) for c in input().split()])
    
dp = [10**8+1 for j in range(2**N)]
dp[0] = 0

for i in range(1, M+1):
    temp = 0
    for k in range(len(C[i-1])):
        temp += 2**(C[i-1][k]-1)
    for j in range(2**N):
        if i == 1:
            if j | temp == temp and j != 0:
                dp[j] = L[i-1][0]

        else:
            dp[temp | j] = min(dp[temp | j], dp[j]+L[i-1][0])
      
if dp[-1] >= 10**8+1:
    print(-1)
else:
    print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
L = []
C = []
for i in range(M):
    L.append([int(l) for l in input().split()])
    C.append([int(c) for c in input().split()])
    
dp = [[10**8+1 for j in range(2**N)] for i in range(M+1)]

for i in range(M+1):
    dp[i][0] = 0

    
for i in range(1, M+1):
    temp = 0
    for k in range(len(C[i-1])):
        temp += 2**(C[i-1][k]-1)
    if i == 1:
        for j in range(1, 2**N):
            if j | temp == temp:
                dp[i][j] = L[i-1][0]
                l = i+1
                while l <= M:
                    dp[l][j] = dp[i][j]
                    l += 1

    else:
        for j in range(2**N):
            dp[i][temp | j] = min(dp[i-1][temp | j], dp[i-1][j]+L[i-1][0], dp[i][temp | j])
            l = i+1
            while l <= M:
                dp[l][temp | j] = dp[i][temp | j]
                l += 1


if dp[-1][-1] >= 10**8+1:
    print(-1)
else:
    print(dp[-1][-1])

Fixed submission:
N,M = map(int, input().split())
L = []
C = []
for i in range(M):
    L.append([int(l) for l in input().split()])
    C.append([int(c) for c in input().split()])
    
dp = [10**8+1 for j in range(2**N)]
dp[0] = 0

for i in range(1, M+1):
    temp = 0
    for k in range(len(C[i-1])):
        temp += 2**(C[i-1][k]-1)
    for j in range(2**N):
        if i == 1:
            if j | temp == temp and j != 0:
                dp[j] = L[i-1][0]

        else:
            dp[temp | j] = min(dp[temp | j], dp[j]+L[i-1][0])
      
if dp[-1] >= 10**8+1:
    print(-1)
else:
    print(dp[-1])
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
P = [int(p) for p in input().split()]

L = [0 for i in range(N-1)]
temp = P[0]
for i in range(1,N):
    if temp > P[i]:
        L[i-1] = 1
    temp = P[i]
    
cnt = 0
for i in range(K-2, N-K+1):
    if L[i] == 1:
        chk = 0
        for j in range(1,K):
            if L[i+j] == L[i-j]:
                chk += 1
            else:
                break
        if chk == K-1:
            cnt += 1
            
zero = []
z = 0
for i in range(N-1):
    if L[i] == 0:
        z += 1
    else:
        zero.append(z)
        z = 0

cnt2 = 0
for i in range(len(zero)):
    if zero[i] >= K-1:
        cnt2 += zero[i]-K+2
        
print(N-K+1-cnt-cnt2)

Fixed submission:
import heapq

N,K = map(int, input().split())
P = [int(p) for p in input().split()]

h = []
H = []
for i in range(K):
    heapq.heappush(h, (P[i], i))
    heapq.heappush(H, (-P[i], i))
    
ans = 1
for i in range(N-K):
    while h[0][1] < i:
        heapq.heappop(h)
    while H[0][1] < i:
        heapq.heappop(H)
    heapq.heappush(h, (P[i+K], i+K))
    heapq.heappush(H, (-P[i+K], i+K))
    if h[0][0] == P[i] and -H[0][0] == P[i+K]:
        continue
    ans += 1
    
f = 0
cnt = 1
for i in range(N-1):
    if P[i] < P[i+1]:
        cnt += 1
    else:
        if cnt >= K and f == 1:
            ans -= 1
        elif cnt >= K and f == 0:
            f = 1
        cnt = 1
        
if cnt >= K and f == 1:
    ans -= 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

A.sort(reverse=True)
List = [[] for i in range(100)]
for i in range(N):
    temp = bin(A[i])
    List[len(temp)-3].append(A[i])

List.reverse()
List = [i for i in List if i != []]
for i in range(len(List)):
    List[i].sort(reverse=True)
c = 0
cnt = 0
while cnt < M:
    for i in range(cnt+1):
        for j in range(len(List[i])):
            List[i][j] = List[i][j]//2
            c += 1
            if c == M:
                cnt = M+1
                c = M+1
                break
        if c > M:
            break
    cnt += 1
            
ans = 0
for i in range(len(List)):
    ans += sum(List[i])
            
print(ans)

Fixed submission:
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

import heapq

h = []
for i in range(N):
    heapq.heappush(h, A[i]*(-1))
    
for i in range(M):
    temp = heapq.heappop(h)
    temp *= (-1)
    temp //= 2
    temp *= (-1)
    heapq.heappush(h, temp)
    
print(sum(h)*(-1))

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

A.sort(reverse=True)
List = [[] for i in range(100)]
for i in range(M):
    temp = bin(A[i])
    List[len(temp)-3].append(A[i])

List.reverse()
List = [i for i in List if i != []]
for i in range(len(List)):
    List[i].sort(reverse=True)
c = 0
cnt = 0
while cnt < M:
    for i in range(cnt+1):
        for j in range(len(List[i])):
            List[i][j] = List[i][j]//2
            c += 1
            if c == M:
                c = M+1
                break
        if c > M:
            break
    cnt += 1
            
ans = 0
for i in range(len(List)):
    ans += sum(List[i])
            
print(ans)

Fixed submission:
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

import heapq

h = []
for i in range(N):
    heapq.heappush(h, A[i]*(-1))
    
for i in range(M):
    temp = heapq.heappop(h)
    temp *= (-1)
    temp //= 2
    temp *= (-1)
    heapq.heappush(h, temp)
    
print(sum(h)*(-1))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

A.sort(reverse=True)

for i in range(M):
    if i == 0:
        A[0] = A[0]//2
    else:
        temp = A[0]
        idx = 0
        j = 0
        while j < N and j <= i:
            if temp < A[j]:
                temp = A[j]
                idx = j
            j += 1
        A[idx] = A[idx]//2
        
print(sum(A))

Fixed submission:
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

import heapq

h = []
for i in range(N):
    heapq.heappush(h, A[i]*(-1))
    
for i in range(M):
    temp = heapq.heappop(h)
    temp *= (-1)
    temp //= 2
    temp *= (-1)
    heapq.heappush(h, temp)
    
print(sum(h)*(-1))
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)
prev = S[0]
ans = 1
i = 1
while i < N:
  ans += 1
  if len(prev) == 2:
    prev = S[i]
    i += 1
    continue
  if prev == S[i] and i < N-1:
    i += 2
    prev = S[i] + S[i+1]
  elif prev == S[i]:
    ans -= 1
    break
  else:
    prev = S[i]
    i += 1
print(ans)

Fixed submission:
S = input()
N = len(S)
prev = S[0]
ans = 1
i = 1
while i < N:
  ans += 1
  if len(prev) == 2:
    prev = S[i]
    i += 1
    continue
  if prev == S[i] and i < N-1:
    prev = S[i] + S[i+1]
    i += 2
  elif prev == S[i]:
    ans -= 1
    break
  else:
    prev = S[i]
    i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [int(h) for h in input().split()]

if N == 1:
    ans = "Yes"
else:
    c = 1
    while c <= N-2:
        if H[c] > H[c+1] and H[c-1] < H[c]:
            H[c] -= 1
        elif H[c] == H[c+1] and H[c-1] < H[c]:
            H[c] -= 1
            H[c+1] -= 1
            c += 1
        c += 1
    List = []
    for j in range(N):
        List.append(H[j])
    List.sort()
    if List == H:
        ans = "Yes"
    else:
        ans = "No"

print(ans,List)

Fixed submission:
N = int(input())
H = [int(h) for h in input().split()]

if N == 1:
    ans = "Yes"
else:
    c = 0
    while c <= N-2:
        if H[c] < H[c+1]:
            H[c+1] -= 1
        c += 1
    List = []
    for j in range(N):
        List.append(H[j])
    List.sort()
    if List == H:
        ans = "Yes"
    else:
        ans = "No"

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

M = sum(A)
L = []
i = 1
while i <= M**0.5:
    if M%i == 0:
        L.append(i)
        L.append(M//i)
    i += 1
    
L.sort(reverse=True)

for i in L:
    temp = [0]*N
    for j in range(N):
        temp[j] = A[j]%i
    temp.sort()
    cnt = 0
    l = 0
    r = N-1
    while l < r:
        if temp[l] == 0:
            l += 1
            continue
        if temp[r] == 0:
            r -= 1
            continue
        temp[l] -= 1
        temp[r] += 1
        temp[r] %= i
        cnt += 1
    if cnt <= K:
        ans = i
        break

print(ans)

Fixed submission:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

M = sum(A)
L = []
i = 1
while i <= M**0.5:
    if M%i == 0:
        L.append(i)
        L.append(M//i)
    i += 1
    
L.sort(reverse=True)

for i in L:
    temp = [0]*N
    for j in range(N):
        temp[j] = A[j]%i
    temp.sort()
    cnt = 0
    l = 0
    r = N-1
    while l < r:
        if temp[l] == 0:
            l += 1
            continue
        if temp[r] == 0:
            r -= 1
            continue
        t = temp[l]
        temp[l] = 0
        cnt += t
        while l < r and temp[r]+t > i:
            t -= i-temp[r]
            temp[r] = 0
            r -= 1
        temp[r] += t
        temp[r] %= i
            
    if cnt <= K:
        ans = i
        break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

M = sum(A)
L = []
i = 1
while i <= M**0.5:
    if M%i == 0:
        L.append(i)
        L.append(M//i)
    i += 1
    
L.sort(reverse=True)

for i in L:
    temp = [0]*N
    for j in range(N):
        temp[j] = A[j]%i
    temp.sort()
    cnt = 0
    l = 0
    r = N-1
    while l < r:
        if temp[l] == 0:
            l += 1
            continue
        if temp[r] == 0:
            r -= 1
            continue
        temp[l] -= 1
        temp[r] += 1
        temp[r] %= i
        cnt += 1
    if cnt <= K:
        ans = i
        break

print(ans)

Fixed submission:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]

M = sum(A)
L = []
i = 1
while i <= M**0.5:
    if M%i == 0:
        L.append(i)
        L.append(M//i)
    i += 1
    
L.sort(reverse=True)

for i in L:
    temp = [0]*N
    for j in range(N):
        temp[j] = A[j]%i
    temp.sort()
    cnt = 0
    l = 0
    r = N-1
    while l < r:
        if temp[l] == 0:
            l += 1
            continue
        if temp[r] == 0:
            r -= 1
            continue
        t = temp[l]
        temp[l] = 0
        cnt += t
        while l < r and temp[r]+t > i:
            t -= i-temp[r]
            temp[r] = 0
            r -= 1
        temp[r] += t
        temp[r] %= i
            
    if cnt <= K:
        ans = i
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]
c = N-1
A.sort()
while c > 0:
    num = A[0]^A[c]
    pre_num = A[c]
    B = [A[0],A[c],num]
    while len(B) < N:
        box = num
        num = num^pre_num
        pre_num = box
        B.append(num)
        if pre_num not in A:
            break
    B.sort()
    if A == B:
        break
    c -= 1
if c > 0:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
c = N-1
A.sort()
num = A[0]^A[c]
pre_num = A[c]
B = [A[0],A[c],num]
while len(B) < N:
    box = num
    num = num^pre_num
    pre_num = box
    B.append(num)
B.sort()
if A == B:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(a) for a in input().split()]
c = N-1
A.sort()
while c > 0:
    num = A[0]^A[c]
    pre_num = A[c]
    B = [A[0],A[c],num]
    while len(B) < N:
        box = num
        num = num^pre_num
        pre_num = box
        B.append(num)
    B.sort()
    if A == B:
        break
    c -= 1
if c > 0:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
c = N-1
A.sort()
num = A[0]^A[c]
pre_num = A[c]
B = [A[0],A[c],num]
while len(B) < N:
    box = num
    num = num^pre_num
    pre_num = box
    B.append(num)
B.sort()
if A == B:
    print("Yes")
else:
    print("No")