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

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

def f(nums):
  out=0
  for samp in abcd:
    if nums[samp[1]-1]-nums[samp[0]-1]==samp[2]:
      out+=samp[3]
  return out

def g(nums):
  if nums[-1]<M:
    nums[-1]+=1
    return nums, False
  
  i=N-1
  while i>=0 and nums[i]==M:
    i-=1
  if i<0:
    return None, True
  
  nums=nums[:i]+[nums[i]+1 for _ in range(N-i)]
  return nums, False

nums=[1]*N
fi=False
ans=0

while fi==False:
  p=f(nums)
  if ans<p:
    ans=p
  nums, fi=g(nums)
  
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, Q=map(int, input().split())
abcd=[list(map(int, input().split())) for _ in range(Q)]

def f(nums):
  out=0
  for samp in abcd:
    if nums[samp[1]-1]-nums[samp[0]-1]==samp[2]:
      out+=samp[3]
  return out

def g(nums):
  if nums[-1]<M-1:
    nums[-1]+=1
    return nums, False
  
  i=N-1
  while i>=0 and nums[i]==M-1:
    i-=1
  if i<0:
    return None, True
  
  nums=nums[:i]+[nums[i]+1]*(M-i)
  return nums, False

nums=[0]*N
fi=False
ans=0

while fi==False:
  p=f(nums)
  if ans<p:
    ans=p
  nums, fi=g(nums)
  
print(ans)
Problem p02815 (python)

Fixed submission:
MOD=10**9+7

