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

Fixed submission:
n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x: x[0]*1000000000000+x[1])
l.append([-1,-1])
a=[]
b=[]
for i in range(n):
    if l[i][0]==l[i+1][0]:
        b.append(l[i][1])
    else:
        a.append(l[i][1])
ans=len(a)*len(a)+sum(a)
#print(ans)
if len(b)>0:
    ans+=sum(b)
    b.sort()
    a.sort()
    i=0
    ai=0
    bi=0
    an=len(a)
    bn=len(b)
    while i<n-k:
        if ai<an and bi<bn:
            ap=a[ai]
            bp=b[bi]
            if ap+2*(an-ai-1)+1>=bp:
                bi+=1
                ans-=bp
            else:
                ans-=ap+2*(an-ai-1)+1
                ai+=1
        elif ai<an:
            ap=a[ai]
            ans-=ap+2*(an-ai-1)+1
            ai+=1
        elif bi<bn:
            ans-=b[bi]
            bi+=1
        i+=1
    print(ans)
else:
    a.sort(reverse=True)
    print(sum(a[:k])+k*k)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
p=[[] for i in range(n)]
for i in range(n):
    p[l[i][0]-1].append(l[i][1])
a=[]
b=[]
for i in range(n):
    if len(p[i])>0:
        mp=max(p[i])
        f=0
        for j in p:
            if f==0 and j==mp:
                a.append(j)
                f+=1
            else:
                b.append(j)
ans=len(a)*len(a)+sum(a)
if b:
    ans+=sum(b)
    b.sort()
    a.sort()
    i=0
    ai=0
    bi=0
    an=len(a)
    bn=len(b)
    while i<n-k:
        if ai<an and bi<bn:
            ap=a[ai]
            bp=b[bi]
            if ap+2*(an-ai-1)+1>=bp:
                bi+=1
                ans-=bp
            else:
                ans-=ap+2*(an-ai-1)+1
                ai+=1
        elif ai<an:
            ap=a[ai]
            ans-=ap+2*(an-ai-1)+1
            ai+=1
        elif bi<bn:
            ans-=b[bi]
            bi+=1
        i+=1
    print(ans)
else:
    a.sort(reverse=True)
    print(sum(a[:k])+k*k)
Problem p03151 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=sum(a)-sum(b)
if s<0:
    print(-1)
else:
    c=[0]*n
    po=0
    ze=0
    ne=0
    nc=0
    for i in range(n):
        c[i]=a[i]-b[i]
        if c[i]>0:
            po+=c[i]
        elif c[i]<0:
            ne-=c[i]
            nc+=1
        else:
            ze+=1
    ans=0
    c=sorted(c)
    for i in range(n-1,-1,-1):
        if ne>0:
            ans+=1
        if c[i]>0:
            ne=ne-c[i]
        
    print(nc+ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=sum(b)-sum(a)
if s<0:
    print(-1)
else:
    c=[0]*n
    for i in range(n):
        c[i]=a[i]-b[i]
    ans=0
    c=sorted(c)
    for i in range(n):
        if s>=c[i]:
            ans+=1
            s-=c[i]
print(n-ans)
Problem p03161 (python)

Fixed submission:
n,k=map(int,input().split())
li=list(map(int,input().split()))
ans=[0]*n
ans[1]=abs(li[0]-li[1])
for i in range(2,n):
    ans[i]=min([y+z for (y,z) in zip(map(lambda x: abs(x-li[i]),li[max(0,i-k):i]),ans[max(0,i-k):i])])
    
print(ans[n-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
li=list(map(int,input().split()))
ans=[0]*n
ans[1]=abs(li[0]-li[1])
for i in range(2,n):
    ans[i]=min(map(sum,map(lambda x: abs(x-li[i]),li[max(0,i-k):i]),ans[max(0,i-k):i]))
    
print(ans[n-1])
Problem p03164 (python)

Fixed submission:
n,W=map(int,input().split())
w=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)+1
dp=[10**10 for i in range(sum(v)+1)]
dp[0]=0
for i in range(n):
    for j in range(V-1,-1,-1):
        if dp[j]!=10**10:
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i])
for i in range(V-1,-1,-1):
    if dp[i]<=W:
        print(i)
        exit()

