Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02695 (python)

Fixed submission:
def main():
	n,m,q = map(int,input().split())
	qu = [list(map(int,input().split())) for x in range(q)]
	ans = 0
	import itertools

	ans_list = set()
	for i in itertools.combinations_with_replacement(list(range(1,m+1)),n):
		for qul in range(q):
			if i[ qu[qul][1]-1 ] - i[ qu[qul][0]-1 ] == qu[qul][2]:
				ans += qu[qul][3]
		ans_list.add(ans)
		ans = 0
	print(max(ans_list))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	n,m,q = map(int,input().split())
	qu = [list(map(int,input().split())) for x in range(q)]
	ans = 0
	import itertools

	ans_list = set()
	for i in itertools.combinations_with_replacement([1,2,3,4,5,6,7,8,9,10],m):
		for qul in range(q):
			if i[ qu[qul][1]-1 ] - i[ qu[qul][0]-1 ] == qu[qul][2]:
				ans += qu[qul][3]
		ans_list.add(ans)
		ans = 0
	print(max(ans_list))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	n,m,q = map(int,input().split())
	qu = [list(map(int,input().split())) for x in range(q)]
	ans = 0
	import itertools

	ans_list = set()
	for i in itertools.combinations_with_replacement([1,2,3,4,5,6,7,8,9,10],m):
		if list(i) == sorted(i):
			for qul in range(q):
				if i[ qu[qul][1]-1 ] - i[ qu[qul][0]-1 ] == qu[qul][2]:
					ans += qu[qul][3]
			ans_list.add(ans)
			ans = 0
	print(max(ans_list))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	n,m,q = map(int,input().split())
	qu = [list(map(int,input().split())) for x in range(q)]
	ans = 0
	import itertools

	ans_list = set()
	for i in list(itertools.product([1,2,3,4,5,6,7,8,9,10],repeat = m)):
		if list(i) == sorted(i):
			for qul in range(q):
				if i[ qu[qul][1]-1 ] - i[ qu[qul][0]-1 ] == qu[qul][2]:
					ans += qu[qul][3]
			ans_list.add(ans)
			ans = 0
	print(max(ans_list))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	n,m,q = map(int,input().split())
	qu = [list(map(int,input().split())) for x in range(q)]
	ans = 0
	import itertools

	ans_list = set()
	for i in list(itertools.product([1,2,3,4,5,6,7,8,9,10],repeat = m)):
		for qul in range(q):
			if i[ qu[qul][1]-1 ] - i[ qu[qul][0]-1 ] == qu[qul][2] and list(i) == sorted(i):
				ans += qu[qul][3]
		ans_list.add(ans)
		ans = 0
	print(max(ans_list))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	n,m,q = map(int,input().split())
	qu = [list(map(int,input().split())) for x in range(q)]
	ans = 0
	import itertools

	alist = list(itertools.product([1,2,3,4,5,6,7,8,9,10],repeat = m))
	ans_list = set()
	for i in alist:
		for qul in range(q):
			if i[ qu[qul][1]-1 ] - i[ qu[qul][0]-1 ] == qu[qul][2] and list(i) == sorted(i):
				ans += qu[qul][3]
		ans_list.add(ans)
		ans = 0
	print(max(ans_list))

if __name__ == '__main__':
	main()
Problem p02729 (python)