N=int(input())
if N==1:
  C=int(input())
  print(2*C%MOD)
  exit()
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
tmp1=pow(2, N-1, MOD)
tmp2=pow(2, N-2, MOD)
for i in range(N):
  out+=(tmp1+tmp2*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print(int(out%MOD))

Buggy submission (verdict: Runtime Error):
MOD=10**9+7

N=int(input())
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
tmp1=pow(2, N-1, MOD)
tmp2=pow(2, N-2, MOD)
for i in range(N):
  out+=(tmp1+tmp2*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print(int(out%MOD))
Problem p02862 (python)

Fixed submission:
p=10**9+7
X, Y=map(int, input().split())

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

if a*b<0:
  print(0)
  exit()

ab=a+b
ue=[1]*(ab+1)
for i in range(1, ab+1):
  ue[i]=ue[i-1]*i%p
  
out=ue[-1]*pow(ue[a], p-2, p)%p
out=out*pow(ue[b], p-2, p)%p

print(out)

Buggy submission (verdict: Runtime Error):
p=10**9+7
X, Y=map(int, input().split())

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

ab=a+b
ue=[1]*(ab+1)
for i in range(1, ab+1):
  ue[i]=ue[i-1]*i%p
  
out=ue[-1]*pow(ue[a], p-2, p)%p
out=out*pow(ue[b], p-2, p)%p

print(out)

Buggy submission (verdict: Runtime Error):
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]

def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

X, Y=map(int, input().split())
 
def f(x, y):
  s=max(x, y)
  t=min(x, y)
  st=s+t
  ans=1
  for i in range(1, t+1):
    ans=ans*(st+1-i)//i
    ans=ans%(10**9+6)
    
  return ans
  
      
b=(2*X-Y)//3
btemp=(2*X-Y)%3
a=(Y-a)//2
atemp=(Y-a)%2
if btemp>0 or atemp>0:
  ans=0
else:
  a=(Y-b)//2
  
  #ans=mt.factorial(a+b)//(mt.factorial(a)*mt.factorial(b))
  #ans=tool.permutations(a+b)//(tool.permutations(a)*tool.permutations(b))
  #s=max(a, b)
  #t=min(a, b)
  #ans=comb(s+t, t, 10**9+7)
  m=10**9+7
  ans=1
  for i in range(1, a+b+1):
    ans=ans*i%m
  for i in range(1, a+1):
    ans=ans*mod_inv(i, m)%m
  for i in range(1, b+1):
    ans=ans*mod_inv(i, m)%m
print(ans)
Problem p02873 (python)

Fixed submission:
S=input()
n=len(S)

def f(a):
  return a*(a+1)//2

ans=0
i=0
if S[i]=='>':
  while i<n and S[i]=='>':
    i+=1
    
  ans+=f(i)
  
while i<n:
  j=i+1
  while j<n and S[j]=='<':
    j+=1
    
  if j==n:
    ans+=f(j-i)
    i=j+1
  else:
    k=j+1
    while k<n and S[k]=='>':
      k+=1
      
    if j-i>k-j:
      ans+=f(j-i)+f(k-j-1)
    else:
      ans+=f(j-i-1)+f(k-j)
      
    i=k
    
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
n=len(S)

def sums(a):
  return (a+1)*a//2

def f(s):
  n=len(s)
  i=0
  while i<n and s[i]=='<':
    i+=1
  if i==n:
    return sums(i)
  else:
    j=i+1
    while j<n and s[j]=='>':
      j+=1
    if i>(j-i):
      temp=sums(i)+sums(j-i-1)
    else:
      temp=sums(j-i)+sums(i-1)
      
    if j<n:
      temp+=f(s[j:])
      
    return temp

if S[0]=='<':
  ans=f(S)
else:
  i=0
  while i<n and S[i]=='>':
    i+=1
    
  if i==n:
    ans=sums(i)
  else:
    ans=sums(i)+f(S[i:])
    
print(ans)
Problem p02891 (python)

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

def f(s):
  i=0
  c=0
  n=len(s)
  if n==1:
    return 0
  else:
    while i<n-1:
      if s[i]==s[i+1]:
        c+=1
        i+=2
      else:
        i+=1
    return c

a=0
n=len(S)
while a<n-1 and S[0]==S[a+1]:
  a+=1
  
b=-1
while a<n-1 and S[0]==S[b]:
  b-=1
  
if a==n-1:
  ans=n*K//2
elif b==-1:
  ans=f(S)*K
elif a==0 and b!=-1:
  ans=(K-1)*((-b-1)//2)+K*f(S[1:b+1])+(-b-1)//2
elif a!=0 and b!=-1:
  ans=(a+1)//2+f(S[a+1:b+1])*K+((a-b)//2)*(K-1)+(-b-1)//2
  
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())

def f(s):
  i=0
  c=0
  n=len(s)
  if n==1:
    return 0
  else:
    while i<n:
      if s[i]==s[i+1]:
        c+=1
        i+=2
      else:
        i+=1
    return c

a=0
while S[0]==S[a+1]:
  a+=1
  
b=-1
while S[0]==S[b]:
  b-=1
  
if b==-1:
  ans=f(S)*K
elif a==0 and b!=-1:
  ans=(K-1)*(-b-1)//2+K*f(S[1:b+1])
elif a!=0 and b!=-1:
  ans=(a+1)//2+f(S[a+1:b+1])*K+((a-b)//2)*(K-1)+(-b-1)//2
  
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())

i=0
c=0
while i<len(S)-1:
  if S[i]==S[i+1]:
    c+=1
    i+=2
  else:
    i+=1
    
if S[0]==S[-1] and S[-2]!=S[-1]:
  print((c+1)*K-1)
else:
  print(c*K)
Problem p02948 (python)

Fixed submission:
import heapq

N, M=map(int, input().split())
AB=[list(map(int, input().split())) for i in range(N)]
AB=sorted(AB, key=lambda x:x[0])
h=[0]*M
heapq.heapify(h)

out=0
j=0
for i in range(1, M+1):
  while j<N and AB[j][0]<=i:
    heapq.heappush(h, -1*AB[j][1])
    j+=1
    
  out+=-1*heapq.heappop(h)
  
print(out)

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

temp=list(map(int, input().split()))
N=temp[0]
M=temp[1]

AB=np.array([list(map(int, input().split())) for i in range(N)])
AB=np.c_[AB, np.zeros((AB.shape[0], 1))]

money=0
for i in range(1, M+1):
  temp=AB[AB[:, 0]<=i]
  temp=temp[temp[:, 2]==0]
  temp=temp[np.argmax(temp[:, 1])]
  money+=temp[1]
  
  x=0
  while x<AB.shape[0]:
    if sum(AB[x, :]==temp)==3:
      AB[x, 2]=1
      break
    x+=1
    