Buggy submission (verdict: Runtime Error):
n,W=map(int,input().split())
w=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)+1
dp=[10**10 for i in range(sum(v)+1)]
dp[0]=0
for i in range(n):
    for j in range(V,-1,-1):
        if dp[j]!=10**10:
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i])
for i in range(V,-1,-1):
    if dp[i]<=W:
        print(i)
        exit()

Buggy submission (verdict: Runtime Error):
n,W=map(int,input().split())
w=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)+1
dp=[10**10 for i in range(sum(v)+1)]
dp[0]=0
for i in range(n):
    for j in range(V,-1,-1):
        if dp[j]!=10**10:
            dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[j])
for i in range(V,-1,-1):
    if dp[i]<=W:
        print(i)
        exit()
Problem p03165 (python)

Fixed submission:
import sys
input=sys.stdin.readline
def main():
    s=tuple(input())
    t=tuple(input())
    n=len(s)
    m=len(t)
    dp=[[0 for i in range(m+1)] for j in range(n+1)]
    for i in range(n):
        for j in range(m):
            if s[i]==t[j]:
                dp[i+1][j+1]=dp[i][j]+1
            else:
                if dp[i+1][j]>dp[i][j+1]:
                    dp[i+1][j+1]=dp[i+1][j]
                else:
                    dp[i+1][j+1]=dp[i][j+1]
    p=dp[n][m]
    ans=['' for _ in range(p)]
    n-=1
    m-=1
    while p>0:
        if s[n]==t[m]:
            ans[p-1]=s[n]
            n-=1
            m-=1
            p-=1
        elif dp[n+1][m+1]==dp[n][m+1]:
            n-=1
        else:
            m-=1
    print(''.join(ans)) 
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
s=list(input())
t=list(input())
n=len(s)
m=len(t)
dp=[[[] for i in range(m+1)] for j in range(n+1)]
#dps=[[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j].append(s[i])
            #dps[i+1][j+1]=dps[i][j]+1
        else:
            if len(dp[i+1][j])>len(dp[i][j+1]):
                dp[i+1][j+1]=dp[i+1][j]
                #dps[i+1][j+1]=dps[i+1][j]
            else:
                dp[i+1][j+1]=dp[i][j+1]
                #dps[i+1][j+1]=dps[i][j+1]
print(''.join(dp[n][m]))
Problem p03166 (python)

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

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

visited = [False]*n
calculated = [False]*n
dp = [1]*n# Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1

def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ
        return dp[v]
    visited[v] = True
    for u in to[v]: # 全ての辺をなめる
        res = dfs(u)
        if res == -1: return -1 # ループがあれば-1を返す
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

def main():
    for i in range(m):
        a,b=map(int,input().split())
        a-=1
        b-=1
        to[a].append(b)
    ans = 0
    for i in range(n):
        res = dfs(i)
        ans = max(ans, res)
    print(ans-1)
    return

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

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

visited = [False]*n
calculated = [False]*n
dp = [1]*MAXV # Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1

def dfs(v):
    if visited[v]:
        if not calculated[v]:
            return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ
        return dp[v]
    visited[v] = True
    for u in to[v]: # 全ての辺をなめる
        res = dfs(u)
        if res == -1: return -1 # ループがあれば-1を返す
        dp[v] = max(dp[v], res+1)
    calculated[v] = True
    return dp[v]

def main():
    to=[[] for i in range(n)]
    for i in range(m):
        a,b=map(int,input().split())
        a-=1
        b-=1
        to[a].append(b)
    ans = 0
    for i in range(n):
        res = dfs(i)
        ans = max(ans, res)
    print(ans)
    return

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
dp=[[0]*m for i in range(m)]
#me=[[[]*m] for i in range(m)]
he=[[]*m for i in range(m)]
ta=[[]*m for i in range(m)]
ans=0
for i in range(n):
    a,b=map(int,input().split())
    if dp[a-1][b-1]==0:
        dp[a-1][b-1]=1
        he[a-1]+=[b-1]
        ta[b-1]+=[a-1]
    a=a-1
    b=b-1
    for j in he[b]:
        dp[a][j]=max(dp[a][j],dp[b][j]+1)
        ans=max(ans,dp[a][j])
    for j in ta[a]:
        dp[j][b]=max(dp[j][b],dp[j][a]+1)
        ans=max(ans,dp[j][b])