Fixed submission:
def main():
	# s = int(input())
	# s = str(input())
	a,b = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	# l = [str(input()) for i in range(n)]
	#R行C列
	# qu = [list(map(str,input().split())) for x in range(q)]
	# print(' '.join(map(str,)))
	import math
	def combinations_count(n, r):
		return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

	if a <= 1 and b > 1:
		print(combinations_count(b,2))
	elif a <= 1 and b <= 1:
		print(0)
	elif a > 1 and b <= 1:
		print(combinations_count(a,2))
	else:
		print(combinations_count(a,2) + combinations_count(b,2))


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# s = int(input())
	# s = str(input())
	a,b = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	# l = [str(input()) for i in range(n)]
	#R行C列
	# qu = [list(map(str,input().split())) for x in range(q)]
	# print(' '.join(map(str,)))
	import math
	def combinations_count(n, r):
		return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

	if b <= 1:
		print(combinations_count(a,2))
	elif a <= 1:
		print(0)
	else:
		print(combinations_count(a,2) + combinations_count(b,2))


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# s = int(input())
	# s = str(input())
	a,b = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	# l = [str(input()) for i in range(n)]
	#R行C列
	# qu = [list(map(str,input().split())) for x in range(q)]
	# print(' '.join(map(str,)))
	import math
	def combinations_count(n, r):
		return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

	if b == 0 or b == 1:
		print(combinations_count(a,2))
	else:
		print(combinations_count(a,2) + combinations_count(b,2))


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# s = int(input())
	# s = str(input())
	a,b = map(int,input().split())

	from itertools import combinations

	if b == 0 or b == 1:
		print(len(combinations(a,2)))
	else:
		print(len(combinations(a,2)) + len(combinations(b,2)))


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# s = int(input())
	# s = str(input())
	a,b = map(int,input().split())
	#1行R列
	# a = list(map(int,input().split()))
	#R行1列
	# l = [str(input()) for i in range(n)]
	#R行C列
	# qu = [list(map(str,input().split())) for x in range(q)]
	# print(' '.join(map(str,)))
	from itertools import permutations, combinations,combinations_with_replacement,product

	if b == 0 or b == 1:
		print(combinations(a,2))
	else:
		print(combinations(a,2) + combinations(b,2))


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():

	a,b = map(int,input().split())

	import fractions
	def combinations_count(n, r):
		return fractions.factorial(n) // (fractions.factorial(n - r) * fractions.factorial(r))

	if b == 0 or b == 1:
		print(combinations_count(a,2))
	else:
		print(combinations_count(a,2) + combinations_count(b,2))


if __name__ == '__main__':
	main()
Problem p02766 (python)

Fixed submission:
def main():
	n,m = map(int,input().split())
	ans = 1
	while n >= m:
		n = (n-n%m) // m
		ans += 1
	print(ans)

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	n,m = map(int,input().split())
	# a = list(map(int,input().split()))
	# l = [str(input()) for i in range(n)]
	
	# m_pre = int(m)
	# ans = []
	# while n > 1:
	# 	print(n%m)
	# 	ans.append(n%m)
	# 	print("n = {}".format(n))
	# 	n = (n - (n%m)) // m
	# if n<m:
	# 	ans.append(1)
	# ans.reverse()
	# print(len(''.join(map(str,ans))))
	if n > m:
    	ans = 1
    else:
		ans = 0
	while n >= m:
		n = (n-n%m) // m
		ans += 1
	# if n < m:
	# 	ans -= 1
	print(ans)
	
 
if __name__ == '__main__':
	main()
Problem p02773 (python)

Fixed submission:
def main():
	# n,m = map(int,input().split())
	n = int(input())
	l = [str(input()) for i in range(n)]
	
	import collections

	c = collections.Counter(l)
	lc = sorted(list(c.items()), key = lambda x:x[1] , reverse = True)
	# print(lc[0][0])
	ans = []
	checker = 0
	i = 0
	while checker == 0 and i < len(lc):
		if lc[i][1] == lc[0][1]:
			ans.append(lc[i][0])
		else:
			checker += 1
		i += 1

	# keys = [k for k, v in c.items() if v == max(c.values())]
	# print(list(c.items())[0][0])
	# checker = 0
	# while checker == 0:
	# 	if c.items() == max(c.values()):
	ans.sort()
	print('\n'.join(map(str, ans)))

	
	
 
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# n,m = map(int,input().split())
	n = int(input())
	l = [str(input()) for i in range(n)]
	
	import collections

	c = collections.Counter(l)
	lc = sorted(list(c.items()), key = lambda x:x[1] , reverse = True)
	# print(lc)
	ans = []
	checker = 0
	i = 0
	while checker == 0:
		if lc[i][1] == lc[0][1]:
			ans.append(lc[i][0])
		else:
			checker += 1
		i += 1

	# keys = [k for k, v in c.items() if v == max(c.values())]
	# print(list(c.items())[0][0])
	# checker = 0
	# while checker == 0:
	# 	if c.items() == max(c.values()):
	ans.sort()
	print('\n'.join(map(str, ans)))

	
	
 
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	n = int(input())
	l = [str(input()) for i in range(n)]
	
	import collections

	c = collections.Counter(l)
	lc = sorted(list(c.items()), key = lambda x:x[1] , reverse = True)
	print(lc)
	ans = []
	checker = 0
	i = 0
	while checker == 0:
		if lc[i][1] == lc[0][1]:
			ans.append(lc[i][0])
		else:
			checker += 1
		i += 1

	ans.sort()
	print('\n'.join(map(str, ans)))

	
	
 
