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

Fixed submission:
N=int(input())
abc=[tuple(map(int,input().split())) for i in range(N-1)]
g=[set() for i in range(N)]
for a,b,c in abc:
  g[a-1].add((b-1,c))
  g[b-1].add((a-1,c))
memo=[-1]*N

Q,K=map(int,input().split())
import collections
q=collections.deque([(K-1,0)])
memo[K-1]=0
while(q):
  
  x,w = q.popleft()
  for a,b in g[x]:
    if memo[a]==-1:
      memo[a]=w+b
      q.append((a,w+b))
  
for i in range(Q):
  x,y=map(int,input().split())
  print(memo[x-1]+memo[y-1])

Buggy submission (verdict: Runtime Error):
N=int(input())
abc=[tuple(map(int,input().split())) for i in range(N-1)]
g=[set() for i in range(N)]
for a,b,c in abc:
  g[a-1].add((b-1,c))
  g[b-1].add((a-1,c))
memo=[0]*N
memo[K-1]=0
Q,K=map(int,input().split())
import collections
q=collections.deque([(K-1,0)])
while(q):
  x,w = q.popleft()
  for a,b in g[x]:
    if memo[a]==-1:
      memo[a]=w+b
      q.append((a,w+b))
  
for i in range(Q):
  x,y=map(int,input().split())
  print(memo[a-1]+memo[b-1])
Problem p03745 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
flag=0
ans=1
for i in range(1,N):
  if flag== 0:
    if a[i]>a[i-1]:
      flag=1
      continue
    elif a[i]<a[i-1]:
      flag=-1
      continue
    else:
      continue
  elif flag>0:
    if a[i]<a[i-1]:
      ans+=1
      flag=0
  else:
    if a[i]>a[i-1]:
      ans+=1
      flag=0
print(ans)

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


diff = [A[i+1] - A[i] for i in range(N-1) if A[i+1]-A[i] != 0]
ans = 1
prev = diff[0]
id = 0
while(id < len(diff)-2):
    if (diff[id]*diff[id+1]) < 0:
        ans += 1
        id += 2
    else:
        id += 1

if diff[-1]*diff[-2] < 0 and diff[-2]*diff[-3]:
    ans += 1
print(ans)

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


diff = [A[i+1] - A[i] for i in range(N-1) if A[i+1]-A[i] != 0]
ans = 1
prev = diff[0]
id = 0
while(id < len(diff)-2):
    if (diff[id]*diff[id+1]) < 0:
        ans += 1
        id += 2
    else:
        id += 1

if diff[-1]*diff[-2] < 0:
    ans += 1
print(ans)

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


diff = [A[i+1] - A[i] for i in range(N-1) if A[i+1]-A[i] != 0]
ans = 1
prev = diff[0]
id = 0
while(id < len(diff)-1):
    if (diff[id]*diff[id+1]) < 0:
        ans += 1
        id += 2
    else:
        id += 1
print(ans)
Problem p03804 (python)

Fixed submission:
N,M=map(int,input().split())
A=[""]*N
B=[""]*M
for i in range(N):
  A[i]=input()
for i in range(M):
  B[i]=input()
  
A_tmp=[""]*M
for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(M):
      A_tmp[k]=A[j+k][i:i+M]
    if A_tmp==B:
      print("Yes")
      exit(0)

print("No")

Buggy submission (verdict: Runtime Error):
N,M=map(int,input.split())
A=[""]*N
B=[""]*M
for i in range(N):
  A[i]=input()
for i in range(M):
  B[i]=input()
  
for i in range(N-M):
    if B[0] in A[i]:
      for j in range(1,M):
        if B[j] in A[i+j]:
          if j = M - 1:
            print("Yes")
            exit(0)
          else:
            continue
        else:
          break
          
print("No")

Buggy submission (verdict: Runtime Error):
N,M=map(int,input.split())
A=[""]*N
B=[""]*M
for i in range(N):
  A[i]=input()
for i in range(M):
  B[i]=input()
flag=False
for i in range(N-M)
    if B[0] in A[i]:
      for j in range(1,M):
        if B[j] in A[i+j]:
          if j = M - 1:
            print("Yes")
            exit(0)
          else:
            continue
        else:
          break
          
print("No")
Problem p03805 (python)

Fixed submission:
from itertools import permutations
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(M)]
g=[[False]*N for i in range(N)]
for a,b in ab:
  g[a-1][b-1]=True
  g[b-1][a-1]=True