print(int(money))
Problem p02951 (python)

Fixed submission:
temp=list(map(int, input().split()))
a=temp[2]-(temp[0]-temp[1])
if a>=0:
  print(a)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
temp=list(map(int, input().stlip()))
a=temp[2]-(temp[0]-temp[1])
if a>=0:
  print(a)
else:
  print(0)
Problem p02954 (python)

Fixed submission:
S=input()
N=len(S)
c=[1]*N
for i in range(N-1):
  if S[i]=='R' and S[i+1]=='R':
    c[i+2]+=c[i]
    c[i]=0
    
for i in range(N-1, 1, -1):
  if S[i]=='L' and S[i-1]=='L':
    c[i-2]+=c[i]
    c[i]=0
    
print(' '.join(map(str, c)))

Buggy submission (verdict: Runtime Error):
S=input()
N=len(S)
ans=[0]*N

a=0
x=0
y=0
while a<N-1:
  x=a+1
  while S[x]=='R':
    x+=1
    
  y=x+1
  while S[y]=='L' and y<N:
    y+=1
    if y==N:
      break
    
  ans[x]+=(x-a)//2
  ans[x-1]+=(x-a-1)//2
  
  ans[x]+=(y-x-1)//2
  ans[x-1]+=(y-x)//2
  
  ans[x]+=1
  ans[x-1]+=1
  
  a=y
  
print(' '.join(map(str, ans)))
Problem p02984 (python)

Fixed submission:
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]
As=[]
As.append(sum([A[i]*pow(-1, i) for i in range(N)]))
for i in range(1, N):
  As.append(A[i-1]-As[i-1])

x1=As[0]/2
print(int(2*x1), end=' ')

for i in range(1, N):
  print(2*int(As[i]-x1*pow(-1, i)), end=' ')

Buggy submission (verdict: Runtime Error):
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]

result=[]
for i in range(N):
  result.append(mean(A[i:i+2]))
  
print(result)

Buggy submission (verdict: Runtime Error):
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]

A=[A[-1]]+A[:-1]
result=[]
for i in range(N):
  result.append(mean(A[i:i+2]))
  
print(result)

Buggy submission (verdict: Runtime Error):
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]

A=[A[-1]]+A[:-1]

for i in range(N):
  print(mean(A[i:i+2]))

Buggy submission (verdict: Runtime Error):
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]

A=[A[-1]]+A

for i in range(N):
  print(mean(A[i:i+2]))

Buggy submission (verdict: Runtime Error):
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]

A=[A[-1]]+A

for i in range(N):
  print(mean(A[i:1+2]))

Buggy submission (verdict: Runtime Error):
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]

A=A[-1]+A

for i in range(N):
  print((A[i]+A[i+1])/2)

Buggy submission (verdict: Runtime Error):
N=int(input())
temp=[input().split() for i in range(N)]
A=[int(temp[i]) for i in range(N)]

A=A[-1]+A

for i in range(N):
  print((A[i]+A[i+1])/2)
Problem p02989 (python)

Fixed submission:
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
d.sort()
  
a=d[int(N/2-1)]
b=d[int(N/2)]
print(int(b-a))

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

d.sort()

print(int(d[n/2]-d[n/2-1]))

Buggy submission (verdict: Runtime Error):
N=int(input())
temp=input().split()
d=[int(temp[i]) for i in range(N)]
d.sort()
  
a=dd[int(N/2-1)]
b=dd[int(N/2)]
print(int(b-a))
Problem p03012 (python)

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

output=abs(W[0]-sum(W[1:]))
for i in range(2, N):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output>temp:
    output=temp
    
print(output)

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

output=abs(W[0]-sum(W[1:]))
for i in range(2, N-1):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output<temp:
    output=temp.copy()
    
print(output)

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

print(np.min([np.abs(np.sum(W[:t])-np.sum(W[t:])) for t in range(1, N-1)]))

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

print(np.min([np.abs(np.sum(W[:t])-np.sum(W[t:]))) for t in range(1, N-1)]))

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

print(np.min([np.abs(np.sum(W[:t])-np.sum(W[t:]))) for t in range(N)]))
Problem p03013 (python)

