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

Fixed submission:
import math
import numpy as np
import sys
import os
from operator import mul
from operator import itemgetter

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N,M = LI()
H = LI()
AB = [LI() for _ in range(M)]

p = []
d = {}
for i in range(N):
    # p.append((i,H[i]))
    d[i]=H[i]
# p.sort(key=itemgetter(1),reverse=True)
# print(p)
# print(d)

# g = np.zeros(shape=(N,N),dtype='int')
g = [set()] * N
a = [True] * N

for i in range(M):
    f = AB[i][0]-1
    t = AB[i][1]-1
    if d[t]>d[f]:
        a[f]=False
    elif d[f]>d[t]:
        a[t]=False
    else:
        a[f]=False
        a[t]=False
# print(a)
print(sum(a))  
    # print(g[f])
    # g[f] = np.append(g[f],t)
    # g[t] = np.append(g[t],f)
   
    # g[f][t]=1
    # g[t][f]=1

# print(g)
# list.sort(key=itemgetter(0))

# for i in range(N):


# a = np.where(g[0]==1)
# print(a)

Buggy submission (verdict: Runtime Error):
import math
import numpy as np
import sys
import os
from operator import mul
from operator import itemgetter
from collections import defaultdict as D


sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N,M = LI()
H = LI()
AB = [LI() for _ in range(M)]

obs = [(i-1,h) for i,h in enumerate(H)]
obs.sort(key=itemgetter(1),reverse=True)

seenFromHigher = set()

roads = D(set)

for i in range(M):
    f = AB[i][0]-1
    t = AB[i][1]-1
    roads[f].add(t)
    roads[t].add(f)

ans = 0
for ob in obs:
    if not (ob[0] in seenFromHigher):
        isHighest = True
        for i in roads[ob[0]]:
            seenFromHigher.add(i)
            if ob[1] < H[i]:
                isHighest = False 
        if isHighest:
            ans += 1

print(ans)

# p = []
# d = {}
# for i in range(N):
#     d[i]=H[i]

# # g = np.zeros(shape=(N,N),dtype='int')
# g = [set()] * N
# a = [True] * N

# for i in range(M):
#     f = AB[i][0]-1
#     t = AB[i][1]-1
#     if d[t]>d[f]:
#         a[f]=False
#     elif d[f]>d[t]:
#         a[t]=False
#     else:
#         a[f]=False
#         a[t]=False
# print(sum(a))
Problem p02759 (python)

Fixed submission:
n = int(input())

p = n % 2 + n // 2

print(p)

Buggy submission (verdict: Runtime Error):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
if M == 0:
    print([0, 10, 100][N - 1])
    exit()
m = map(int, read().split())
S, C = zip(*zip(m, m))

def test(n):
    st = str(n)
    if len(st) != N:
        return False
    for i, c in zip(S, C):
        i -= 1
        if st[i] != str(c):
            return False
    return True

def main():
    for n in range(1000):
        if test(n):
            return n
    return -1

print(main())
Problem p02773 (python)

Fixed submission:
import sys 
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
l = read().decode().split()
c = Counter(l)

max = c.most_common()[0][1]
ans = [i[0] for i in c.items() if i[1] >= max]

print('\n'.join(sorted(ans)))

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())

S = []
for _ in range(N):
    S.append(input())

c = collections.Counter(S)
c1 = c.most_common()

# print(c1[0][0])

tmp = []
for i in range(len(c1)):
    tmp.append(c1[i][0])
    print(sorted(tmp))
    if (c1[0][1] > c1[i][1]):
        break

ans = sorted(tmp)
for i in range(len(ans)):
    print(ans[i])
Problem p02881 (python)

Fixed submission:
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

# 最短距離
# 素因数分解
N = I()

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