nodes=[i for i in range(1,N)]
ans=0
for route in permutations(nodes):
  if g[0][route[0]]== False:
    continue
  for i in range(N-1):
    if i == N-2:
      ans+=1
      
      break
    elif g[route[i]][route[i+1]]:
      continue
    else:
      break
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import permutation
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(M)]
g=[[False]*N for i in range(N)]
for a,b in ab:
  g[a-1][b-1]=True
  g[b-1][a-1]=True
nodes=[i for i in range(N)]
ans=0
for route in permutation(nodes):
  for i in range(N):
    if i == N-1:
      ans+=1
      break
    if g[route[i]][route[i+1]]:
      continue
    else:
      break
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
ab=[[0]*8]*8
a=[0]*M
b=[0]*M

reached=[0]*M

for i in range(M):
  a[i],b[i]=map(int,input().split())
  ab[a[i]-1][b[i]-1]=1
  ab[b[i]-1][a[i]-1]=1
    
def rootCount(pos,N,reached):
  count=0
  prev=0
  finish=1
  for i in range(N):
    if reached[i] == 0:
      finish=0
  if finish==1:
    return 1
    
  
  for i in range(1,N):
    if ab[pos][i]==0:
      continue
    if reached[i]==1:
      continue
    reached[i]=1
    count+=rootCount(i,N,reached)
    reached[i]=0
  return(count)

reached[0]=1
count=rootCount(0,N,reached)
print(count)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
ab=[[0]*8]*8
a=[0]*M
b=[0]*M

reached=[0]*M

for i in range(M):
  a[i],b[i]=map(int,input().split())
  ab[a[i]-1][b[i]-1]=1
  ab[b[i]-1][a[i]-1]=1
    
def rootCount(pos,N,reached):
  count=0
  prev=0
  finish=1
  for i in range(N):
    if reached[i] == 0:
      finish=0
  if finish==1:
    return 1
    
  
  for i in range(N):
    if ab[pos][i]==0:
      continue
    if reached[i]==1:
      continue
    reached[i]=1
    count+=rootCount(i,N,reached)
    reached[i]=0
  return(count)

reached[0]=1
count=rootCount(0,N,reached)
print(count)

Buggy submission (verdict: Runtime Error):

N,M=map(int,input().split())
ab=[[0]*M]*M
a=[0]*M
b=[0]*M

reached=[0]*M

for i in range(M):
  a[i],b[i]=map(int,input().split())
  ab[a[i]][b[i]]=1
  ab[b[i]][a[i]]=1
    
def rootCount(pos,N,reached):
  count=0
  prev=0
  for i in range(N):
    if ab[pos][i]==0:
      continue
    if reached[i]==1:
      continue
    reached[i]=1
    count+=rootCount(i,N,reached)
    reached[i]=0
  return(count)

reached[0]=1
count=rootCount(0,N,reached)
print(count)
Problem p03839 (python)

Fixed submission:
N,K=map(int,input().split())
a=list(map(int,input().split()))
ans=0
tmp=0
sa=[0]*(N+1)
A=[0]*(N+1)
for i in range(N):
  sa[i+1]=sa[i]+a[i]
  if a[i]>0:
    A[i+1]=A[i]+a[i]
  else:
    A[i+1]=A[i]
for i in range(N-K+1):
  tmp=sa[i+K]-sa[i]
  tmp2=A[i]+(A[-1]-A[i+K])
  #print(max(0,tmp),tmp2)
  if max(0,tmp)+tmp2>ans:
    ans=max(0,tmp)+tmp2
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
a=list(map(int,input().split()))
ans=0
tmp=0
for i in range(N):
  if i < K:
    tmp+=a[i]
  else:
    if a[i]>0:
      ans+=a[i]
ans+=max(0,tmp)

ans2=0
tmp=0
for i in range(N-1,-1,-1):
  if ans < N-K:
    if a[i]>0:
      ans2+=a[i]
  else:
    tmp+=a[i]
ans2+=max(0,tmp)
print(max(ams2,ans))
Problem p03986 (python)

Fixed submission:
X = input()
Y = []
for i in X:
    Y.append(i)
    if len(Y) > 1:
        if Y[-2] + Y[-1] == "ST":
            Y.pop()
            Y.pop()
print(len(Y))