if __name__ == '__main__':
	main()
Problem p02860 (python)

Fixed submission:
def main():
	# n,m = map(int,input().split())
	n = int(input())
	s = str(input())
	# a = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# print(s+s)
	if s[:(int(n/2))] + s[:int(n/2)] == s:
		print("Yes")

	else:
		print("No")


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# n,m = map(int,input().split())
	n = int(input())
	s = str(input())
	# a = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]

	if s[:(n/2)] == s+s:
		print("Yes")

	else:
		print("No")
	
	






if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# n,m = map(int,input().split())
	n = int(input())
	s = str(intpu())
	# a = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]

	if s[:(n/2)] == s+s:
		print("Yes")

	else:
		print("No")
	
	






if __name__ == '__main__':
	main()
Problem p02879 (python)

Fixed submission:
def main():
	# a,b,k = map(int,input().split())
	n,k = map(int,input().split())
	# s = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(n-1)]
	# s = list(s)
 
	if n < 10 and k < 10:
		print(int(n*k))
	else:
 		print(-1)
 
 
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# a,b,k = map(int,input().split())
	n,k = map(int,input().split())
	# s = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(n-1)]
	# s = list(s)

	if n < 10 or k < 10:
		print(int(n*k))	
 	else:
 		print(-1)

 
if __name__ == '__main__':
	main()
Problem p02897 (python)

Fixed submission:
def main():
	# a,b,k = map(int,input().split())
	# n,k = map(int,input().split())
	n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(5)]
	# s = list(s)
	ans = 0
	for i in range(1,n+1):
		if i % 2 != 0:
			ans += 1
	print(ans/n)


 
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# a,b,k = map(int,input().split())
	# n,k = map(int,input().split())
	n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(5)]
	# s = list(s)
	
	for i in range(n):
		if n % 2 != 0:
			ans += 1
	print(ans/n)


 
if __name__ == '__main__':
	main()
Problem p02933 (python)

Fixed submission:
def main():
	# n,m = map(int,input().split())
	# n,k = map(int,input().split())
	# n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	
	a = int(input())
	s = str(input())

	if a >= 3200:
		print(s)
	else:
		print("red")


 
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# n,m = map(int,input().split())
	# n,k = map(int,input().split())
	# n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	
	a = int(input())
	s = int(input())

	if a >= 3200:
		print("red")
	else:
		print(s)


 
if __name__ == '__main__':
	main()
Problem p02951 (python)

Fixed submission:
def main():
	a,b,c = map(int,input().split())
	
	ans = c-a+b
	
	if ans < 0:
		print(0)
	else:
		print(ans)

 
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	# n,m = map(int,input().split())
	# n,k = map(int,input().split())
	# n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	
	a,b,c = map(int,input().split())
 	ans = c-a+b
	if ans < 0:
		print(0)
	else:
		print(ans)

 
if __name__ == '__main__':
	main()
Problem p02987 (python)

Fixed submission:
def main():
	n = list(str(input()))
	n_s = sorted(n)
	if n_s[0] == n_s[1] and n_s[2] == n_s[3] and n_s[1] != n_s[2]:
		print("Yes")
	else:
		print("No")

 
if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	n = list(str(input()))

	n_s = sorted(n)
	elif n_s[0] == n_s[1] and n_s[2] == n_s[3] and n_s[1] != n_s[2]:
		print("Yes")
	else:
		print("No")

 
if __name__ == '__main__':
	main()
Problem p02580 (python)

Fixed submission:
from collections import Counter


def solve():
    H, W, M = map(int, input().split())
    dh, dw = Counter(), Counter()
    used = set()

    for _ in range(M):
        h, w = map(int, input().split())
        dh[h] += 1
        dw[w] += 1
        used.add((h, w))

    ih = dh.most_common()
    iw = dw.most_common()

    h, counth = ih[0]
    w, countw = iw[0]

    s = counth + countw
    ans = counth + countw - ((h, w) in used)

    for h, counth in ih:
        for w, countw in iw:
            if counth+countw < s or ans == s:
                break
            b = counth + countw - ((h, w) in used)
            ans = max(ans, b)
    print(ans)


solve()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

H, W, M = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(M)]

dh, dw = defaultdict(int), defaultdict(int)
used = set()

for h, w in l:
    dh[h] += 1
    dw[w] += 1
    used.add((h, w))