print(ans)
Problem p03175 (python)

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10**9)
n=int(input())
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
q=deque([0])
v=[0]*n
v[0]=1
gp=[[] for i in range(n)]
while q:
    p=q.popleft()
    for i in g[p]:
        if v[i]==0:
            v[i]=1
            gp[p].append(i)
            q.append(i)
MOD=10**9+7
flag=[0]*n
dp=[[0,0] for i in range(n)]
def f(i):
    if flag[i]:
        return 0
    flag[i]=1
    dp[i][0]=1
    dp[i][1]=1
    for j in gp[i]:
        f(j)
        dp[i][0]=dp[i][0]*(dp[j][0]+dp[j][1])%MOD
        dp[i][1]=dp[i][1]*dp[j][0]
        dp[i][0]%=MOD
        dp[i][1]%=MOD
    return 0
f(0)
print((dp[0][0]+dp[0][1])%MOD)

Buggy submission (verdict: Runtime Error):
from collections import deque
n=int(input())
g=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
q=deque([0])
v=[0]*n
v[0]=1
gp=[[] for i in range(n)]
while q:
    p=q.popleft()
    for i in g[p]:
        if v[i]==0:
            v[i]=1
            gp[p].append(i)
            q.append(i)
MOD=10**9+7
flag=[0]*n
dp=[[0,0] for i in range(n)]
def f(i):
    if flag[i]:
        return 0
    flag[i]=1
    dp[i][0]=1
    dp[i][1]=1
    for j in gp[i]:
        f(j)
        dp[i][0]=dp[i][0]*(dp[j][0]+dp[j][1])%MOD
        dp[i][1]=dp[i][1]*dp[j][0]
    return 0
f(0)
print((dp[0][0]+dp[0][1])%MOD)
Problem p03192 (python)

Fixed submission:
s=list(str(input()))
ans=0
for i in range(4):
    if s[i]=='2':
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
s=list(str(input()))
ans=0
for i in range(4):
    id s[i]=='2':
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
s=list(input())
ans=0
for i in range(4):
    id s[i]=='2':
        ans+=1
print(ans)
Problem p03216 (python)

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
l=input()
q=int(input())
kl=tuple(map(int,input().split()))
for k in kl:
    d=0
    m=0
    dm=0
    ans=0
    for j in range(n):
        if l[j]=='D':
            d+=1
        elif l[j]=='M':
            m+=1
            dm+=d
        elif l[j]=='C':
            ans+=dm
        if j>=k-1:
            if l[j-k+1]=='D':
                dm-=m
                d-=1
            elif l[j-k+1]=='M':
                m-=1
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n=int(input())
l=input()
q=int(input())
kl=tuple(map(int,input().split()))
for i in kl:
    k=i
    d=0
    m=0
    dm=0
    ans=0
    for j in range(n):
        if l[j]=='D':
            d+=1
        elif l[j]=='M':
            m+=1
            dm+=d
        else l[j]=='C':
            ans+=dm
        if j>=k-1:
            if l[j-k+1]=='D':
                dm-=m
                d-=1
            elif l[j-k+1]=='M':
                m-=1
    print(ans)
Problem p03231 (python)

