Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
import queue
def main():
    input=sys.stdin.readline
    n,x,y=map(int,input().split())
    edge=[]
    for i in range(int(n)):
        tmp=[0 if i==j else 1 if abs(i-j)==1 else -1 for j in range(n)]
        edge.append(tmp)
    edge[x-1][y-1]=1
    edge[y-1][x-1]=1
    step=[0]*n#ある歩数の点の選び方をカウントする
    def bfs(start,graph,step):
        kyori={}#スタートからある点までの距離をある点をキーとして入れる
        que_check=[0]*n#queueに入ったかを記録する
        Tovis=queue.Queue()#探索待ちの点を入れるキュー
        Tovis.put(start)
        que_check[start]=1
        kyori[start]=0        
        while Tovis.empty()==False:            
            nex=Tovis.get()            
            for v in range(n):                
                tmp=graph[nex][v]
                if tmp!=-1:                    
                    if que_check[v]==1:
                        continue
                    Tovis.put(v)
                    que_check[v]=1
                    res=kyori[nex]+1
                    kyori[v]=res#点ｖまでの距離はその前に通った点までの距離+1
                    step[res]+=0.5#i->j j->iの二回数えてしまうので
    for i in range(n):
        bfs(i,edge,step)
    for i in range(1,len(step)):
        print(int(step[i]))
if __name__ == '__main__':
    main()       


Fixed submission:
s=input()

x=1
if s[2]!=s[3]:
    x=0
    
if s[4]!=s[5]:
    x=0
    
        
if x==1:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n,x,y=map(int,input().split())
edge=[]
for i in range(int(n)):
    tmp=[0 if i==j else 1 if abs(i-j)==1 else -1 for j in range(n)]
    edge.append(tmp)
edge[x-1][y-1]=1
edge[y-1][x-1]=1
step=[0 for i in range(n)]#ある歩数の点の選び方をカウントする
def bfs(start,graph,step):
    kyori={}#スタートからある点までの距離をある点をキーとして入れる
    num=0
    Tovis=[start]
    kyori[start]=0
    visited=[]
    while Tovis:
        nex=Tovis.pop(0)
        visited.append(nex)
        for v in range(len(graph[nex])):
            tmp=graph[nex][v]
            if tmp!=-1:
                if v in visited:
                    continue
                if  v in Tovis:
                    continue
                Tovis.append(v)
                kyori[v]=kyori[nex]+1#点ｖまでの距離はその前に通った点までの距離+1
                step[kyori[v]]+=0.5#i->j j->iの二回数えてしまうので
for i in range(n):
    bfs(i,edge,step)