Fixed submission:
temp=input().split()
N=int(temp[0])
M=int(temp[1])

index=[int(1) for i in range(N)]
for i in range(M):
  index[int(int(input())-1)]=0

temp=[0, 1]
for i in range(N):
  if index[i]==1:
    temp=[temp[1], temp[0]+temp[1]]
  else:
    temp=[temp[1], 0]
    
print(temp[1]%1000000007)

Buggy submission (verdict: Runtime Error):
N, M=map(int, input().split())
if M>0:
  a=[int(input()) for i in range(M)]

  if a[0]==1:
    way=[1, 0]
    a.remove(1)
  else:
    way=[1, 1]
else:
  way=[1, 1]
  
for i in range(2, N+1):
  if len(a)>0:
    if i==a[0]:
      a.remove(i)
      way=[way[1], 0]
    else:
      way=[way[1], sum(way)]
  else:
    way=[way[1], sum(way)]
    
print(way[1]%1000000007)

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

if a[0]==1:
  way=[1, 0]
  a.remove(1)
else:
  way=[1, 1]
  
for i in range(2, N+1):
  if len(a)>0:
    if i==a[0]:
      a.remove(i)
      way=[way[1], 0]
    else:
      way=[way[1], sum(way)]
  else:
    way=[way[1], sum(way)]
    
print(way[1]%1000000007)

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

if a[0]==1:
  way=[1, 0]
  a.remove(1)
else:
  way=[1, 1]
  
for i in range(2, N+1):
  if len(a)>0:
    if i==a[0]:
      a.remove(i)
      way=[way[1], 0]
    else:
      way=[way[1], sum(way)]
  else:
    way=[way[1], sum(way)]
    
print(way[1]%1000000007)
Problem p03041 (python)

Fixed submission:
temp=list(map(int, input().split()))
S=list(input())
K=int(temp[1]-1)

if S[K]=='A':
  S[K]='a'
elif S[K]=='B':
  S[K]='b'
else:
  S[K]='c'
  
print("".join(S))

Buggy submission (verdict: Runtime Error):
temp=list(map(int, input().split()))
S=input()
K=int(temp[1]-1)

if S[K]=='A':
  S[K]='a'
elif S[K]=='B':
  S[K]='b'
else:
  S[K]='c'
  
print(S)

Buggy submission (verdict: Runtime Error):
temp=list(map(int, input().split()))
S=input()
K=temp[1]

if S[K-1]=='A':
  S[K-1]='a'
elif S[K-1]=='B':
  S[K-1]='b'
else:
  S[K-1]='c'
  
print(S)
Problem p03045 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def f(j):
  a[j]=1
  n=len(dic[j])
  for k in range(n):
    if a[dic[j][k]]==0:
      f(dic[j][k])

N, M=map(int, input().split())
dic={}
for i in range(1, N+1):
  dic[i]=[]

for i in range(M):
  x, y, z=map(int, input().split())
  dic[x].append(y)
  dic[y].append(x)
  
a=[0]*(N+1)
out=0
i=1
while i<N+1:
  if a[i]==0:
    a[i]=1
    out+=1
    n=len(dic[i])
    for j in range(n):
      if a[dic[i][j]]==0:
        f(dic[i][j])
  i+=1
print(out)

Buggy submission (verdict: Runtime Error):
def f(j):
  nodes[j]=1
  for k in links[j]:
    if nodes[k]==0:
      f(k)

N, M=map(int, input().split())
XYZ=[list(map(int, input().split())) for _ in range(M)]
links=[[] for _ in range(N+1)]
for i in range(M):
  links[XYZ[i][0]].append(XYZ[i][1])
  links[XYZ[i][1]].append(XYZ[i][0])
  
nodes=[0]*(N+1)
ans=0
for i in range(1, N+1):
  if nodes[i]==0:
    ans+=1
    nodes[i]=1
    for j in links[i]:
      f(j)
      
print(ans)

Buggy submission (verdict: Runtime Error):
def f(j):
  a[j]=1
  n=len(dic[j])
  for k in range(n):
    if a[dic[j][k]]==0:
      f(dic[j][k])

N, M=map(int, input().split())
dic={}
for i in range(1, N+1):
  dic[i]=[]