Fixed submission:
import fractions
N, M = map(int, input().split())
S = input()
T = input()
ans = (N * M) // fractions.gcd(N, M)
n = N // fractions.gcd(N, M)
m = M // fractions.gcd(N, M)
for i in range(min(N // n, M // m)):
    tmpn = S[n * i]
    tmpm = T[m * i]
    if tmpn != tmpm:
        ans = -1
        break

print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
n,m=map(int,input().split())
s=list(input())
t=list(input())
if s[0]!=t[0]:
    print(-1)
    exit()
p=n*m//fractions.gcd(n,m)
sf=p//n
tf=p//m
for i in range(1,p):
    if i%n==i%m==0:
        if s[i//m]!=t[i//n]:
        print(-1)
        exit()
print(p)

Buggy submission (verdict: Runtime Error):
import fractions
n,m=map(int,input().split())
s=list(input())
t=list(input())
if s[0]!=t[0]:
    print(-1)
    exit()
p=n*m//fractions.gcd(n,m)
sf=p//n
tf=p//m
for i in range(1,p):
    if i%n==i%m==0:
        if s[i//m]!=l[i//n]:
        print(-1)
        exit()
print(p)
Problem p03244 (python)

Fixed submission:
n=int(input())

l=list(map(int,input().split()))

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm1[0])
else:
    if km1[0]-km2[0]>=gm1[0]-gm2[0]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])

Buggy submission (verdict: Runtime Error):
n=int(input())

l=list(map(int,input().split()))

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm[0])
else:
    if km1[1]-km2[1]>=gm1[1]-gm2[1]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])

Buggy submission (verdict: Runtime Error):
n=int(input())

l=list(int,input().split())

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm[0])
else:
    if km1[1]-km2[1]>=gm1[1]-gm2[1]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])
Problem p03263 (python)

Fixed submission:
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(map(int,input().split())))
    
ans=[]  
for i in range(h-1):
    for j in range(w):
        if a[i][j]%2==1:
            ans.append([i+1,j+1,i+2,j+1])
            a[i+1][j]+=1
  
for j in range(w-1):
    if a[h-1][j]%2==1:
        ans.append([h,j+1,h,j+2])
        a[h-1][j+1]+=1
print(len(ans))
for i in range(len(ans)):
    print(ans[i][0],end=" ")
    print(ans[i][1],end=" ")
    print(ans[i][2],end=" ")
    print(ans[i][3])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(input()))
    
ans=[]  
for i in range(h-1):
    for j in range(w):
        if a[i][j]%2==1:
            ans.append([i,j,i+1,j])
            a[i+1][j]+=1
  
for j in range(w-1):
    if a[h-1][j]%2==1:
        ans.append([h-1,j,h-1,j+1])
        a[h-1][j+1]+=1
print(len(ans))
for i in range(len(ans)):
    print(ans[i][0],end=" ")
    print(ans[i][1],end=" ")
    print(ans[i][2],end=" ")
    print(ans[i][3])
Problem p03273 (python)

Fixed submission:
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
wl=[]
for i in range(h):
    wf=0
    for j in range(w):
        if l[i][j]=='.':
            wf+=1
    if wf<w:
        wl.append(i)
    
hl=[]
for i in range(w):
    hf=0
    for j in range(h):
        if l[j][i]=='.':
            hf+=1
    if hf<h:
        hl.append(i)
for i in wl:
    for j in hl:
        print(l[i][j],end='')
    print()

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
wl=[]
for i in range(h):
    wf=0
    for j in range(w):
        if l[i][j]=='.':
            wf+=1
    if wf<w:
        wl.append(i)
    
hl=[]
for i in range(w):
    hf=0
    for j in range(h):
        if l[j][i]=='.':
            hf+=1
    if hf<h:
        hl.append(i)
for i in hl:
    for j in wl:
        print(l[i][j],end='')
    print()

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
wl=[]
for i in range(h):
    wf=0
    for j in range(w):
        if l[i][j]=='.':
            wf+=1
    if wf<w:
        wl.append(i)
    
hl=[]
for i in range(w):
    hf=0
    for j in range(h):
        if l[j][i]=='.':
            hf+=1
    if hf<h:
        hl.append(i)
for i in hl:
    for j in wl:
        print(l[i][j],end='')
    print(/n)
Problem p03274 (python)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=0
zf=0
for i in range(n):
    if l[i]==0:
        zf=1
if zf==0:
    l.append(0)
    l.sort()
else:
    k-=1
if k==0:
    print(0)
    exit()
n=len(l)
pl=[]
nl=[]
for i in range(n):
    if l[i]==0:
        m=i
    elif l[i]>0:
        pl.append(l[i])
    else:
        nl.append(-l[i])
        