ih = sorted(dh.items(), key=lambda x:-x[1])
iw = sorted(dw.items(), key=lambda x:-x[1])

def get(x):
    h, counth = ih[x]
    w, countw = iw[x]
    ans = counth + countw
    if (h, w) in used:
        ans -= 1
    return ans

print(max(get(0), get(1)))
Problem p02598 (python)

Fixed submission:
N, K = map(int, input().split())
*A, = map(int, input().split())

def f(t):
    if t!=0:
        c = 0
        for i in A:
            c += i//t if i!=t else 0
        return c<=K
    else:
        return all(i<=t for i in A)

left, right = -1, 10**10
while right-left>1:
    m = (right+left)//2
    if f(m):
        right = m
    else:
        left = m

print(right)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

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

def g(X, t):
    if X<=t:
        return 0
    return 1+g(t, t)+g(X-t, t)

def f(t):
    c = 0
    for i in A:
        c += i//t if i!=t else 0
    return c<=K

left, right = -1, 10**10
while right-left>1:
    m = (right+left)//2
    if f(m):
        right = m
    else:
        left = m

print(right)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

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

def g(X, t):
    if X<=t:
        return 0
    return 1+g(t, t)+g(X-t, t)

def f(t):
    c = 0
    for i in A:
        c += g(i, t)
    return c<=K

left, right = -1, 10**10
while right-left>1:
    m = (right+left)//2
    if f(m):
        right = m
    else:
        left = m

print(right)
Problem p02679 (python)

Fixed submission:
from math import gcd
from collections import defaultdict

N = int(input())
d = {}
MOD = 10**9+7
zall = 0

for _ in range(N):
    A, B = map(int, input().split())

    if A==0 and B==0:
        zall += 1
    else:
        if A and B:
            if A<0 and B<0:
                A *= -1
                B *= -1
            elif A<0 and B>0:
                A *= -1
                B *= -1

            g = gcd(A, B)
            A //= g
            B //= g
        elif A==0:
            B = 1
        elif B==0:
            A = 1
        
        if (A, B) in d:
            d[(A, B)] += 1
        else:
            d[(A, B)] = 1

ans = 1
used = defaultdict(int)

for (i, j), v in d.items():
    if used[(i, j)]:continue
    used[(i, j)] = 1
    buf = 0

    if j>0:
        if (j, -i) in d:
            used[(j, -i)] = 1
            buf = d[(j, -i)]
        else:
            buf = 0
    else:
        if (-j, i) in d:
            used[(-j, i)] = 1
            buf = d[(-j, i)]
        else:
            buf = 0

    ans *= (pow(2, buf, MOD)+pow(2, v, MOD)-1)
    ans %= MOD

print((ans+zall-1)%MOD)

Buggy submission (verdict: Runtime Error):
from math import gcd
from collections import defaultdict

N = int(input())
d = {}
MOD = 10**9+7

for _ in range(N):
    A, B = map(int, input().split())
    g = gcd(A, B)
    A//=g
    B//=g
    if (A, B) in d:
        d[(A, B)] += 1
    else:
        d[(A, B)] = 1

b = 1
used = defaultdict(int)

for (i, j), v in d.items():
    if used[(i, j)]:continue
    buf = 0
    if (-j, i) in d or (j, -i) in d:
        if (-j, i) in d:
            used[(-j, i)] = 1
            buf += pow(2, d[(-j, i)], MOD)+pow(2, v, MOD)-1
        if (j, -i) in d:
            used[(j, -i)] = 1
            buf += pow(2, d[(j, -i)], MOD)+pow(2, v, MOD)-1
        b *= buf
    else:
        b *= pow(2, v, MOD)
    b %= MOD
b -= 1
b %= MOD
print(b)
Problem p02779 (python)