Buggy submission (verdict: Runtime Error):
X = input()
X = list(X)
prev = ""
for i in range(len(X) - 1):
    if X[i] + X[i + 1] == "ST":
        a = X.pop(i + 1)
        b = X.pop(i)
        X = [b,a].extend(X)

for i in range(0, len(X)):
    if X[len(X) - (i+1)] == "T":
        print(i * 2)
        break
Problem p02951 (python)

Fixed submission:
A, B, C = list(map(int, input().strip().split(' ')))
 
print(max(C - (A - B), 0))

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

keta = len(str(N))

count = 0
  
for i in range(1, keta, 2):
  count += (10 ** i)
  
if (keta  % 2) != 0:
  count += (N - 10 ** (keta - 1) + 1)
  
if N >= 10:
  count -= 1
  
print(count)

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

keta = len(str(N))

count = 0
  
for i in range(1, keta, 2):
  count += (10 ** i)
  
if (keta  % 2) != 0:
  count += (N - 10 ** (keta - 1) + 1)
  
if N >= 10:
  count -= 1
  
print(count)
Problem p02711 (python)

Fixed submission:
N=input()
if '7' in N:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N=int(input())
a=int(N/100)
b=int((N-a*100)/10)
c=int(N-100*a-10*b)
l=int()
if a*b*c==7l:
    print('yes')
else:
    print('no')
Problem p02729 (python)

Fixed submission:
n,m=map(int,input().split())
print(int((n*(n-1)+m*(m-1))/2))

Buggy submission (verdict: Runtime Error):
N,M=input().split()
print((N*N-1+M*M-1)/2)
Problem p02835 (python)

Fixed submission:
A_1,A_2,A_3=map(int,input().split())
if A_1+A_2+A_3>=22:
    print("bust")
if A_1+A_2+A_3<=21:
    print("win")

Buggy submission (verdict: Runtime Error):
A_1=int(input())
A_2=int(input())
A_3=int(input())
if A_1+A_2+A_3>=22:
    print("bust")
if A_1+A_2+A_3<=21:
    print("win")

Buggy submission (verdict: Runtime Error):
A_1=int(input())
A_2=int(input())
A_3=int(input())
if A_1+A_2+A_3>=22:
    print("bust")
if A_1+A_2+A_3<=21:
    print("bust")
Problem p02860 (python)

Fixed submission:
n=int(input())
s=input()
a=(s[0:int(n/2)])
b=(s[int(n/2):n])
if n%2==0:
    if a==b:
        print('Yes') 
    else:
        print('No')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
if type(n/2)=='int':
    if s[0:n/2]=s[n/2:n]:
        print('Yes')
    else:
        print('No')
else:
    print('No')
Problem p02781 (python)

Fixed submission:
def nCr(n,r):
  ret = 1
  for i in range(r):
    ret *= n-i
    ret /= i+1
  return ret

def top(N,K):
  if K == 0:
    return 1
  L = len(N)
  ans = 0
  if L < K:
    return 0
  else:
    ans += nCr(L-1,K) * 9 ** K

    u = int(N[0])
    z = N.count('0')
    o = N.count('1')
    f = 0
    if z + o == L:
      f = 1
    if f == 0:
      ans += (u - 1) * nCr(L-1,K - 1) * 9 ** (K - 1)
      if L == 1:
        return ans + 1
      else:
        return ans + top(str(int(N[1:])),K - 1)
    else:
      if len(str(int(N[1:]))) != 1:
        return ans + top(str(int(N[1:])),K - 1)
      else:
        if o >= K:
          return ans + 1
        else:
          return ans

N = str(input())
K = int(input())

print(int(top(N,K)))

Buggy submission (verdict: Runtime Error):
def nCr(n,r):
  ret = 1
  for i in range(r):
    ret *= n-i
    ret /= i+1
  return ret

def top(N,K):
  if K == 0:
    return 1
  L = len(N)
  ans = 0
  if L < K:
    return 0
  else:
    ans += nCr(L-1,K) * 9 ** K

    u = int(N[0])
    z = N.count('0')
    o = N.count('1')
    f = 0
    if z + o == L:
      f = 1
    if f == 0:
      ans += (u - 1) * nCr(L-1,K - 1) * 9 ** (K - 1)
      return ans + top(str(int(N[1:])),K - 1)
    else:
      if len(str(int(N[1:]))) != 1:
        return ans + top(str(int(N[1:])),K - 1)
      else:
        if o >= K:
          return ans + 1
        else:
          return ans