ans=1e10
for i in range(min(k-1,len(pl))):
    a=len(nl)-k+i+1
    if a>=0 and a<len(nl):
        ans=min(ans,2*pl[i]+nl[len(nl)-k+i+1])
for i in range(min(k-1,len(nl))):
    a=len(nl)-i-1
    b=k-i-2
    if b>=0 and b<len(pl):
        ans=min(ans,2*nl[a]+pl[k-i-2])
if k<=len(pl):
    ans=min(ans,pl[k-1])
if k<=len(nl):
    ans=min(ans,nl[len(nl)-k])
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=0
zf=0
for i in range(n):
    if l[i]==0:
        zf=1
if zf==0:
    l.append(0)
    l.sort()
else:
    k-=1
if k==0:
    print(0)
    exit()
n=len(l)
pl=[]
nl=[]
for i in range(n):
    if l[i]==0:
        m=i
    elif l[i]>0:
        pl.append(l[i])
    else:
        nl.append(-l[i])
        
ans=1e10
for i in range(min(k-1,len(pl))):
    a=len(nl)-k+i+1
    if a>=0 and a<len(nl):
        ans=min(ans,2*pl[i]+nl[len(nl)-k-i+1])
for i in range(min(k-1,len(nl))):
    a=len(nl)-i-1
    b=k-i-2
    if b>=0 and b<len(pl):
        ans=min(ans,2*nl[a]+pl[k-i-2])
if k<=len(pl):
    ans=min(ans,pl[k-1])
if k<=len(nl):
    ans=min(ans,nl[len(nl)-k])
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=0
zf=0
for i in range(n):
    if l[i]==0:
        zf=1
if zf==0:
    l.append(0)
    l.sort()
else:
    k-=1
    
n=len(l)
pl=[]
nl=[]
for i in range(n):
    if l[i]==0:
        m=i
    elif l[i]>0:
        pl.append(l[i])
    else:
        nl.append(-l[i])
        
ans=1e10
for i in range(min(k,len(pl))):
    a=len(nl)-k-i+1
    if a>=0 and a<len(nl):
        ans=min(ans,2*pl[i]+nl[len(nl)-k-i+1])
for i in range(min(k,len(nl))):
    a=len(nl)-i-1
    b=k-i-2
    if b>=0 and b<len(pl):
        ans=min(ans,2*nl[a]+pl[k-i-2])
if k<=len(pl):
    ans=min(ans,pl[k-1])
if k<=len(nl):
    ans=min(ans,nl[len(nl)-k])
print(ans)
Problem p03283 (python)

Fixed submission:
n,m,q=map(int,input().split())
g=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    #a-=1
    #b-=1
    g[a][b]+=1
    
for i in range(n):
    for j in range(n+1):
        g[i+1][j]+=g[i][j]
for i in range(n+1):
    for j in range(n):
        g[i][j+1]+=g[i][j]
for i in range(q):
    a,b=map(int,input().split())
    a-=1
    print(g[b][b]+g[a][a]-g[a][b]-g[b][a])
#print(g)

Buggy submission (verdict: Runtime Error):
n,m,q=map(int,input().split())
g=[[0 for i in range(n+2)] for j in range(n+2)]
for i in range(m):
    a,b=map(int,input().split())
    #a-=1
    #b-=1
    g[a][a]+=1
    g[a][b+1]-=1
    g[b+1][a]-=1
    g[b+1][b+1]+=1
for i in range(n):
    for j in range(n+1):
        g[i+1+1][1+j]+=g[1+i][1+j]
for i in range(n+1):
    for j in range(n):
        g[1+i][1+j+1]+=g[1+i][j+1]
        
#r=[[0 for i in range(n+2)] for j in range(n+2)]
for i in range(n+1):
    for j in range(n+2):
        g[i+1][j]+=g[i][j]
for i in range(n+2):
    for j in range(n+1):
        g[i][j+1]+=g[i][j]
for i in range(q):
    a,b=map(int,input().split())
    b+=1
    print(r[b][b]+r[a][a]-2*r[a][b])
Problem p03290 (python)

Fixed submission:
d,g=map(int,input().split())
l=[]
for i in range(d):
    l.append(list(map(int,input().split())))