for i in range(M):
  x, y, z=map(int, input().split())
  dic[x].append(y)
  dic[y].append(x)
  
a=[0]*(N+1)
out=0
i=1
while i<N+1:
  if a[i]==0:
    a[i]=1
    out+=1
    n=len(dic[i])
    for j in range(n):
      if a[dic[i][j]]==0:
        f(dic[i][j])
  i+=1
print(out)
Problem p02571 (python)

Fixed submission:
S = input()
T = input()

l = []
if len(S) != len(T):
  for i in range(len(S) - len(T)):
    cnt = 0
    for j in range(len(T)):
      if T[j] != S[i+j]:
        cnt += 1
    l.append(cnt)
  print(min(l))
else:
  cnt = 0
  for i in range(len(S)):
    if T[i] != S[i]:
      cnt += 1
  print(cnt)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

l = []
for i in range(len(S) - len(T)):
  cnt = 0
  for j in range(len(T)):
    if T[j] != S[i+j]:
      cnt += 1
  l.append(cnt)
print(min(l))
Problem p02571 (python)

Fixed submission:
s = input()
t = input()
ls = len(s)
lt = len(t)

ans = 0
for i in range(ls-lt+1):
  same = 0
  for j in range(lt):
    ind = i+j
    if s[ind]==t[j]:
      same += 1
  ans = max(ans,same)