# c = sympy.divisors(N)
c = make_divisors(N)
lenc = len(c)
if (lenc % 2)==0:
    a = c[lenc // 2 - 1]
    b = c[lenc // 2]
else:
    a = c[lenc // 2]
    b = a

print(a + b -2)

#H,N = LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
#Ap = np.array(A)
#C = np.zeros(N + 1)

# if ans:
#     print('Yes')
# else:
#     print('No')

Buggy submission (verdict: Runtime Error):
import bisect,collections,copy,heapq,itertools,math,string,sympy
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

# 最短距離
# 素因数分解
N = I()
c = sympy.divisors(N)
lenc = len(c)
if (lenc % 2)==0:
    a = c[lenc // 2 - 1]
    b = c[lenc // 2]
else:
    a = c[lenc // 2]
    b = a

print(a + b -2)

#H,N = LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
#Ap = np.array(A)
#C = np.zeros(N + 1)

# if ans:
#     print('Yes')
# else:
#     print('No')
Problem p02833 (python)

Fixed submission:
import math

N = int(input())

memo = [0]*26
for i in range(26):
    memo[i] = 5**(i+1)

if N % 2 == 0:
    ans = 0
    for j in range(26):
        ans += (N//memo[j])//2
    print(ans)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math

N_str = input()
N = int(N_str)
digit = int(math.log10(N))+1

digit = len(N_str)

memo = [0]*26
for i in range(26):
    memo[i] = 5**(i+1)

if N % 2 == 0:
    ans = 0
    for j in range(26):
        ans += (N//memo[j])//2
    print(ans)
else:
    print(0)
Problem p03013 (python)

Fixed submission:
N,M = list(map(int, input().split()))

combination = [1,1,2]
for i in range(3,N+1):
    combination.append(combination[i-1]+combination[i-2])

a = 0
ans = 1
lst = []

if M > 0:
    next_a = int(input())
    lst.append(combination[next_a-a-1])
    a = next_a
    for i in range(M-1):
        next_a = int(input())
        if next_a-a == 1:
            ans = 0
            break
        elif next_a-a == 0:
            continue
        lst.append(combination[next_a-a-2])
        a = next_a

    next_a = N
    lst.append(combination[next_a-a-1])
else:
    lst.append(combination[N])
    
for tmp in lst:
    ans *= tmp
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
N,M = list(map(int, input().split()))

combination = [1,1,2]
for i in range(3,N):
    combination.append(combination[i-1]+combination[i-2])

a = 0
ans = 1
lst = []

next_a = int(input())
lst.append(combination[next_a-a-1])
a = next_a

for i in range(M-1):
    next_a = int(input())
    if next_a-a == 1:
        ans = 0
        break
    lst.append(combination[next_a-a-2])
    a = next_a
    
next_a = N
lst.append(combination[next_a-a-1])

for tmp in lst:
    ans *= tmp
print(ans%1000000007)
Problem p03242 (python)

Fixed submission:
print(1110-int(input()))

Buggy submission (verdict: Runtime Error):
print(1110-int(input))
Problem p03745 (python)

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

ans = 0
if 2 <= N:
    isBigger = A[0] < A[1] 
    isEqual = A[0] == A[1]
    for i in range(1,N):
        if isEqual:
            if A[i] < A[i-1]:
                isBigger = False
                isEqual = False
            elif A[i-1] < A[i]:
                isBigger = True
                isEqual = False
            else:
                continue
        elif isBigger:
            if A[i] < A[i-1]:
                ans += 1
                if i < N-1:
                    isBigger = A[i] < A[i+1]
                    isEqual = A[i] == A[i+1]
                else:
                    break
        else:
            if A[i-1] < A[i]:
                ans += 1
                if i < N-1:
                    isBigger = A[i] < A[i+1]
                    isEqual = A[i] == A[i+1]
                else:
                    break

ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

isBigger = A[0] < A[1] 
isEqual = A[0] == A[1]
ans = 0
for i in range(1,N):
    if isEqual:
        if A[i] < A[i-1]:
            isBigger = False
            isEqual = False
        elif A[i-1] < A[i]:
            isBigger = True
            isEqual = False
        else:
            continue
    elif isBigger:
        if A[i] < A[i-1]:
            ans += 1
            if i < N-1:
                isBigger = A[i] < A[i+1]
                isEqual = A[i] == A[i+1]
            else:
                break
    else:
        if A[i-1] < A[i]:
            ans += 1
            if i < N-1:
                isBigger = A[i] < A[i+1]
                isEqual = A[i] == A[i+1]
            else:
                break

ans += 1
print(ans)
Problem p02757 (python)

Fixed submission:
n,p = map(int,input().split())
a = list(map(int,list(input())))
ans = 0
if p == 2:
  for i in range(n):
    if a[i]%2==0:
      ans += i+1
elif p == 5:
  for i in range(n):
    if a[i]==5 or a[i]==0:
      ans += i+1
else:
  b = 0
  c = [0 for i in range(p)]
  c[0] = 1
  for i in range(n):
    b = (b+pow(10,n-i,p)*a[i])%p
    c[b] += 1
  c = list(map(lambda x:x*(x-1)//2,c))
  ans = sum(c)
print(ans)

Buggy submission (verdict: Runtime Error):
n,p = map(int,input().split())
a = list(map(int,list(input())))
ans = 0
if p == 2:
  for i in range(n):
    if a[i]%2==0:
      ans += i+1
elif p == 5:
  for i in range(n):
    if a[i]==5 or a[i]==0:
      ans += i+1
else:
  b = 0
  c = [0 for i in range(p)]
  c[0] = 1
  for i in range(n):
    b = (b[i]+pow(a[i],n-i,p))%p
    c[b] += 1
c = list(map(lambda x:x*(x+1)//2,c))
ans = sum(c)
print(ans)
Problem p02831 (python)

Fixed submission:
import fractions
a,b = map(int,input().split())
print(a*b//fractions.gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
print(a*b//math.gcd(a,b))
Problem p03242 (python)

Fixed submission:
a = list(input())
for i in range(3):
  if a[i] == "1":
    a[i] = "9"
  else:
    a[i] = "1"
print("".join(a))

Buggy submission (verdict: Runtime Error):
a = list(input())
for i in range(3):
  if a[i] = "1":
    a[i] = "9"
  else:
    a[i] = "1"
print("".join(a))

Buggy submission (verdict: Runtime Error):
a = list(input())
for i in range(3):
  if a[i] = "1":
    a[i] = 9
  else:
    a[i] = 1
print("".join(a))
Problem p02623 (python)

Fixed submission:
import numpy as np
N,M,K = map(int, input().split())
a = np.array([0] + list(map(int, input().split())),dtype=np.int64)
b = np.array([0] + list(map(int, input().split())),dtype=np.int64)

asum = a.cumsum()
bsum = b.cumsum()

ans = 0
for ind,i in enumerate(asum):
    if i>K:
        break
    mx = np.searchsorted(bsum, K-i ,side='right') - 1
    ans = max(ans, ind + mx,)

print(ans)

Buggy submission (verdict: Runtime Error):
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dp = [[-1 for _1 in range(N+1)] for _2 in range(M+1)]
dp[0][0] = 0
for i in range(N):
    dp[0][i+1] = dp[0][i] + A[i]
for j in range(M):
    dp[j+1][0] = dp[j][0] + B[j]
#print(dp)
for m in range(1,M+1):
    for n in range(1,N+1):
        dp[m][n] = dp[m][0] + dp[0][n]
#print(dp)
ans = 0
for a in range(N+M+1):
    for b in range(a+1):
        #print(a,b,dp[M-a+b][N-b])
        if dp[M-a+b][N-b] <= K:
            ans =N+M -a
            print(ans)
            exit()
Problem p02624 (python)

Fixed submission:
import numpy as np
from numba import *

@njit('i8(i8,i8[:])', cache=True)
def solve(x,count):
    for i in range(2,x+1):
        for j in range(i,x+1,i):
            count[j] += 1
    return int(np.sum(np.arange(x+1)*count))

if __name__== "__main__":
    x = int(input())
    count = np.ones(x + 1, dtype=np.int64)
    print(solve(x,count))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit


@njit('(i8)', cache=True)
def solve(x):
    count = np.zeros(x + 1, dtype=np.int64)
    for i in range(1, x + 1):
        for j in range(i, x + 1, i):
            count[j] += j
    return count.sum()


if __name__ == "__main__":
    x = int(input())
    print(solve(x))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit
 
@njit('i8(i8)', cache=True)
def solve(x):
    count = np.ones(x + 1, dtype=np.int8)
    for i in range(2,x+1):
        for j in range(i,x+1,i)
            count[j] += 1
    return int(np.sum(np.arange(x + 1) * count))
 
if __name__== "__main__":
    x = int(input())
    print(solve(x))
Problem p02679 (python)

Fixed submission:
from collections import defaultdict
from math import gcd
N = int(input())
MOD = 10**9 + 7
L = defaultdict(lambda: [0,0])
zero = 0
for _ in range(N):
    A, B = map(int, input().split())
    if A==0: d=B
    elif B==0: d=A
    else: d=gcd(A,B)
    if d != 0:
        A, B = A//d, B//d
        if A<0: A, B = -A, -B
        if B>0: L[(A,B)][0] += 1
        else: L[(-B,A)][1] += 1
    else: zero += 1
res = 1
for x,y in L.values():
    res *= pow(2,x,MOD) + pow(2,y,MOD) -1
    res %= MOD
print((res+zero-1)%MOD)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from math import gcd
N = int(input())
MOD = 10**9 + 7
L = defaultdict(lambda: [0,0])
for _ in range(N):
    A, B = map(int, input().split())
    d = gcd(A,B)
    A, B = A//d, B//d
    if A<0:
        A, B = -A, -B
    if B>=0:
        L[(A,B)][0] += 1
    else:
        L[(-B,A)][1] += 1
res = 1
for x,y in L.values():
    res *= pow(2,x,MOD) + pow(2,y,MOD) -1
    res %= MOD
print(res-1)
Problem p02726 (python)

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

X -= 1
Y -= 1
dist = [0]*(N-1)
for i in range(N):
    for j in range(i+1, N):
        dist[min(j-i, abs(X-i) + 1 + abs(Y-j))-1] += 1

print(*dist, sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
from itertools import chain
from collections import Counter


V, X, Y = map(int, input().split())                             # V:頂点数 E:辺の数 r:始点

edge = np.array([[i,i+1,1] for i in range(1,V)] + [[X, Y,1]], dtype = np.int64).T

graph = csr_matrix((edge[2], (edge[:2] - 1)), (V, V))           # [[辺の左端],[辺の右端],[辺の距離]] の形で渡す
# graph = csr_matrix((edge[2], (edge[:2] )), (V, V))           # 番号のデクリメントが不要な場合


d = floyd_warshall(graph, directed = False)                         # 有効グラフの場合は directed = True とする。

nagativity = False                                             # 負のサイクルかどうかを判定
for i in range(V):
    if d[i][i] < 0:
        nagativity = True
if nagativity:
    print('NEGATIVE CYCLE')
else:
    d = [['INF' if i == float("inf") else int(i) for i in l ] for l in d]   # numpy.float64をintに変換し、inf をどのように記述するかを指定

res = Counter(chain.from_iterable(d))

for i in range(1,V):
    print(res.get(i,0)//2)
Problem p02757 (python)

Fixed submission:
"""
タグ：区間
"""
import sys
input = sys.stdin.readline
N, P = map(int, input().split())
S = input().strip()

if P == 5:
    res = 0
    i = 0
    for s in reversed(S):
        if int(s)%5==0:
            res += N-i
        i += 1
    print(res)
elif P == 2:
    res = 0
    i = 0
    for s in reversed(S):
        if int(s)%2==0:
            res += N-i
        i += 1
    print(res)
else:
    T = [0]
    p = 1
    for s in reversed(S):
        T.append(int(s)*p + T[-1])
        p = p*10%P

    cnt = [0]*P
    for i in range(N+1):
        cnt[T[i]%P] += 1

    res = 0
    for c in cnt:
        res += c*(c-1)//2
    print(res)

Buggy submission (verdict: Runtime Error):
"""
タグ：区間
"""
import sys
input = sys.stdin.readline
N, P = map(int, input().split())
S = input()

if P == 5:
    res = 0
    i = 0
    for s in reversed(S):
        if int(s)%5==0:
            res += N-i
        i += 1
    print(res)
elif P == 2:
    res = 0
    i = 0
    for s in reversed(S):
        if int(s)%2==0:
            res += N-i
        i += 1
    print(res)
else:
    T = [0]
    p = 1
    for s in reversed(S):
        T.append(int(s)*p + T[-1])
        p = p*10%P

    cnt = [0]*P
    for i in range(N+1):
        cnt[T[i]%P] += 1

    res = 0
    for c in cnt:
        res += c*(c-1)//2
    print(res)
Problem p02793 (python)

Fixed submission:
import sys
input = sys.stdin.readline
import math

def main():
    big = 10 ** 9 + 7

    N = int(input())
    A = list(map(int, input().split()))
    num = A[0]
    for i in range(1, N):
        num = num * A[i] // math.gcd(num, A[i])

    res = 0
    for a in A:
        res += num // a

    print(res % big)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import defaultdict


class PrimeFactor():

    def __init__(self, n):                  # エラトステネス　O(N loglog N)
        self.n = n
        self.table = list(range(n+1))
        self.table[2::2] = [2]*(n//2)
        for p in range(3, int(n**0.5) + 2, 2):
            if self.table[p] == p:
                self.table[p * p::2 * p] = [p] * ((n - p * p - 1) // (2 * p) + 1)

    def is_prime(self, x):  # 素数判定　O(1)
        if x < 2:
            return False
        return self.table[x] == x

    def prime_factors(self, x):             # 素因数分解 O(logN)
        res = []
        if x < 2:
            return res
        while self.table[x] != 1:
            res.append(self.table[x])
            x //= self.table[x]
        return res

    def prime_counter(self, x):             # 素因数分解（個数のリスト）
        res = defaultdict(int)
        if x < 2:
            return res
        while self.table[x] != 1:
            res[self.table[x]] += 1
            x //= self.table[x]
        return res

    def prime_gcd(self, X):                 # n個の最大公約数　X:n個のリスト
        exponents = self.prime_counter(X[0])
        for x in X[1:]:
            Y = self.prime_counter(x)
            for prime, exp in exponents.items():
                if Y[prime] < exp:
                    exponents[prime] = Y[prime]
        res = 1
        for prime, exp in exponents.items():
            res *= pow(prime, exp)
        return res

    def prime_lcm(self, X, mod=None):       # n個の最小公倍数　X:n個のリスト
        exponents = defaultdict(int)
        for x in X:
            for prime, exp in self.prime_counter(x).items():
                if exp > exponents[prime]:
                    exponents[prime] = exp
        res = 1
        for prime, exp in exponents.items():
            res *= pow(prime, exp, mod)
        if mod == None:
            return res
        else:
            return res % mod

mod = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
A.sort()
table = PrimeFactor(A[-1])
num = table.prime_lcm(A,mod)

res = 0
for a in A:
    res += num * pow(a, mod - 2, mod)

print(res % mod)
Problem p02851 (python)

Fixed submission:
from itertools import accumulate
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = accumulate([0]+ A)
C = [(b-i)%K for i, b in enumerate(B)]
cnt = defaultdict(int)
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
    if i >= K:
        cnt[C[i-K]] -= 1
    res += cnt[C[i]]
    cnt[C[i]] += 1
print(res)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = accumulate([0]+ A)
C = [(b-i)%K for i, b in enumerate(B)]
cnt = [0]*N
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
    if i >= K:
        cnt[C[i-K]] -= 1
    res += cnt[C[i]]
    cnt[C[i]] += 1
print(res)
Problem p02955 (python)

Fixed submission:
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):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    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])

Buggy submission (verdict: Runtime Error):
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):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    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

print(D[binary_search_int(0,len(D),test)])
Problem p03346 (python)

Fixed submission:
N = int(input())
P, Q = [], [0]*(N+1)
for i in range(1,N+1):
    p = int(input())
    P.append(p)
    Q[p] = i
Q.append(0)
cnt = 1
res = []
for i in range(1,N+1):
    if Q[i] < Q[i+1]:
        cnt += 1
    else:
        res.append(cnt)
        cnt = 1
if res:
    print(N-max(res))
else:
    print(N)

Buggy submission (verdict: Runtime Error):
N = int(input())
P, Q = [], [0]*(N+1)
for i in range(1,N+1):
    p = int(input())
    P.append(p)
    Q[p] = i
cnt = 1
res = []
for i in range(1,N):
    if Q[i] < Q[i+1]:
        cnt += 1
    else:
        res.append(cnt)
        cnt = 1
print(N-max(res))
Problem p02571 (python)

Fixed submission:
# B

S=input()
T=input()

def check(i,T):
    ns=S[i:i+len(T)]
    res=0
    for i in range(len(T)):
        if ns[i]!=T[i]:
            res+=1
    return res

print(min([check(i,T) for i in range(len(S)-len(T)+1)]))

Buggy submission (verdict: Runtime Error):
# B

S=input()
T=input()

def check(i,T):
    ns=S[i:i+len(T)]
    res=0
    for i in range(len(T)):
        if ns[i]!=T[i]:
            res+=1
    return res

print(min([check(i,T) for i in range(len(S)-len(T))]))
Problem p02597 (python)

Fixed submission:
# ABC174 D
import sys
sys.setrecursionlimit(3*10**5)

N=int(input())
S=input()

def search(l,r):
    # 半開区間
    if l==r:
        return 0
    if S[l]=='R':
        return search(l+1,r)
    if S[r-1]=='W':
        return search(l,r-1)
    return search(l+1,r-1)+1
print(search(0,N))

Buggy submission (verdict: Runtime Error):
# ABC174 D

N=int(input())
S=input()

def search(s):
    if s=='':
        return 0
    if s[0]=='R':
        return search(s[1:])
    if s[-1]=='W':
        return search(s[:-1])
    return search(s[1:-1])+1
print(search(S))