N = str(input())
K = int(input())

print(int(top(N,K)))

Buggy submission (verdict: Runtime Error):
def nCr(n,r):
  ret = 1
  for i in range(r):
    ret *= n-i
    ret /= i+1
  return ret

def top(N,K):
  if K == 0:
    return 1
  L = len(N)
  ans = 0
  if L < K:
    return 0
  else:
    ans += nCr(L-1,K) * 9 ** K

    u = int(N[0])
    if int(N) % u * 10 ** (L-1) != 0 or u != 1:
      ans += (u - 1) * nCr(L-1,K - 1) * 9 ** (K - 1)
      return ans + top(str(N[1:]),K - 1)
    else:
      return ans

N = str(input())
K = int(input())

print(int(top(N,K)))

Buggy submission (verdict: Runtime Error):
def nCr(n,r):
  ret = 1
  for i in range(r):
    ret *= n-i
    ret /= i+1
  return ret

def top(N,K):
  if K == 0:
    return 1
  L = len(N)
  ans = 0
  if L < K:
    return 0
  else:
    ans += nCr(L-1,K) * 9 ** K

    u = int(N[0])
    if int(N) % u * 10 ** (L-1) != 0:
      ans += (u - 1) * nCr(L-1,K - 1) * 9 ** (K - 1)
      return ans + top(str(N[1:]),K - 1)
    else:
      return ans

N = str(input())
K = int(input())

print(int(top(N,K)))
Problem p02769 (python)

Fixed submission:
n, k = map(int, input().split())
mod = 10**9+7
def make_fact(n):#0~nの階乗を求める
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i%mod
    return fact
fact = make_fact(n*2) #＠
def make_fact_inv(n):#0~nの階乗のmodに関する逆元を求める
    fact_inv = [1]*(n+1)
    fact_inv[n] = pow(fact[n], mod-2, mod)#フェルマーの小定理
    for i in range(n, 0, -1):
        fact_inv[i-1] = fact_inv[i]*i%mod
    return fact_inv
fact_inv = make_fact_inv(n*2)#＠
def comb(n, k):#nCk
    return fact[n]*fact_inv[k]*fact_inv[n-k]%mod
mod = 10**9+7
ans = 0
for i in range(n):
    m = n-i
    c = n-m
    if c+i>k*2:
        continue
    ans+=comb(n, i)*comb(m+c-1, m-1)%mod
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
def make_fact(n):#0~nの階乗を求める
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i%mod
    return fact
fact = make_fact(n*2) #＠
def make_fact_inv(n):#0~nの階乗のmodに関する逆元を求める
    fact_inv = [1]*(n+1)
    fact_inv[n] = pow(fact[n], mod-2, mod)#フェルマーの小定理
    for i in range(n, 0, -1):
        fact_inv[i-1] = fact_inv[i]*i%mod
    return fact_inv
fact_inv = make_fact_inv(n*2)#＠
def comb(n, k):#nCk
    return fact[n]*fact_inv[k]*fact_inv[n-k]%mod
mod = 10**9+7
ans = 0
for i in range(n):
    m = n-i
    c = n-m
    if c+i>k*2 or (c+i)%2 != k%2:
        continue
    ans+=comb(n, i)*comb(m+c-1, m-1)%mod
    ans%=mod
print(ans)
Problem p02793 (python)

Fixed submission:
mod = 10**9+7
def fctr(n): 
    res=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            res.append([i,c])
            c=0
    if n!=1:
        res.append([n,1])
    return res
N = int(input())
A = list(map(int, input().split()))
A_inv = [pow(a, mod-2, mod) for a in A]
primes = [0]*(10**6+1)
for a in A:
    res = fctr(a)
    for i, c in res:
        primes[i] = max(primes[i], c)
m = 1
for i in range(1, 10**6+1):
    c = primes[i]
    m*=pow(i, c, mod)
    m%=mod
ans = 0
for a in A_inv:
    ans+=m*a
    ans%=mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 10**9+7
def fctr(n): 
    res=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            res.append([i,c])
            c=0
    if n!=1:
        res.append([n,1])
    return res
N = int(input())
A = list(map(int, input().split()))
A_inv = [pow(a, mod-2, mod) for a in A]
primes = [0]*(10**4+1)
for a in A:
    res = fctr(a)
    for i, c in res:
        primes[i] = max(primes[i], c)