Fixed submission:
N = int(input())
*l, = map(int, input().split())
print("YES" if len(l)==len(set(l)) else "NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
*l = map(int, input().split())
print("YES" if len(l)==len(set(l)) else "NO")
Problem p02835 (python)

Fixed submission:
*A, = map(int, input().split())
print("bust" if sum(A)>=22 else "win")

Buggy submission (verdict: Runtime Error):
*A, = map(int, input().split())
print("bust" if sum(a)>=22 else "win")
Problem p02851 (python)

Fixed submission:
from collections import Counter

N, K = map(int, input().split())
*A, = map(int, input().split())
MOD = 10**9+7
S = [0]*(N+1)
c = Counter()
c[0] = 1
ans = 0

for i in range(N):
    S[i+1] = (S[i]+A[i]-1)%K
    if i+1-K>=0:
        c[S[i+1-K]] -= 1
    ans += c[S[i+1]]
    c[S[i+1]] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N, K = map(int, input().split())
*A, = map(int, input().split())
MOD = 10**9+7
ac = [0]*(N+1)

for i in range(1, N+1):
    ac[i] = (ac[i-1]+A[i-1])%K
for i in range(N+1):
    ac[i] -= i
    ac[i] %= K

c = Counter()
for i in range(K-1):
    c[ac[i]] += 1
ans = 0
for i in range(N+1):
    if i+K-1<=N:
        c[ac[i+K-1]] += 1
    ans += c[ac[i]]-1
    c[ac[i]] -= 1

print(ans)
Problem p02862 (python)

Fixed submission:
X, Y = map(int, input().split())

mod = 10**9+7
N = 1333334
fac = [1]*(N+1)
rev = [1]*(N+1)
 
for i in range(1,N+1):
  fac[i] = i*fac[i-1]%mod
  rev[i] = pow(fac[i], mod-2, mod)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod

a, b = (2*X-Y)//3, (2*Y-X)//3
if a<0 or b<0 or (2*X-Y)%3 or (2*Y-X)%3:
    print(0)
else:
    print(comb(a+b, a))

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())

if (2*X-Y)%3==0 and (2*Y-X)%3==0:
    a = (2*X-Y)//3
    b = X-2*a
    MOD = 10**9+7
    n = a+b+1
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
        fac[i] = i*fac[i-1]%MOD
        rev[i] = pow(fac[i], MOD-2, MOD)
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

    print(comb(a+b, a))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())

if (2*X-Y)%3 or (2*Y-X)%3:
    print(0)
else:
    a, b = (2*X-Y)//3, X-2*a
    MOD = 10**9+7
    n = a+b+1
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
        fac[i] = i*fac[i-1]%MOD
        rev[i] = pow(fac[i], MOD-2, MOD)
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

    print(comb(a+b, a))

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())

if (2*X-Y)%3:
    print(0)
else:
    a = (2*X-Y)//3
    b = X-2*a

    MOD = 10**9+7
    n = a+b+1
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
        fac[i] = i*fac[i-1]%MOD
        rev[i] = pow(fac[i], MOD-2, MOD)
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

    print(comb(a+b, a))
Problem p02955 (python)

Fixed submission:
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)

Buggy submission (verdict: Runtime Error):
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 m:
        ans = max(ans, d)

print(ans)
Problem p02964 (python)

Fixed submission:
from collections import defaultdict, Counter
from bisect import bisect_right, bisect_left

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

c = Counter(A)
target = []
d = defaultdict(list)

dd = defaultdict(list)
for i, j in enumerate(A):
    dd[j].append(i)

pos = 0
loop = 1
l = []

while pos < N:
    num = A[pos]
    
    pp = bisect_right(dd[num], pos)
    if pp < len(dd[num]):
        pos = dd[num][pp]+1
    else:
        pos = dd[num][0]+1            
        loop += 1
    l.append((num, pos, loop))

for v, pos, p in l:
    if (K-p)%loop==0:
        break

pos = pos if pos<N else 0
ans = []
while pos < N:
    num = A[pos]
    pp = bisect_right(dd[num], pos)
    if pp < len(dd[num]):
        pos = dd[num][pp]+1
    else:
        ans.append(num)
        pos += 1
print(*ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from bisect import bisect_right

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

dd = defaultdict(list)
for i, j in enumerate(A):
    dd[j].append(i)

pos = 0
loop = 1
# l = []
cic = defaultdict(list)

while pos < N:
    num = A[pos]
    
    pp = bisect_right(dd[num], pos)
    if pp < len(dd[num]):
        pos = dd[num][pp]+1
    else:
        pos = dd[num][0]+1            
        loop += 1
    # l.append((pos, loop))
    cic[loop].append(pos)

# for pos, v in l:
#     if (K-v)%loop==0:
#         break

if cic[K%loop]:
    print()
else:
    pos = cic[K%loop][0] #pos if pos<N else 0
    ans = []
    while pos < N:
        num = A[pos]
        pp = bisect_right(dd[num], pos)
        if pp < len(dd[num]):
            pos = dd[num][pp]+1
        else:
            ans.append(num)
            pos += 1
    print(*ans)