op=[[0],[1]]
for i in range(d-1):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
    op=tmp
ans=10**10
for i in op:
    z=0
    k=[]
    c=0
    for j in range(d):
        if i[j]==1:
            z+=l[j][0]*100*(j+1)+l[j][1]
            c+=l[j][0]
        else:
            k.append(j)
    if z>=g:
        ans=min(ans,c)
    else:
        if len(k)>0:
            m=max(k)
            p=g-z
            cn=-(-p//((m+1)*100))
            if cn<l[m][0]:
                ans=min(ans,c+cn)
print(ans)

Buggy submission (verdict: Runtime Error):
d,g=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
op=[[0],[1]]
for i in range(d-1):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
    op=tmp
ans=10**10
for i in op:
    z=0
    k=[]
    c=0
    for j in range(d):
        if i[j]==1:
            z+=l[j][0]*100*(j+1)+l[j][1]
            c+=l[j][0]
        else:
            k.append(j)
    if z>=g:
        ans=min(ans,c)
    else:
        if len(k)>0:
            m=max(k)
            p=g-z
            cn=-(-p//((m+1)*100))
            if cn<l[m][0]:
                ans=min(ans,c+cn)
print(ans)
Problem p03305 (python)

Fixed submission:
import heapq
import sys
input=sys.stdin.readline
def dijk(s,edge,n):
    used = [-1] * n #True:未確定
    used[s] = 0
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,[e[0],e[1]])
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if used[minedge[1]]>=0:
            continue
        v = minedge[1]
        kai=minedge[0]
        used[v] = kai
        for e in edge[v]:
            if used[e[1]]==-1:
                heapq.heappush(edgelist,[e[0]+kai,e[1]])                   
    return used

################################
def main():
    n,m,s,t = map(int,input().split()) #n:頂点数　w:辺の数
    s-=1
    t-=1
    edge1 = [[] for i in range(n)]
    edge2= [[] for i in range(n)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for i in range(m):
        x,y,z,w = map(int,input().split())
        edge1[x-1].append([z,y-1])
        edge1[y-1].append([z,x-1])
        edge2[x-1].append([w,y-1])
        edge2[y-1].append([w,x-1])
    en=dijk(s,edge1,n)
    su=dijk(t,edge2,n)
    ans=[]
    aa=10**20
    for i in range(n-1,-1,-1):
        aa=min(aa,en[i]+su[i])
        ans.append(10**15-aa)
    for i in range(n-1,-1,-1):
        print(ans[i])
if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import heapq
import sys
input=sys.stdin.readline
def dijk(s,edge):
    used = [-1] * n #True:未確定
    used[s] = 0
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,[e[0],e[1]])
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if used[minedge[1]]>=0:
            continue
        v = minedge[1]
        kai=minedge[0]
        used[v] = kai
        for e in edge[v]:
            if used[e[1]]==-1:
                heapq.heappush(edgelist,[e[0]+kai,e[1]])                   
    return used

################################
def main():
    n,m,s,t = map(int,input().split()) #n:頂点数　w:辺の数
    s-=1
    t-=1
    edge1 = [[] for i in range(n)]
    edge2= [[] for i in range(n)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for i in range(m):
        x,y,z,w = map(int,input().split())
        edge1[x-1].append([z,y-1])
        edge1[y-1].append([z,x-1])
        edge2[x-1].append([w,y-1])
        edge2[y-1].append([w,x-1])
    en=dijk(s,edge1)
    su=dijk(t,edge2)
    ans=[]
    aa=10**20
    for i in range(n-1,-1,-1):
        aa=min(aa,en[i]+su[i])
        ans.append(10**15-aa)
    for i in range(n-1,-1,-1):
        print(ans[i])
if __name__=='__main__':
    main()
Problem p03316 (python)

Fixed submission:
n=int(input())
s=list(str(n))
sn=0
for i in range(len(s)):
    sn+=int(s[i])
if n%sn==0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(str(n))
sn=0
for i range(len(s)):
    sn+=int(s[i])
if sn%n==0:
    print('Yes')
else:
    print('No')