m = 1
for i in range(1, 10**4+1):
    c = primes[i]
    m*=pow(i, c, mod)
    m%=mod
ans = 0
for a in A_inv:
    ans+=m*a
    ans%=mod
print(ans)
Problem p02834 (python)

Fixed submission:
import sys
#input = sys.stdin.readline
from collections import deque
N, u, v = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
v-=1
u-=1
que = deque([v])
par = [-1]*N
depth = [-1]*N
depth[v] = 0
while que:
    i = que.popleft()
    d = depth[i]
    for nv in G[i]:
        if depth[nv]>=0:
            continue
        depth[nv] = d+1
        par[nv] = i
        que.append(nv)
d = depth[u]
now = u
m = 0
que = deque([now])
while que:
    i = que.pop()
    m = max(m, depth[i])
    for nv in G[i]:
        if depth[nv]<depth[i]:
            continue
        que.append(nv)
for i in range(d//2):
    pp = par[now]
    que = deque([pp])
    while que:
        i = que.pop()
        m = max(m, depth[i])
        for nv in G[i]:
            if depth[nv]<depth[i] or nv == now:
                continue
            que.append(nv)
    now = pp
print(m-1)

Buggy submission (verdict: Runtime Error):
import sys
#input = sys.stdin.readline
from collections import deque
N, u, v = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
v-=1
u-=1
que = deque([v])
par = [-1]*N
depth = [-1]*N
depth[v] = 0
while que:
    i = que.popleft()
    d = depth[i]
    for nv in G[i]:
        if depth[nv]>=0:
            continue
        depth[nv] = d+1
        par[nv] = i
        que.append(nv)
d = depth[u]
now = u
m = 0
que = deque([now])
while que:
    i = que.pop()
    m = max(m, depth[i])
    for nv in G[i]:
        if depth[nv]<depth[i]:
            continue
        que.append(nv)
for i in range(d//2):
    pp = par[now]
    que = deque([p])
    while que:
        i = que.pop()
        m = max(m, depth[i])
        for nv in G[i]:
            if depth[nv]<depth[i] or nv == pp:
                continue
            que.append(nv)
    now = pp
print(m-1)
Problem p02914 (python)

Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())), dtype = np.int64)
a = np.bitwise_xor.reduce(A)
for i in range(60):
    bit = 1<<i
    if bit & a:
        A^=(A&bit)
for k in range(60, -1, -1):
    bit = 1<<k
    one = (A&bit != 0)
    i = np.where(one & (A < (1<<(k+1))))[0]
    if len(i) == 0:
        continue
    i = i[0]
    x = A[i]
    A[one]^=x
    A[i] = x
b = np.bitwise_xor.reduce(A)
a^=b
print(a+b)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
a = np.bitwise_xor.reduce(A)
A^=a
for k in range(60, -1, -1):
    bit = 1<<k
    one = (A&bit != 0)
    i = np.where(one & (A < (1<<(k+1))))[0]
    if len(i) == 0:
        continue
    i = i[0]
    x = A[i]
    A[one]^=x
    A[i] = x
b = np.bitwise_xor.reduce(A)
a^=b
print(a+b)

Buggy submission (verdict: Runtime Error):
import numpy as np
from numpy.fft import fft, ifft
from bisect import bisect_left
import sys
Max = 10**6
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = np.zeros(Max+1)
D = np.zeros(Max+1)
for a in A:
    C[a] +=1
for b in B:
    D[b]+=1
L = 2**8
res = ifft(fft(C, L)*fft(D, L))
res = np.where(res>1.5)
if res[0].size == 0:
    print(-1)
    sys.exit()
res = res[0][-1]
B.sort()
ans  = []
for i, a in enumerate(A):
    j = bisect_left(B, res-a)
    b = B[j]
    if b == res-a:
        ans.append(i)
        ans.append(j)
    if len(ans) == 4:
        break
if len(ans) < 4:
    print(liahbcon)
