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

Fixed submission:
from collections import defaultdict
from copy import deepcopy

from bisect import bisect_left as bl

N,M=map(int,input().split())
n=N
A=list(map(int,input().split()))
dic={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dict=defaultdict(int)
list=[]
L=[]
for key in range(9,0,-1):
    if key in A:
        if dic[key] in dict.values():
            continue
        dict[key]=dic[key]
        list.append([key,dic[key]])
        L.append(key)
list.sort(key=lambda x:x[0],reverse=True)
cost=[]
for i in list:
    cost.append(i[1])
num=len(dict.keys())

dp=[[-1 for i in range(num+1)] for j in range(N+1)]
dp[0]=[0]*(num+1)
#dp[i] N=iでの最大値
Non=[-1]*(num+1)
for i in range(N):
    ini=[]
    for j in range(num):
        if i+1-cost[j]>=0 and dp[i+1-cost[j]]!=Non:
            a=dp[i+1-cost[j]][:]
            a[j+1]+=1
            a[0]+=1
            ini.append(a)
    if ini:
        dp[i+1]=max(ini)
s=""


for l in L:
    for i in range(num):
        key,cost=list[i]
        if l==key:
            s+=str(key)*dp[N][i+1]

print(s)

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

from bisect import bisect_left as bl

N,M=map(int,input().split())
n=N
A=list(map(int,input().split()))
dic={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dict=defaultdict(int)
list=[]
L=[]
for key in range(9,0,-1):
    if key in A:
        if dic[key] in dict.values():
            continue
        dict[key]=dic[key]
        list.append([key,dic[key]])
        L.append(key)
list.sort(key=lambda x:x[1])
cost=[]
for i in list:
    cost.append(i[1])
num=len(dict.keys())

dp=[[-1 for i in range(num+1)] for j in range(N+1)]
dp[0]=[0]*(num+1)
#dp[i] N=iでの最大値
Non=[-1]*(num+1)
for i in range(N):
    ini=[]
    for j in range(num):
        if i+1-cost[j]>=0 and dp[i+1-cost[j]]!=Non:
            a=dp[i+1-cost[j]][:]
            a[j+1]+=1
            a[0]+=1
            ini.append(a)
    if ini:
        dp[i+1]=max(ini)
s=""
s1=""
Num=N
Keys=dic.keys()
Keys.reverse()
for i in range(dp[N][0]):
    for k in Keys:
        if Num-dic[k]>=0 and dp[Num][0]-1==dp[Num-dic[k]][0]:
            s1+=str(k)
            Num-=dic[k]
            break
print(s1)
Problem p03145 (python)

Fixed submission:
AB,BC,CA=map(int,input().split())
print(int(AB*BC/2))

Buggy submission (verdict: Runtime Error):
AB,BC,CA=map(int,input()split())
print(AB*BC/2)
Problem p03148 (python)

Fixed submission:
N,K=map(int,input().split())
td=[]
for i in range(N):
    t,d=map(int,input().split())
    td.append([t,d])
td.sort(key=lambda x:x[1],reverse=True)
A=td[:K]
B=[]
s2=set()
for i,j in td[K:]:
    if not(i in s2):
        s2.add(i)
        B.append([i,j])
s1=set()
n=0
C=[]
sum=0
for i,j in A:
    if not(i in s1):
        s1.add(i)
        n+=1
        sum+=j
    else:
        C.append([i,j])
        sum+=j
sum+=n**2
B.reverse()
D=[]
for i,j in B:
    if not(i in s1):
        D.append([i,j])
list=[sum]

while(C):
    if D:
        i,j=D.pop()
        list.append(list[-1]+2*n+1+(j-C[-1][1]))
        n+=1
    C.pop()
print(max(list))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
td=[]
for i in range(N):
    t,d=map(int,input().split())
    td.append([t,d])
td.sort(key=lambda x:x[1],reverse=True)
A=td[:K]
B=[]
s2=set()
for i,j in td[K:]:
    if not(i in s2):
        s2.add(i)
        B.append([i,j])
s1=set()
n=0
C=[]
sum=0
for i,j in A:
    if not(i in s1):
        s1.add(i)
        n+=1
        sum+=j
    else:
        C.append([i,j])
        sum+=j
sum+=n**2
B.reverse()
D=[]
for i,j in B:
    if not(i in s1):
        D.append([i,j])
list=[sum]
while(D):
    i,j=D.pop()
    list.append(list[-1]+2*n+1+(j-A[-1][1]))
    n+=1
    A.pop()
    if n==K:
        break
print(max(list))
Problem p03213 (python)

Fixed submission:
from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy
from math import log

N=int(input())
def nCr(n,r):
    if n<r:
        return 0
    a=factorial(n)
    b=factorial(n-r)
    c=factorial(r)
    return a//(b*c)
f=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
a=0
b=0
c=0
d=0
e=0
for F in f:
    s=sum([(N//(F**i)) for i in range(1,7)])
    if s>=74:
        e+=1
    elif s>=24:
        d+=1
    elif s>=14:
        c+=1
    elif s>=4:
        b+=1
    elif s>=2:
        a+=1

print(nCr(b+c+d+e,2)*a+nCr(b+c+d+e,3)*3+(c+d+e)*(max(b+c+d+e-1,0))+(e+d)*(max(0,a+b+c+d+e-1))+e)

Buggy submission (verdict: Runtime Error):
N=int(input())
def nCr(n,r):
    if n<r:
        return 0
    a=factorial(n)
    b=factorial(n-r)
    c=factorial(r)
    return a//(b*c)
f=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
a=0
b=0
c=0
d=0
e=0
for F in f:
    s=sum([N/(F**i) for i in range(1,7)])
    if s>=74:
        e+=1
    elif s>=24:
        d+=1
    elif s>=14:
        c+=1
    elif s>=4:
        b+=1
    elif s>=2:
        a+=1
print(nCr(b+c+d+e,2)*a+nCr(b+c+d+e,3)*3+(c+d+e)*(b+c+d+e-1)+(e+d)*(a+b+c+d+e-1)+e)
Problem p03227 (python)

Fixed submission:
S=input()
if len(S)==2:
    print(S)
else:
    print(S[::-1])

Buggy submission (verdict: Runtime Error):
S=input()
if len(S)==2:
    print(S)
else:
    S.reverse()
    print(S)
Problem p03231 (python)

Fixed submission:
from fractions import gcd
from math import sqrt
from heapq import *
from math import factorial
from collections import defaultdict

N,M=map(int,input().split())
S=input()
T=input()
g=gcd(N,M)
m=(N//g)*(M//g)*g
a=0
b=0
A=m//N
B=m//M
t=True
while(a<N):
    if S[a]==T[b]:
        a+=B
        b+=A
    else:
        print(-1)
        quit()
print(m)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
S=input()
T=input()
g=gcd(N,M)
m=(N//g)*(M//g)*g
a=0
b=0
A=m//N
B=m//M
t=True
while(a<N):
    if S[a]==T[b]:
        a+=B
        b+=A
    else:
        print(-1)
        quit()
print(m)
Problem p03240 (python)

Fixed submission:
N=int(input())

xyh=[]
for i in range(N):
    xi,yi,hi=map(int,input().split())
    xyh.append([xi,yi,hi])
xyh.sort(reverse=True,key=lambda x:x[2])
for Cx in range(0,101):
    for Cy in range(0,101):
        for i in range(N):
            X=xyh[i][0]
            Y=xyh[i][1]
            h=xyh[i][2]
            if i==0:
                H=h+abs(X-Cx)+abs(Y-Cy)
                continue
            H_=h+abs(X-Cx)+abs(Y-Cy)
            if h==0:
                if H_<H:
                    break
            elif H!=H_:
                break
            if i==N-1:
                print(Cx,Cy,H)
                quit()

Buggy submission (verdict: Runtime Error):
N=int(input())
xyh=[]
for i in range(N):
  xyh.append(list(map(int,input().split())))
def height(x,y,h,Cx,Cy,):
  height=h+abs(x-Cx)+abs(y-Cy)
  return height
def find(N):
  for Cx in range(101):
    for Cy in range(101):
      Height=height(xyh[0][0],xyh[0][1],xyh[0][2],Cx,Cy)
      for i in range(1,N):
        Height_=height(xyh[i][0],xyh[i][1],xyh[i][2],Cx,Cy)
        if Height==Height_:
          if i==N-1:
            return (Cx,Cy,Height)
          continue
        else:
          break
Cx,Cy,H=find(N)
print(Cx,"",Cy," ",H)
Problem p03244 (python)

Fixed submission:
import bisect
from collections import deque
from collections import defaultdict
#from math import factorial
from math import sqrt
n=int(input())
v=list(map(int,input().split()))

a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])

A=defaultdict(int)
B=defaultdict(int)
for i in a:
    A[i]+=1
for i in b:
    B[i]+=1
A[0]=0
B[0]=0
Amax=0
Akey=0
Bmax=0
Bkey=0

for key in A.keys():
    if Amax<A[key]:
        Akey=key
        Amax=A[key]
for key in B.keys():
    if Bmax<B[key]:
        Bkey=key
        Bmax=B[key]
min=10**5
n_=int(n/2)
for i in B.keys():
    min_=(n_-Amax)+(n_-B[i])
    if Akey!=i and min>min_:
        min=min_
for i in A.keys():
    min_=(n_-A[i])+(n_-Bmax)
    if Bkey!=i and min>min_:
        min=min_
print(min)

Buggy submission (verdict: Runtime Error):
import bisect
from collections import deque
from collections import defaultdict
#from math import factorial
from math import sqrt
n=int(input())
v=map(int,input().split())

a=[]
b=[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])

A=defaultdict(int)
B=defaultdict(int)
for i in a:
    A[i]+=1
for i in b:
    B[i]+=1
A[0]=0
B[0]=0
Amax=0
Akey=0
Bmax=0
Bkey=0

for key in A.keys():
    if Amax<A[key]:
        Akey=key
        Amax=A[key]
for key in B.keys():
    if Bmax<B[key]:
        Bkey=key
        Bmax=B[key]
min=10**5
n_=n/2
for i in B.keys():
    min_=(n_-Amax)+(n_-B[i])
    if Akey!=i and min>min_:
        min=min_
for i in A.keys():
    min_=(n_-A[i])+(n_-Bmax)
    if Bkey!=i and min>min_:
        min=min_
print(min)
Problem p03260 (python)

Fixed submission:
A,B=map(int,input().split())
if (A*B)%2==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A=list(map(int,input().split()))
sum=1
for i in A:
    sum*=i
if sum%2=1:
    print('Yes')
else:
    print("No")
Problem p03282 (python)

Fixed submission:
S=input()
K=int(input())
num=100000
for i in range(len(S)):
    if S[i]!="1":
        num=i
        T=int(S[i])
        break
if K-1<num:
    print(1)
else:
    print(T)

Buggy submission (verdict: Runtime Error):
S=input()
K=input()
num=-1
for i in range(len(S)):
    if S[i]!="1":
        num=i
        T=int(S[i])
        break
if K-1<num:
    print(1)
else:
    print(T)
Problem p03308 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()
print(A[-1]-A[0])

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A.sort()
prit(A[-1]-A[0])
Problem p03311 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
    B.append(A[i]-(i+1))
B.sort()
b=B[N//2]
ans=0
for i in B:
    ans+=abs(i-b)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
    B.append(A[i]-(i+1))
B.sort()
b=B[N/2]
ans=0
for i in B:
    ans+=abs(i-b)
print(ans)
Problem p03316 (python)

Fixed submission:
N=int(input())
s=0
S=str(N)
for i in S:
    s+=int(i)
if N%s==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())
s=0
S=str(N):
for i in S:
    s+=int(i)
if N%s==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())
s=0
S=str(N):
for i in S:
    s+=i
if N%s==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())
s=0
S=str(N):
for i in S:
    s+=i
if S%s==0:
    print("Yes")
else:
    print("No")
Problem p03324 (python)

Fixed submission:
D,N=map(int,input().split())
if N==100:
    N+=1
print((100**D)*N)

Buggy submission (verdict: Runtime Error):
D,N=map(int,input().split())
if N==100:
    print(2/0)
print((100**D)*N)
Problem p03339 (python)

Fixed submission:
N=int(input())
S=input()
S="E"+S+"W"
E=[0]*(N+2)
W=[0]*(N+2)
for i in range(len(S)-1):
    if S[i]=="W":
        E[i+1]=E[i]+1
    else:
        E[i+1]=E[i]

for i in range(len(S)-1,0,-1):
    if S[i]=="E":
         W[i-1]=W[i]+1
    else:
         W[i-1]=W[i]
ans=10**9
for i in range(N):
    ans=min(ans,E[i+1]+W[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
S="E"+S+"W"
E=[0]*(N+2)
W=[0]*(N+2)
for i in range(len(S)-1):
    if S[i]=="W":
        E[i+1]=E[i]+1
    else:
        E[i+1]=E[i]
 
for i in range(len(S)-1,0,-1):
    if S[i]=="E":
         W[i-1]=W[i]+1
    else:
         W[i-1]=W[i]
ans=10**9
for i in range(N):
    ans=min(ans,E[i+1]+W[i+1])
print(ans)
N=int(input())
S=input()
S="E"+S+"W"
E=[0]*(N+2)
W=[0]*(N+2)
for i in range(len(S)-1):
    if S[i]=="W":
        E[i+1]=E[i]+1
    else:
        E[i+1]=E[i]

for i in range(len(S)-1,0,-1):
    if S[i]=="E":
         W[i-1]=W[i]+1
    else:
         W[i-1]=W[i]
ans=10**9
for i in range(N):
    ans=min(ans,E[i+1]+W[i+1])
print(ans)
Problem p03361 (python)

Fixed submission:
H,W=map(int,input().split())
S=[]
for i in range(H):
    s=input()
    S.append(s)
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            continue
        l=[(j-1,i),(j+1,i),(j,i+1),(j,i-1)]
        koritu=True
        for x,y in l:
            if 0<=y<=H-1 and  0<=x<=W-1:
                koritu=koritu and S[y][x]=="."
        if koritu:
            print("No")
            quit()
print("Yes")

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[]
for i in range(H):
    s=input()
    S.append(s)
for i in range(H):
    for j in range(W):
        if S[j][i]==".":
            continue
        l=[(j-1,i),(j+1,i),(j,i+1),(j,i-1)]
        koritu=True
        for y,x in l:
            if 0<=y<=H-1 and  0<=x<=W-1:
                koritu=koritu and S[y][x]=="."
        if koritu:
            print("No")
            quit()
print("Yes")
Problem p03363 (python)

Fixed submission:
from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy
from math import log
from itertools import accumulate


N=int(input())
A=list(map(int,input().split()))
sums=list(accumulate([0]+A))
def nCr(n,r):
    a=factorial(n)
    b=factorial(n-r)
    c=factorial(r)
    return int(a//(b*c))
dic=defaultdict(int)
for i in sums:
    dic[i]+=1
ans=0
for i in dic.keys():
    if dic[i]>=2:
        ans+=nCr(dic[i],2)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate


N=int(input())
A=list(map(int,input().split()))
sums=list(accumulate([0]+A))
def nCr(n,r):
    a=factorial(n)
    b=factorial(n-r)
    c=factorial(r)
    return int(a//(b*c))
dic=defaultdict(int)
for i in sums:
    dic[i]+=1
ans=0
for i in dic.keys():
    if dic[i]>=2:
        ans+=nCr(dic[i],2)
print(ans)
Problem p03372 (python)

Fixed submission:
N,C=map(int,input().split())
xv=[(0,0)]
xv_=[]
for i in range(N):
    x,v=map(int,input().split())
    xv.append((x,v))
    xv_.append((x,v))
xv_.append((C,0))
xv_.reverse()
r=[0]*(N+1)
r_=[0]*(N+1)
for i in range(N):
    r[i+1]=r[i]-(xv[i+1][0]-xv[i][0])+xv[i+1][1]
    r_[i+1]=max(r_[i],r[i+1]-xv[i+1][0])
l=[0]*(N+1)
l_=[0]*(N+1)
for i in range(N):
    l[i+1]=l[i]-abs(xv_[i+1][0]-xv_[i][0])+xv_[i+1][1]
    l_[i+1]=max(l_[i],l[i+1]-(C-xv_[i+1][0]))
ans=0
for i in range(1,N+1):
    ans=max(r[i]+l_[N-i],ans)
    ans=max(l[i]+r_[N-i],ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=[]
for i in range(29):
  T=2**i
  B_=list(B)
  A_=list(A)
  t=0
  for j in range(N):
    B_[j]%=2*T
    A_[j]%=2*T
  B_.sort()
  for j in range(N):
    a=A_[j]
    p=bisect.bisect_left(B_,T-a)
    q=bisect.bisect_left(B_,2*T-a)
    r=bisect.bisect_left(B_,3*T-a)
    s=bisect.bisect_left(B_,4*T-a)
    t+=(q-p)+(s-r)
  ans.append(t%2)
a=0
for i in range(29):
  a+=2**i*ans[i]
print(a)
Problem p03385 (python)

Fixed submission:
S=input()
#N=int(input())
#a,b,x=map(int,input().split())
s=1
for i in S:
    if i=="a":
        s*=2
    if i=="b":
        s*=3
    if i=="c":
        s*=5
if s==30:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
S=input()
#N=int(input())
#a,b,x=map(int,input().split())
s=1
for i in range(S):
    if i=="a":
        s*=2
    if i=="b":
        s*=3
    if i=="c":
        s*=5
if s==30:
    print("Yes")
else:
    print("No")
Problem p03399 (python)

Fixed submission:
A=int(input())
B=int(input())
C=int(input())
D=int(input())
print(min([A,B])+min([C,D]))

Buggy submission (verdict: Runtime Error):
#S=input()
#N=int(input())
A,B,C,D=map(int,input().split())
print(min([A,B])+min([C,D]))
Problem p03407 (python)

Fixed submission:
#S=input()
#N=int(input())
A,B,C=map(int,input().split())
if A+B>=C:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=[]
for i in range(28):
  T=2**i
  B_=list(B)
  A_=list(A)
  t=0
  for j in range(N):
    B_[j]%=2*T
    A_[j]%=2*T
  B_.sort()
  for j in range(N):
    a=A_[j]
    p=bisect.bisect_left(B_,T-a)
    q=bisect.bisect_left(B_,2*T-a)
    r=bisect.bisect_left(B_,3*T-a)
    s=bisect.bisect_left(B_,4*T-a)
    t+=(q-p)+(s-r)
  ans.append(t%2)
a=0
for i in range(28):
  a+=2**i*ans[i]
print(a)
Problem p03415 (python)

Fixed submission:
c=[]
for i in range(3):
    ci=input()
    c.append(ci)
print(c[0][0]+c[1][1]+c[2][2])

Buggy submission (verdict: Runtime Error):
c=[]
for i in range(3):
    ci=input()
    a.append(ci)
print(c[0][0]+c[1][1]+c[2][2])

Buggy submission (verdict: Runtime Error):
c=[]
for i in range(3):
    ci=input()
    a.append(ci)
print(c[1][1]+c[2][2]+c[3][3])
Problem p03450 (python)

Fixed submission:
#重み付きUnion-Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        px = find(par[x])
        wei[x] += wei[par[x]]
        par[x] = px
        return px

#xの根から距離
def weight(x):
    find(x)
    return wei[x]


#w[y]=w[x]+wとなるようにxとyを併合
def unite(x,y,w):
    w += wei[x]-wei[y]
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
            w = -w
        par[x] += par[y]
        par[y] = x
        wei[y] = w
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#x,yが同じ集合に属するときのwei[y]-wei[x]
def diff(x,y):
    return weight(y)-weight(x)

n,m = map(int,input().split())

#初期化
#par:根なら-size,子なら親の頂点
#wei:親からの距離,根なら0
par = [-1]*n
wei = [0]*n

for i in range(m):
    l,r,d = map(int,input().split())
    l,r = l-1,r-1
    if same(l,r):
        if d != diff(l,r):
            print('No')
            exit()
    else:
        unite(l,r,d)
print('Yes')

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

N,M=map(int,input().split())
if M==0:
    print("Yes")
    quit()
G=[[] for i in range(N)]
for i in range(M):
    l,r,d=map(int,input().split())
    G[l-1].append((l-1,r-1,d))
x=[-1]*N
y=[1]*N
stack=deque()
for i in range(N):
    if y[i]:
        stack.extend(G[i])
        y[i]=0
    if len(stack)==0:
        continue
    while(stack):

        l,r,d=stack.popleft()

        if x[l]==-1:
            x[l]=0
        if x[r]==-1:
            x[r]=x[l]+d
            continue
        if x[r]!=x[l]+d:
            print("No")
            quit()
        stack.extend(G[r])
        y[r]=0
if max(x)>10**9:
    print("No")
else:
    print("Yes")
Problem p03504 (python)

Fixed submission:
from collections import defaultdict
from copy import deepcopy
from math import log
from itertools import accumulate

N,C=map(int,input().split())
T=10**5+1
programs=defaultdict(list)
for i in range(N):
    s,t,c=map(int,input().split())
    programs[c].append((s,t))
imos=[0]*(T)
for c,p in programs.items():
    p.sort()
    ps,pt=p[0]
    for s,t in p[1:]:
        if pt==s:
            pt=t
            continue
        imos[ps-1]+=1
        imos[pt]-=1
        ps,pt=s,t
    imos[ps-1]+=1
    imos[pt]-=1
print(max(accumulate(imos)))

Buggy submission (verdict: Runtime Error):
N,C=map(int,input().split())
T=10**5+2
sm=[0]*(T)
l=[]
r=[]
c=[]
for i in range(N):
    s,t,k=map(int,input().split())
    l.append(s)
    r.append(t)
    c.append(k)
for i in range(1,C+1):
    tt=[0]*T
    for j in range(N):
        if c[j]==i:
            tt[l[j]*2]+=1
            tt[r[j]*2+1]-=1
    for j in range(T):
        if tt[j]>0:
            sm[j-1]+=tt[j]
        else:
            sm[j]+=tt[j]
for j in range(T-1):
    sm[j+1]+=sm[j]
print(max(sm))
Problem p03555 (python)

Fixed submission:

c=input()
d=input()
a=c
b=d
c=c[::-1]
d=d[::-1]
if a==d and b==c:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  string c1,c2;
  cin >>c1>>c2;
  string c3=c1,c4=c2;
  reverse(c1.begin(),c1.end());
  reverse(c2.begin(),c2.end());
  if (c1==c4 and c2==c3) cout <<"YES"<<endl;
  else cout <<"NO"<<endl;
}
Problem p03558 (python)

Fixed submission:
import heapq
K=int(input())
G=[[((i+1)%K,1)] for i in range(K)]
for i in range(K):
    a=(i*10)%K
    G[i].append((a,0))
def dijkstra(G,s):#Gはi->jの辺をG[i]=[(j,cost),...]で保存
  INF=10**19
  n=len(G)
  d=[INF]*n#n=node数
  d[s]=0
  visited={s}
  que=[(0,s)]
  while(que):
    p=heapq.heappop(que)
    v=p[1]
    visited.add(v)
    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heapq.heappush(que,(d[node],node))
  return d

d=dijkstra(G,1)
print(d[0]+1)

Buggy submission (verdict: Runtime Error):
K=int(input())
G=[[(1,(i+1)%K)] for i in range(K)]
for i in range(K):
    a=(i*10)%K
    G[i].append((0,a))
stack=list(G[1])
heapq.heapify(stack)
reached=[0]*K
reached[1]=1
while(stack):
    c,g=heapq.heappop(stack)
    if g==0:
        print(c+1)
        quit()
    reached[g]=1
    for i in G[g]:
        if reached[i[1]]:
            continue
        heapq.heappush(stack,(c+i[0],i[1]))

Buggy submission (verdict: Runtime Error):
from math import log
K=int(input())
N=K
def func(N):
    res=0
    while(N!=0):
        res+=N%10
        N//=10
    return res
ans=func(K)
if ans==1:
    print(ans)
    quit()
n=ceil(log(K,10))
MOD=10**(n)
K=K*(ceil((10**n)/K))
ans=min(ans,func(K))
used=[0]*N
K%=MOD
K*=10
while(True):
    K%=N
    if K==0:
        print(1)
        quit()
    ans=min(ans,func(K)+1)
    if used[K]:
        print(ans)
        quit()
    used[K]=1
    K*=10
Problem p03587 (python)

Fixed submission:
S=input()
ans=0
for i in S:
    
    ans+=int(i)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from copy import deepcopy
from math import log
N,K=map(int,input().split())
AB=[0]*N
dic=defaultdict(int)
#n=int(ceil(log(K,2)))+1
for i in range(N):
    a,b=map(int,input().split())
    if a in dic.keys():
        AB[dic[a]]=[a,AB[dic[a]][1]+b]
    else:
        dic[a]=i
        AB[i]=[a,b]
ans=sum([b for a,b in AB if K|a==K])
print(bin(K))
for i in range(int.bit_length(K)-1,0,-1):
    if not K &(1<<i):
        continue
    m=K & ~(1<<i)|(1<<i)-1
    print(bin(m))
    s=sum([b for a,b in AB if m | a ==m])
    ans=max(s,ans)
print(ans)
Problem p03605 (python)

Fixed submission:
N=int(input())
if N//10==9 or N%10==9:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())
ans=0
for i in range(N):
    l,r=map(int,input().split())
    ans=ans+l-r+1
print(ans)