print(lt-ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
ls = len(s)
lt = len(t)

ans = 0
for i in range(ls-lt+1):
  same = 0
  for j in range(lt):
    ind = i+lt
    if s[ind]==t[j]:
      same += 1
  ans = min(ans,min)
print(ans)
Problem p02629 (python)

Fixed submission:
s = "zabcdefghijklmnopqrstuvwxyz"
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
print(ans)

Buggy submission (verdict: Runtime Error):
s = "zabcdefghijklmnopqrstuvwxy"
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = ""
while(n>0):
    r = n%26
    if r==0:
        r = 26
    ans = s[r] + ans
    n -= r
    n //=26
Problem p02891 (python)

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

ss = s + s

if len(set(s))==1:
    print(int((len(s)*k)/2))
else:
    a=0
    prev = "?"
    for v in s:
        if v==prev:
            a += 1
            prev = "?"
        else:
            prev = v

    b=0
    prev = "?"
    for v in ss:
        if v==prev:
            b += 1
            prev = "?"
        else:
            prev = v

    print(a+(b-a)*(k-1))

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

ss = s + s

if len(set(s)==1):
    print(int((len(s)*k)/2))
else:
    a=0
    prev = "?"
    for v in s:
        if v==prev:
            a += 1
            prev = "?"
        else:
            prev = v

    b=0
    prev = "?"
    for v in ss:
        if v==prev:
            b += 1
            prev = "?"
        else:
            prev = v

    print(a+(b-a)*(k-1))
Problem p02948 (python)

Fixed submission:
import heapq as hp

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  if a<=m:
  	lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  if len(h)>0:
    ans -= hp.heappop(h)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as hp

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  if len(h)>0:
    ans -= hp.heappop(h)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as hp

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  if h!=None:
	ans -= hp.heappop(h)
  
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as hp

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  if h!=None:
	  ans -= hp.heappop(h)
  
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as hp

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  ans -= hp.heappop(h)
  
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as hq

n,m =[int(i) for i in input().split()]
lists = [[] for i in range(m)]

for _ in range(n):
  a,b = [int(i) for i in input().split()]
  lists[a-1].append(b)
  
h = []
ans = 0
for day in range(m):
  for v in lists[day]:
    hp.heappush(h, -v)
  ans -= hp.heappop(h)
  
print(ans)
Problem p02954 (python)

Fixed submission:
s = input()
n = len(s)
ans = [0] *n 

left = 0
i = 0

while(left<n-1):
  while s[i]=="R":
    i+=1
  right=i
  while s[right]=="L":
    if right==n-1:
      right += 1
      break        
    right +=1

  for k in range(left, right):
    if (i-k) % 2==0:
      ans[i] += 1
    else:
      ans[i-1] += 1

  left = right
  i = left
    
print(*ans)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
ans = [0] *n 

left = 0
i = 0

while(left<n):
  while s[i]=="R":
    i+=1
  right=i
  while s[right]=="L":
    right +=1
    if right==n-1:
      right += 1
      break

  for k in range(left, right):
    if (i-k) % 2==0:
      ans[i] += 1
    else:
      ans[i-1] += 1

  left = right
  i = left
print(*ans)
Problem p03768 (python)

Fixed submission:
#b
#上で再起の代わりにナイーブに配列内の値を埋めていく。
#aこのほうがちょい早い。

#b
#by using the condition d<=10, we should memorize V*d whether the pair is already searched.
#if searched, we can stop.
#まだ遅い。TLE.

n,m = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
colors = [0]*n

checker = [[0 for _ in range(11)] for _ in range(n)]        

for _ in range(m):
    a,b = [int(i) for i in input().split()]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
    

def dfs(d,v,c):
    if checker[v][d] != 0 or d<0:
        return
    #d>=0 and (v,d) is not checked
    if colors[v]==0: #not colored yet
        colors[v] = c
        
    #ここよ
    for j in range(d+1):
        checker[v][j] = 1
        
        
    nodes=edges[v]
    for u in nodes:
        dfs(d-1, u, c)

    
q = int(input())
info = []
for _ in range(q):
    v,d,c = [int(i) for i in input().split()]
    info.append((v-1,d,c))
    
info.reverse()
for tupple in info:
    v,d,c = tupple
    
    #not bfs but dfs
    dfs(d,v,c)
    
for i in range(n):
    print(colors[i])

Buggy submission (verdict: Runtime Error):
#b
#by using the condition d<=10, we should memorize V*d whether the pair is already searched.
#if searched, we can stop.

n,m = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
colors = [0]*n

checker = [[0 for _ in range(10)] for _ in range(n)]

def dfs(d,v,c):
    if checker[v][d] != 0 or d<0:
        return
    #d>=0 and (v,d) is not checked
    colors[v] = c
    checker[v][d] = 1 #checked
    
    dfs(d-1, v, c) #dが低いやつについて全て埋めておく必要がある。もう先着ありで無理ですよ、って宣言。
    
    nodes=edges[v]
    for u in nodes:
        dfs(d-1, u, c)

        

for _ in range(m):
    a,b = [int(i) for i in input().split()]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
    
q = int(input())
info = []
for _ in range(q):
    v,d,c = [int(i) for i in input().split()]
    info.append((v,d,c))
    
info.reverse()
for tupple in info:
    v,d,c = tupple
    
    #not bfs but dfs
    dfs(d,v-1,c)
    
for i in range(n):
    print(colors[i])
Problem p03822 (python)

Fixed submission:
#b
import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    b = int(input())
    edges[b-1].append(i+1)
    
def dfs(u):
    e = edges[u]
    if e==[]:
        return 0
    #else
    #return maximum
    length = []
    for v in e:
        length.append(dfs(v))
    l = len(length)
    length.sort()
    maxi = 0
    for v in length:
        cal = v + l
        maxi= max(maxi, cal)
        l -= 1
    return maxi    
    
print(dfs(0))

Buggy submission (verdict: Runtime Error):
#b
n = int(input())
edges = [[] for _ in range(n)]
for i in range(n-1):
    b = int(input())
    edges[b-1].append(i+1)
    
def dfs(u):
    e = edges[u]
    if e==[]:
        return 0
    #else
    #return maximum
    length = []
    for v in e:
        length.append(dfs(v))
    l = len(length)
    length.sort()
    maxi = 0
    for v in length:
        cal = v + l
        maxi= max(maxi, cal)
        l -= 1
    return maxi    
    
print(dfs(0))
Problem p04005 (python)

Fixed submission:
a,b,c = [int(i) for i in input().split()]
if (a*b*c)%2==0:
    print(0)
else:
    ans = a*b
    ans = min(ans, b*c)
    ans = min(ans, c*a)
    print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c = [int(i) for i in input().split()]
if (a*b*c)%2==0:
    print(0)
else:
    ans = a*b
    ans = min(ans, b*c)
    ans = min(aans, c*a)
    print(ans)