for i in range(1,len(step)):
    print(int(st

Fixed submission:
s=input()

x=1
if s[2]!=s[3]:
    x=0
    
if s[4]!=s[5]:
    x=0
    
        
if x==1:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
def gaus(n):
    if n//1<n:
        return int(n+1)
    return int(n)
def hante(S):
    n=len(S)
    for i in range(n//2):
        if S[i]!=S[n-i]:
            return False
    return True
S=input()
S1=S[:len(S)//2]
S2=S[gaus(len(S)/2):]
if hante(S1)==True and hante(S2)==True:
    print("Yes")
print("No")


Fixed submission:
def gaus(n):
    if n//1<n:
        return int(n+1)
    return int(n)
def hante(S):
    n=len(S)
    for i in range(n//2):
        if S[i]!=S[n-i-1]:
            return False
    return True
S=input()
S1=S[:len(S)//2]
S2=S[gaus(len(S)/2):]

if hante(S)==True and hante(S1)==True and hante(S2)==True:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
A=list(map(int,input().split()))
while m>0:
    max=0
    num=0
    for i in range(n):
        if A[i]>max:
            max=A[i]
            num=i
    A[num]=A[num]/2
   # print(num+1)
    m+=-1
sum=0
for a in A:
    #print(a)
    sum+=(a//1)
print(int(sum))
    


Fixed submission:
import heapq
n,m=map(int,input().split())
def func(x):
    return -1*int(x)
A=list(map(func,input().split()))
#print(A)
heapq.heapify(A)
while m>0:
    x=heapq.heappop(A)
    x/=2
    heapq.heappush(A,x)
    m+=-1
sum=0
for a in A:
    #print((-1*a)//1)
    sum+=((-1*a)//1)
print(int(sum))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=0
for i in range(n):
  x+=i
print(x)
  

Fixed submission:
n=int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
cnt = 0
for r in range(3000):
  for g in range(3000):
    v = R * r + G * g
    if N >= v and (N - v) % B == 0:
      cnt += 1
print(cnt)

Fixed submission:
R, G, B, N = map(int, input().split())
rmax = N // R
gmax = N // G
cnt = 0
for r in range(rmax + 1):
  for g in range(gmax + 1):
    rest = N - R * r - G * g
    if rest >= 0 and rest % B == 0:
      cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
rmax = N // R
gmax = N // G
cnt = 0
for r in range(rmax + 1):
  for g in range(gmax + 1):
    rest = N - R * r - G * g
    if rest >= 0 and rest % B == 0:
      cnt += 1
print(cnt)

Fixed submission:
R, G, B, N = map(int, input().split())
rmax = N // R
gmax = N // G
cnt = 0
for r in range(rmax + 1):
  for g in range(gmax + 1):
    rest = N - R * r - G * g
    if rest >= 0 and rest % B == 0:
      cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
  while y:
    x, y = y, x % y
  return x

N = int(input())
A = list(map(int, input().split()))
M = []
for i in range(N):
  AA = A[:i] + A[i + 1:]
  g = 0
  for j in range(len(AA)):
    g = gcd(g, AA[j])
  M.append(g)
print(max(M))

Fixed submission:
def gcd(x, y):
  while y:
    x, y = y, x % y
  return x

N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
M = [0] * N
L[0] = 0
for i in range(N - 1):
  L[i + 1] = gcd(L[i], A[i])
R[N-1] = 0
for j in range(N - 1):
  R[N - j - 2] = gcd(R[N - j - 1], A[N - j - 1])
for i in range(N):
  M[i] = gcd(L[i], R[i])
print(max(M))
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
ans = a
for i in range(a + 1, b + 1):
  ans ^= i
print(ans)

Fixed submission:
def func(x):
  mod = (x + 1) % 4
  if (mod == 0): return 0
  elif (mod == 1): return x
  elif (mod == 2): return 1
  else: return x ^ 1
a, b = map(int, input().split())
print(func(a - 1) ^ func(b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
taka = []
aoki = []
score = 0
for i in range(n):
  t, a = map(int, input().split())
  taka.append(t)
  aoki.append(a)
for i in range(n):
  maxT = max(taka)
  maxA = max(aoki)
  rm = 0
  if (maxT > maxA):
    rm = taka.index(maxT)
  else:
    rm = aoki.index(maxA)
  if (i % 2 == 0):
    score += taka.pop(rm)
    aoki.pop(rm)
  else:
    taka.pop(rm)
    score -= aoki.pop(rm)
print(score)

Fixed submission:
n = int(input())
l = []
ans = 0
for i in range(n):
  a, b = map(int, input().split())
  l.append(a + b)
  ans -= b
l.sort(reverse=True)
for i in range(n):
  if (i % 2 == 0):
    ans += l[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input(),split())
print(a * b // 2)

Fixed submission:
a, b, c = map(int, input().split())
print(a * b // 2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = 'E' + input() + 'W'
ans = len(s)
for i in range(len(s) - 1):
  if (s[i:i + 2] == 'EW'):
    x = s[:i].count('W') + s[i + 2:].count('E')
    if (ans >= x):
      ans = x
print(ans)

Fixed submission:
n = int(input())
s = input()
ans = len(s)
wc = 0
ec = s.count('E')
for i in range(len(s)):
  if (s[i] == 'E'):
    ec -= 1
  if (ans > ec + wc):
    ans = ec + wc
  if (s[i] == 'W'):
    wc += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
buttons = [0]
pushed = [0] * (n + 1)
ans = 0
for i in range(n):
  buttons.append(int(input()))
push = 1
while(push != 2):
  if ((buttons[push] not in buttons) or (pushed[push] == 1)):
    print(-1)
    sys.exit()
  else:
    pushed[push] = 1
    push = buttons[push]
    ans += 1
print(ans)

Fixed submission:
import sys
n = int(input())
b = [0]
pushed = [0] * (n + 1)
for i in range(n):
  b.append(int(input()))
push = 1
cnt = 0
while(push != 2):
  if (pushed[push] != 1):
    pushed[push] = 1
    cnt += 1
    push = b[push]
  else:
    print(-1)
    sys.exit()
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
power = 1
n = int(input())
for i in range(n):
  power *= i + 1
print(power % 1000000007)


Fixed submission:
import math
n = int(input())
print(math.factorial(n) % 1000000007)
Buggy python submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
image = []
temp = []
match = False
for i in range(n):
  image.append(input())
for i in range(m):
  temp.append(input())
for i in range(n):
  for j in range(n - m + 1):
    if (temp[0] == image[i][j : j + m]):
      match = True
      for k in range(1, m):
        if ((temp[k] != image[i + k][j : j + m]) | (i + k >= n)):
          match = False
          break
      if (match == True):
        print('Yes')
        sys.exit()
print('No')

Fixed submission:
import sys
n, m = map(int, input().split())
image = []
temp = []
match = False
for i in range(n):
  image.append(input())
for i in range(m):
  temp.append(input())
for i in range(n):
  for j in range(n - m + 1):
    if (temp[0] == image[i][j : j + m]):
      match = True
      for k in range(1, m):
        if (i + k >= n):
          match = False
          break
        elif (temp[k] != image[i + k][j : j + m]):
          match = False
          break
      if (match == True):
        print('Yes')
        sys.exit()
print('No')
Buggy python submission (verdict: Runtime Error):
N, L= input().split()
s = []
for i in range(int(N)):
    s.append(input())
print(''.join(s.sort()))


Fixed submission:
n ,l = map(int, input().split())
s=sorted([input() for i in range(n)])
print(*s, sep="")

Buggy python submission (verdict: Runtime Error):
N, L= input().split()
s = []
for i in range(int(N)):
    s.append(input())
''.join(s.sort())


Fixed submission:
n ,l = map(int, input().split())
s=sorted([input() for i in range(n)])
print(*s, sep="")
Buggy python submission (verdict: Runtime Error):
"""
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def ngcd(li):
    temp=gcd(li[0], li[1])
    if len(li)-3 >=0:
        for i in range(len(li)-2):
            temp=gcd(temp, li[i+2])
    return temp
    """

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def ngcd(numbers):
    return reduce(math.gcd, numbers)

n=int(input())
a=[int(i) for i in input().split()]

t=a[0]
t2=a[1]
out=0
f=1
min=10**9+1
for i in range(0, len(a)):
  gcd2=gcd(t, a[i])
  if gcd2<min:
    min=gcd2
    out=i
    #print(t, a[i],out, min)
"""
min=10**9+1
for i in range(0, len(a)):
  gcd2=gcd(t2, a[i])
  if gcd2<min:
    min=gcd2
    out=i
    print(t2, a[i],out, min)


print(out)
"""

"""
  if not (a[i]%t==0 or t %a[i]==0):
    if f:
      out=i
      f=0
    elif not f:
      out=0
"""
if not len(a)==2:
  temp=a[0:out]
  temp.extend(a[out+1:])
  #print(temp)
  itemp=ngcd(temp)
  itemp2=ngcd(a[1:])
  #print(itemp, itemp2)
  print(max(itemp, itemp2))
else:
  print(max(a[0], a[1]))


"""
max=0
for i in range(len(a)):
    temp=a[0:i]
    temp.extend(a[i+1:])
    itemp=ngcd(temp)
    if max < itemp:
        max=itemp

print(max)
"""

Fixed submission:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def ngcd(li):
    temp=gcd(li[0], li[1])
    if len(li)-3 >=0:
        for i in range(2, len(li)):
            temp=gcd(temp, li[i])
    return temp


n=int(input())
a=[int(i) for i in input().split()]

l=[]
l.append(0)
for i in range(len(a)):
  l.append(gcd(l[i], a[i]))
r=[]
r.append(0)
for i in range(len(a)):
  r.append(gcd(r[i], a[n-i-1]))
#print(l)
#print(r)

ans=[]
for i in range(len(a)):
  ans.append(gcd(l[i], r[n-i-1]))

print(max(ans))

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def ngcd(li):
    temp=gcd(li[0], li[1])
    if len(li)-3 >=0:
        for i in range(len(li)-3):
            temp=gcd(temp, li[i+2])
    return temp

n=int(input())
a=[int(i) for i in input().split()]

max=0
for i in range(len(a)):
    temp=a[0:i]
    temp.extend(a[i+1:])
    itemp=ngcd(temp)
    if max < itemp:
        max=itemp

print(max)


Fixed submission:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def ngcd(li):
    temp=gcd(li[0], li[1])
    if len(li)-3 >=0:
        for i in range(2, len(li)):
            temp=gcd(temp, li[i])
    return temp


n=int(input())
a=[int(i) for i in input().split()]

l=[]
l.append(0)
for i in range(len(a)):
  l.append(gcd(l[i], a[i]))
r=[]
r.append(0)
for i in range(len(a)):
  r.append(gcd(r[i], a[n-i-1]))
#print(l)
#print(r)

ans=[]
for i in range(len(a)):
  ans.append(gcd(l[i], r[n-i-1]))

print(max(ans))
Buggy python submission (verdict: Runtime Error):
[a,b]=[int(i) for i in input().split()]

print(int(a+b/2)


Fixed submission:
[a,b]=[int(i) for i in input().split()]

print(int(a+b/2))
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    if a>b:
        c = a%b
    else:
        c = b%a
    if c==0:
        return b
    else:
        return gcd(b,c)

[n,m]=[int(i) for i in input().split()]
s=input()
t=input()
g=gcd(n,m)

lcm=int(n*m/g)

s1=int(lcm/n)
s2=int(lcm/m)

#print(s1, s2)

c=max(int(n/m), int(m/n))
f=1
for i in range(c):
    if s[s1*i] != t[s2*i]:
        f=0

if f:
    print(lcm)
else:
    print("-1")


Fixed submission:
def gcd(a, b):
    if a>b:
        c = a%b
    else:
        c = b%a
    if c==0:
        return b
    else:
        return gcd(b,c)

[n,m]=[int(i) for i in input().split()]
s=input()
t=input()
g=gcd(n,m)

lcm=int(n*m/g)

s1=int(lcm/n)
s2=int(lcm/m)

#print(s1, s2, int(n/s2))

f=1
for i in range(int(n/s2)):
    #print(s2*i, s[s2*i], s1*i, t[s1*i])
    if s[s2*i] != t[s1*i]:
        f=0

if f:
    print(lcm)
else:
    print("-1")
Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
     if x%y==0:
             return y
     else:
             return gcd(y, x%y)

[n,m]=[int(i) for i in input().split()]
x=[int(i)-m for i in input().split()]
x.append(0)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

for i in range(len(x)-1):
    li.append(abs(x[i]-x[i+1]))
temp=abs(min(x))
li.append(temp)
try:
    x.remove(temp)
except:
    x.remove(-temp)
temp=abs(min(x))
li.append(temp)



if f:
    for i in range(len(li)-1):
        a=li[0]
        a=gcd(a, li[i+1])
    print(a)


Fixed submission:
def gcd(x,y):
     if x%y==0:
             return y
     else:
             return gcd(y, x%y)

[n,m]=[int(i) for i in input().split()]
x=[int(i)-m for i in input().split()]
x.append(0)

li=[]
f=1
if n==1:
    f=0
    print(abs(x[0]-x[1]))

for i in range(len(x)-1):
    li.append(max(abs(x[i]-x[i+1]), (abs(x[i+1]-x[i]))))
temp=abs(min(x))
li.append(temp)


if f:
    a=li[0]
    for i in range(len(li)-1):
        a=gcd(a, li[i+1])
    print(a)
Buggy python submission (verdict: Runtime Error):
r=int(imput())

if r<1200:
    print("ABC")
elif r<2800:
    print("ARC")
else:
    print("AGC")


Fixed submission:
r=int(input())

if r<1200:
    print("ABC")
elif r<2800:
    print("ARC")
else:
    print("AGC")
Buggy python submission (verdict: Runtime Error):
import math

n=input()
a=[int(i) for i in input().split()]
ac=a[:]


def lcm(x, y):
    return (x * y) // math.gcd(x, y)

while(len(ac)>1):
    x=ac.pop()
    y=ac.pop()
    ac.append(lcm(x, y))

g=ac[0]-1

ans=0
for i in a:
    ans+=g%i

print(ans)


Fixed submission:
n=input()
a=[int(i) for i in input().split()]
ac=a[:]


def lcm(x, y):
    x2=x
    y2=y
    while y != 0:
        x, y = y, x%y
    return (x2 * y2) // x

while(len(ac)>1):
    x=ac.pop()
    y=ac.pop()
    ac.append(lcm(x, y))

g=ac[0]-1

ans=0
for i in a:
    ans+=g%i

print(ans)

Buggy python submission (verdict: Runtime Error):
n=input()
a=[int(i) for i in input().split()]

import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

g=lcm(*a)-1

ans=0
for i in a:
    ans+=g%i

print(ans)


Fixed submission:
n=input()
a=[int(i) for i in input().split()]
ac=a[:]


def lcm(x, y):
    x2=x
    y2=y
    while y != 0:
        x, y = y, x%y
    return (x2 * y2) // x

while(len(ac)>1):
    x=ac.pop()
    y=ac.pop()
    ac.append(lcm(x, y))

g=ac[0]-1

ans=0
for i in a:
    ans+=g%i

print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())

li=[]
if len(s)<=k:
    iif=0
else:
    iif=k
for i in range(len(s)):
    for j in range(1, len(s)-iif+1):
        li.append(s[i:i+j])
        #print(s[i:i+j])

se=set(li)
sli=list(se)
sli.sort()
#print(sli)
print(sli[k-1])

Fixed submission:
s=input()
k=int(input())

li=[]
for i in range(len(s)):
    for j in range(1, k+1):
        li.append(s[i:i+j])

se=set(li)
sli=list(se)
sli.sort()
#print(sli)
print(sli[k-1])
Buggy python submission (verdict: Runtime Error):
a,b=map(int,intput().split())
print(a*b-a-b+1)

Fixed submission:
a,b=map(int,input().split())
print(a*b-a-b+1)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=list(map(int,input().split()))
ans=1
for i in range(a):
  ans=ans*b[i]
  if ans>10**18:
  	ans=-1
    break
  
print(ans)


Fixed submission:
a=int(input())
b=list(map(int,input().split()))
b.sort()
ans=1
for i in range(a):
  ans=ans*b[i]
  if ans>10**18:
    ans=-1
    break
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a=int(input())
b=list(map(int,input().split()))
ans=1
for i in range(a):
  ans=ans*b[i]
  
if ans>10**18:
  ans=-1
  
print(ans)

Fixed submission:
a=int(input())
b=list(map(int,input().split()))
b.sort()
ans=1
for i in range(a):
  ans=ans*b[i]
  if ans>10**18:
    ans=-1
    break
  
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
DP=[[0 for j in range(b+1)]for i in range(a)]
for i in range(c[0][0],b+1):
  DP[0][i]+=c[0][1]
for i in range(1,a):
  for j in range(c[i][0]):
    DP[i][j]=DP[i-1][j]
  for j in range(c[i][0],b):
    DP[i][j]=max(DP[i-1][j-c[i][0]]+c[i][1],DP[i-1][j])
  DP[i][b]=max(DP[i-1][b-1]+c[i][1],DP[i-1][b])
print(max(DP[-1]))
    

Fixed submission:
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
DP=[[0 for j in range(b+1)]for i in range(a)]
for i in range(c[0][0],b+1):
  DP[0][i]+=c[0][1]
for i in range(1,a):
  for j in range(b):
    if j<c[i][0]:
      DP[i][j]=DP[i-1][j]
    else:
      DP[i][j]=max(DP[i-1][j-c[i][0]]+c[i][1],DP[i-1][j])
  DP[i][b]=max(DP[i-1][b-1]+c[i][1],DP[i-1][b])
print(max(DP[-1]))
Buggy python submission (verdict: Runtime Error):
import math
a,b,c=map(int,input().split())
d=b-c/(a**2)
d=d*2
if d==0:
  print(0)
if d>a:
  e=c*2/(a*b)
  print(90-math.degrees(math.atan(e/b)))
else:
  print(90-math.degrees(math.atan(a/d)))

Fixed submission:
import math
a,b,c=map(int,input().split())
d=b-c/(a**2)
d=d*2
if d==0:
  print(0)
elif d>b:
  e=(c*2)/(a*b)
  print(math.degrees(math.atan(b/e)))
else:
  print(math.degrees(math.atan(d/a)))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[0 for i in range(m)]
b=[0 for i in range(m)]
c=[[] for i in range(m)]
for i in range(m):
  a[i],b[i]=map(int,input().split())
  c[i]=list(map(int,input().split()))
  
dp=[float("inf") for i in range(2**n)]
dp[0]=0
for i in range(m):
  now=0
  for j in c[i]:
    jj=1<<j-1
    now=now|jj
  for k in range(2**n):
    kk=k|now
    dp[kk]=min(dp[kk],dp[k]+a[i])
    

if dp[-1]==float("inf"):
  print(-1)
else:
  print(dp[-1])

Fixed submission:
import sys
input=sys.stdin.readline
def main():
  n,m=map(int,input().split())
  a=[0 for i in range(m)]
  b=[0 for i in range(m)]
  c=[[] for i in range(m)]
  for i in range(m):
    a[i],b[i]=map(int,input().split())
    c[i]=list(map(int,input().split()))
  
  dp=[float("inf") for i in range(2**n)]
  dp[0]=0
  for i in range(m):
    now=0
    for j in c[i]:
      jj=1<<j-1
      now=now|jj
    for k in range(2**n):
      kk=k|now
      dp[kk]=min(dp[kk],dp[k]+a[i])
    

  if dp[-1]==float("inf"):
    print(-1)
  else:
    print(dp[-1])
    
if __name__ == '__main__':  
  main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
def main():
  a,b=map(int,sys.stdin.readline().split())
  e=[[]for i in range(a)]

  for i in range(a-1):
    c1,c2=map(int,sys.stdin.readline().split())
    e[c1-1].append(c2-1)
    e[c2-1].append(c1-1)

  g=[[]for i in range(a)]
  f=deque([(0,-1)])
  ans=[0 for _ in range(a)]
  for i in range(b):
    ten,p=map(int,input().split())
    ans[ten-1]+=p
  i=0
  while len(f)!=0:
    i,fr=f.pop()
    for j in e[i]:
      if j==fr:
        continue
      else:
        ans[j]+=ans[i]
        f.append((j,i)) 
  print(*ans)
if __name__ == '__main__':  
  main()
    
  

  
  


Fixed submission:
a=int(input())
b=input()
if a>=3200:
  print(b)
else:
  print("red")
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=map(int,input().split())
b.sort()
c=b[0]

for i in range(1,a):
  c=(c+b[i])/2
  
print(c)

Fixed submission:
a=int(input())
b=list(map(int,input().split()))
b.sort()
c=b[0]

for i in range(1,a):
  c=(c+b[i])/2
  
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
d=[]
sum=0
e=0
for i in range(1,b+1):
  for j in range(e,a):
    if c[j][0]<=i:
      d.append(c[j][1])
    else:
      e=j
      break
  d.sort()
  if len(d)>0:
    sum+=d[-1]
    d.pop()
      
    
  
print(sum)

Fixed submission:
import heapq
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
d=[[0]for i in range(b)]
sum=0
for i,j in c:
  if i<=b:
    d[i-1].append(j)
e=[]

for i in d:
  for j in i:
    heapq.heappush(e,-j)
  sum-=heapq.heappop(e)
      
    
  
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
d=[[]for i in range(b+1)]
for i in c:
  if i[0]<=b:
    e=i[0]
    d[e].append(i[1])
    
for i in range(b+1):
  d[i].sort()
sum=0
for i in range(b+1):
  e=0
  f=0
  for j in range(i+1):
    if len(d[j])!=0:
      if e<=d[j][-1]:
        f=j
        e=d[j][-1]    
  sum+=e
  if f>0:
    d[f].pop()
      
    
  
print(sum)

Fixed submission:
import heapq
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
d=[[0]for i in range(b)]
sum=0
for i,j in c:
  if i<=b:
    d[i-1].append(j)
e=[]

for i in d:
  for j in i:
    heapq.heappush(e,-j)
  sum-=heapq.heappop(e)
      
    
  
print(sum)

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=[sorted(input()) for j in range(a)]
c=[[0for i in range(26)] for j in range(a)]
for i in range(a):
  for j in range(10):
    c[i][ord(b[i][j])-97]+=1
sum=0
d=1
c.sort()
for i in range(a-1):
  if c[i]==c[i+1]:
    d+=1
  else:
    sum+=d*(d-1)//2
    d=1
  if i==a-2:
    sum+=d*(d-1)//2
    
print(sum)

Fixed submission:
import heapq
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
d=[[0]for i in range(b)]
sum=0
for i,j in c:
  if i<=b:
    d[i-1].append(j)
e=[]

for i in d:
  for j in i:
    heapq.heappush(e,-j)
  sum-=heapq.heappop(e)
      
    
  
print(sum)

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=[sorted(input()) for j in range(a)]
c=[[0for i in range(26)] for j in range(a)]
for i in range(a):
  for j in range(10):
    c[i][ord(b[i][j])-97]+=1
sum=0
d=1
c.sort()
print(c)
for i in range(a-1):
  if c[i]==c[i+1]:
    d+=1
  else:
    sum+=d*(d-1)//2
    d=1
  if i==a-2:
    sum+=d*(d-1)//2
    
print(sum)

Fixed submission:
import heapq
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
c.sort()
d=[[0]for i in range(b)]
sum=0
for i,j in c:
  if i<=b:
    d[i-1].append(j)
e=[]

for i in d:
  for j in i:
    heapq.heappush(e,-j)
  sum-=heapq.heappop(e)
      
    
  
print(sum)