print(*ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from numpy.fft import rfft, irfft
from bisect import bisect_left
import sys
Max = 10**6
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = np.zeros(Max+1)
D = np.zeros(Max+1)
for a in A:
    C[a] +=1
for b in B:
    D[b]+=1
L = 2**8
res = irfft(rfft(C, L)*rfft(D, L))
res = np.where(res>1.4)
if res[0].size == 0:
    print(ahfkgashg)
    sys.exit()
res = res[0][-1]
B.sort()
ans  = []
for i, a in enumerate(A):
    j = bisect_left(B, res-a)
    b = B[j]
    if b == res-a:
        ans.append(i)
        ans.append(j)
    if len(ans) == 4:
        break
if len(ans) < 4:
    print(liahbcon)
print(*ans)
Problem p02955 (python)

Fixed submission:
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()))
m = sum(A)
divisors = make_divisors(m)
for d in divisors:
    A1 = list(map(lambda x:x%d, A))
    A1.sort()
    res = 0
    index = N
    for i in range(N):
        res+=A1[i]
        if res>K:
            res-=A1[i]
            index = i
            break
    
    res1 = 0
    for i in range(index, N):
        res1+=d-A1[i]
    if res>=res1:
        ans = d
        break
print(ans)

Buggy submission (verdict: Runtime Error):
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()))
m = sum(A)
divisors = make_divisors(m)
for d in divisors:
    A1 = list(map(lambda x:x%d, A))
    A1.sort()
    res = 0
    for i in range(N):
        res+=A1[i]
        if res>K:
            res-=A1[i]
            index = i+1
            break
    res1 = 0
    for i in range(index, N):
        res1+=d-A1[i]
    if res>=res1:
        ans = d
        break
print(ans)
Problem p03003 (python)

Fixed submission:
mod = 10**9+7
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(M+1) for _ in range(N+1)]
dp[0][0] = 1
Sum = [[1]*(M+1) for _ in range(N+1)]
for i in range(1, N+1):
    for j in range(1, M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = Sum[i-1][j-1]%mod
        else:
            dp[i][j] = 0
        Sum[i][j] = (Sum[i-1][j]+Sum[i][j-1]-Sum[i-1][j-1]+dp[i][j])%mod
print(Sum[N][M]%mod)

Buggy submission (verdict: Runtime Error):
mod = 10**9+7
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
memo = [[-1]*(M+1) for _ in range(N)]
List = [[]for _ in range(N)]

for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            List[i].append(j)
def dp(i, j):
    if i==N-1:
        cnt = 0
        for k in List[i]:
            if j<k:
                cnt+=1
        return (cnt+1)%mod
    res = 0
    for k in List[i]:
        if j<k:
            if memo[i+1][k]<0:
                memo[i+1][k]=dp(i+1, k)
            res+=memo[i+1][k]
    if memo[i+1][j]<0:
        memo[i+1][j]=dp(i+1, j)
    res+=memo[i+1][j]
    return res%mod
print(dp(0, -1)%mod)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
memo = [[-1]*(M+1) for _ in range(N)]
List = [[]for _ in range(N)]

for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            List[i].append(j)
def dp(i, j):
    if i==N-1:
        cnt = 0
        for k in List[i]:
            if j<k:
                cnt+=1
        return (cnt+1)%mod
    res = 0
    for k in List[i]:
        if j<k:
            if memo[i+1][k]<0:
                memo[i+1][k]=dp(i+1, k)
            res+=memo[i+1][k]
    if memo[i+1][j]<0:
        memo[i+1][j]=dp(i+1, j)
    res+=memo[i+1][j]
    return res%mod
print(dp(0, -1)%mod)
Problem p03013 (python)

Fixed submission:
def solve():
    mod = 10**9+7
    N, M = map(int, input().split())
    k = [0]*(N+1)
    if M==0:
        k[0]=1
        k[1]=1
        for i in range(2, N+1):
            k[i]=(k[i-1]+k[i-2])%mod
        print(k[N]%mod)
        return
    a = [int(input()) for _ in range(M)]
    k[0]=1
    cnt = 0
    if a[0]!=1:
        k[1]=1
    else:
        cnt+=1
    for i in range(2, N+1):
        if cnt<M and i ==a[cnt]:
            cnt+=1
            continue
        else:   
            k[i]=(k[i-1]+k[i-2])%mod
    print(k[N]%mod)
    return
solve()

Buggy submission (verdict: Runtime Error):
mod = 10**9+7
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
k = [0]*(N+1)
k[0]=1
cnt = 0
if a[0]!=1:
    k[1]=1
else:
    cnt+=1
for i in range(2, N+1):
    if cnt<M and i ==a[cnt]:
        cnt+=1
        continue
    else:
        k[i]=k[i-1]+k[i-2]
print(k[N]%mod)