Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=(int(s[i])*(seki))%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)

Fixed submission:
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=int(s[i])*seki
    num=num%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
sisu=0
for i in range(l):
    num+=int(s[i])*(10**(sisu))
    num=num%mod
    count[num]+=1
    sisu+=1
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)

Fixed submission:
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=int(s[i])*seki
    num=num%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
s=list(input())
l=len(s)
ans=0
for i in range(l-3):
    sum_keta=int(s[i])
    num=s[i]
    index=i+1
    while sum_keta<=100:
        num+=s[i+j]
        if int(num)%2019==0:
            ans+=1
        index+=1
        sum_keta+=int(s[i+j])
        if l-1<index:
            break
print(ans)

Fixed submission:
s=list(input())
s=s[::-1]
l=len(s)
mod=2019
count=[0]*2019
count[0]=1
num=0
seki=1
for i in range(l):
    num+=int(s[i])*seki
    num=num%mod
    count[num]+=1
    seki=(seki*10)%mod
ans=0
for i in range(2019):
    N=count[i]
    ans+=N*(N-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
total=0
info=[0]
for i in range(1,201):
    for j in range(1,201):
        if j<i:
            info.append(0)
            continue
        info.append(math.gcd(i,j))
        #print(str(i)+" "+str(j)+" "+str(math.gcd(i,j)))
#print(info[202])
#print(info)
for i in range(1,k+1):
    a=[]
    a.append(i)
    for j in range(1,k+1):
        a.append(j)
        for m in range(1,k+1):
            a.append(m)
            a=sorted(a)
            gcd=info[(a[0]-1)*200+a[1]]
            b=min(gcd,a[2])
            c=max(gcd,a[2])
            gcd=info[(b-1)*200+c]
            total+=gcd
            #print(gcd)
            #print(a)
            a=[i,j]
        a=[i]
print(total)

Fixed submission:
import math
k=int(input())
total=0
info=[0]
for i in range(1,201):
    for j in range(1,201):
        if j<i:
            info.append(0)
            continue
        info.append(math.gcd(i,j))
        #print(str(i)+" "+str(j)+" "+str(math.gcd(i,j)))
#print(info[202])
#print(info)
for i in range(1,k+1):
    a=[]
    a.append(i)
    for j in range(1,k+1):
        a.append(j)
        for m in range(1,k+1):
            a.append(m)
            a=sorted(a)
            gcd=info[(a[0]-1)*200+a[1]]
            b=min(gcd,a[2])
            c=max(gcd,a[2])
            gcd=info[(b-1)*200+c]
            total+=gcd
            #print(gcd)
            #print(a)
            a=[i,j]
        a=[i]
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
import math
k=int(input())
total=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for m in range(1,k+1):
            g=math.gcd(i,j)
            g=math.gcd(g,m)
            total+=g
print(total)

Fixed submission:
import math
k=int(input())
total=0
info=[0]
for i in range(1,201):
    for j in range(1,201):
        if j<i:
            info.append(0)
            continue
        info.append(math.gcd(i,j))
        #print(str(i)+" "+str(j)+" "+str(math.gcd(i,j)))
#print(info[202])
#print(info)
for i in range(1,k+1):
    a=[]
    a.append(i)
    for j in range(1,k+1):
        a.append(j)
        for m in range(1,k+1):
            a.append(m)
            a=sorted(a)
            gcd=info[(a[0]-1)*200+a[1]]
            b=min(gcd,a[2])
            c=max(gcd,a[2])
            gcd=info[(b-1)*200+c]
            total+=gcd
            #print(gcd)
            #print(a)
            a=[i,j]
        a=[i]
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
count=[[0 for i in range(10)] for j in range(9)]
ans=0
for i in range(1,n+1):
    num=list(str(i))
    l,r=eval(num[0]),eval(num[-1])
    #print(str(l)+"  "+str(r))
    #print(l+r)
    count[l-1][r]+=1
#print(count)
for i in range(1,10):
    for j in range(1,10):
        if i==j:
            continue
        ans+=(count[i-1][j])*(count[j-1][i])
for i in range(1,10):
    ans+=(count[i-1][i]**2)
print(ans)

Fixed submission:
n=int(input())
count=[[0 for i in range(10)] for j in range(9)]
ans=0
num=1
zero=0
for i in range(1,n+1):
    if (10**(zero+1))<=num:
        zero+=1
    a=i//10
    r=i-a*10
    l=i//(10**zero)
    count[l-1][r]+=1
    num+=1
#print(count)
for i in range(1,10):
    for j in range(1,10):
        if i==j:
            continue
        ans+=(count[i-1][j])*(count[j-1][i])
for i in range(1,10):
    ans+=(count[i-1][i]**2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
count=[[0 for i in range(10)] for j in range(9)]
ans=0
for i in range(1,n+1):
    num=list(str(i))
    l,r=eval(num[0]),eval(num[-1])
    #print(str(l)+"  "+str(r))
    #print(l+r)
    count[l-1][r]+=1
#print(count)
for i in range(1,10):
    for j in range(1,10):
        if i==j:
            continue
        ans+=(count[i-1][j])*(count[j-1][i])
for i in range(1,10):
    ans+=(count[i-1][i]**2)
print(ans)

Fixed submission:
n=int(input())
count=[[0 for i in range(10)] for j in range(9)]
ans=0
num=1
zero=0
for i in range(1,n+1):
    if (10**(zero+1))<=num:
        zero+=1
    a=i//10
    r=i-a*10
    l=i//(10**zero)
    count[l-1][r]+=1
    num+=1
#print(count)
for i in range(1,10):
    for j in range(1,10):
        if i==j:
            continue
        ans+=(count[i-1][j])*(count[j-1][i])
for i in range(1,10):
    ans+=(count[i-1][i]**2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#import time

#t1=time.time()
n=int(input())
s=list(input())
info=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            info.append(str(i)+str(j)+str(k))
ans=0
kind=0
while kind<=999:
    point=0
    check=info[kind]
    for i in range(n):
        if point==0:  
            if check[0]==s[i]:
                point+=1
                continue
        if point==1:
            if check[1]==s[i]:
                point+=1
                continue
        if point==2:
            if check[2]==s[i]:
                point+=1
                break
    if point==3:
        ans+=1
        #print(info[kind])
    kind+=1
print(ans)
#t2=time.time()
#print(t2-t1)

Fixed submission:
#import time

#t1=time.time()
n=int(input())
s=list(input())
info=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            info.append(str(i)+str(j)+str(k))
ans=0
kind=0
while kind<=999:
    point=0
    check=info[kind]
    for i in range(n):
        if point==0:  
            if check[0]==s[i]:
                point+=1
                continue
        if point==1:
            if check[1]==s[i]:
                point+=1
                continue
        if point==2:
            if check[2]==s[i]:
                point+=1
                break
    if point==3:
        ans+=1
        #print(info[kind])
    kind+=1
print(ans)
#t2=time.time()
#print(t2-t1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())
info=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            info.append(str(i)+str(j)+str(k))
ans=0
kind=0
while kind<=999:
    point=0
    for i in range(n):
        if point==0:  
            if info[kind][0]==s[i]:
                point+=1
                continue
        if point==1:
            if info[kind][1]==s[i]:
                point+=1
                continue
        if point==2:
            if info[kind][2]==s[i]:
                point+=1
                break
    if point==3:
        ans+=1
        #print(info[kind])
    kind+=1
print(ans)

Fixed submission:
#import time

#t1=time.time()
n=int(input())
s=list(input())
info=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            info.append(str(i)+str(j)+str(k))
ans=0
kind=0
while kind<=999:
    point=0
    check=info[kind]
    for i in range(n):
        if point==0:  
            if check[0]==s[i]:
                point+=1
                continue
        if point==1:
            if check[1]==s[i]:
                point+=1
                continue
        if point==2:
            if check[2]==s[i]:
                point+=1
                break
    if point==3:
        ans+=1
        #print(info[kind])
    kind+=1
print(ans)
#t2=time.time()
#print(t2-t1)
Buggy python submission (verdict: Runtime Error):
import math

n=int(input())
info=[]
for i in range(n):
    x,y=map(int,input().split())
    info.append([x,y])
total=0
for i in range(n-1):
    for j in range(i+1,n):
        total+=math.sqrt((info[i][0]**2-info[j][0]**2)+(info[i][1]**2-info[j][1]**2))
print(total*2/n)

Fixed submission:
import math

n=int(input())
info=[]
for i in range(n):
    x,y=map(int,input().split())
    info.append([x,y])
total=0
for i in range(n-1):
    for j in range(i+1,n):
        total+=math.sqrt((info[i][0]-info[j][0])**2+(info[i][1]-info[j][1])**2)
print(total*2/n)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n=int(input())
info=[[0]]
for i in range(n):
    x,y=map(int,input().split())
    info.append([x,y])
max_num=""
for i in range(n,0,-1):
    max_num+=str(i)

def sitigosan(num):
    total=0
    if int(num)>int(max_num):
        return 0
    check=0
    #print(num)
    for i in range(1,n+1):
        if str(i) not in num:
            check=1
            break
    if check==0:
        total+=kyori(num)
    for i in max_num:
        total+=sitigosan(num+i)
    return total

def kyori(num):
    d=0
    a=list(num)
    for i in range(1,len(a)-1):
        d+=math.sqrt((info[int(a[i])][0]-info[int(a[i+1])][0])**2+(info[int(a[i])][1]-info[int(a[i+1])][1])**2)
    return d

ans=sitigosan("0")/(math.factorial(n))
print(ans)

Fixed submission:
import math

n=int(input())
info=[]
for i in range(n):
    x,y=map(int,input().split())
    info.append([x,y])
total=0
for i in range(n-1):
    for j in range(i+1,n):
        total+=math.sqrt((info[i][0]-info[j][0])**2+(info[i][1]-info[j][1])**2)
print(total*2/n)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
l2=sorted(l)
box=[0] #各長さの棒が何本あるか　最初の０は数合わせ
ans=0

num=1
while num<l2[0]: #最小の棒までは０をappend
    box.append(0)
    num+=1
    
now=l2[0]
bounum=1
for i in range(1,n):
    if l2[i]!=now:
        box.append(bounum)
        while now+1<l2[i]:
            box.append(0)
        now=l2[i]
        bounum+=1
    else:
        bounum+=1
if len(box)!=l2[-1]+1:
    box.append(bounum) #boxの完成

for i in range(n-2):
    for j in range(i+1,n-1):
        c=l2[i]+l2[j]-1
        if c>l2[-1]:
            c=l2[-1]
        add=box[c]-(j+1)
        if add<0:
            add=0
        ans+=add

print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l2=sorted(l)
box=[0] #各長さの棒が何本あるか　最初の０は数合わせ
ans=0

num=1
while num<l2[0]: #最小の棒までは０をappend
    box.append(0)
    num+=1
    
now=l2[0]
bounum=1
for i in range(1,n):
    if l2[i]!=now:
        box.append(bounum)
        next=now+1
        while next<l2[i]:
            box.append(bounum)
            next+=1 
        now=l2[i]
        bounum+=1
    else:
        bounum+=1
if len(box)!=l2[-1]+1:
    box.append(bounum) #boxの完成

for i in range(n-2):
    for j in range(i+1,n-1):
        c=l2[i]+l2[j]-1
        if c>l2[-1]:
            c=l2[-1]
        add=box[c]-(j+1)
        if add<0:
            add=0
        ans+=add

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
                ans+=1
print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l2=sorted(l)
box=[0] #各長さの棒が何本あるか　最初の０は数合わせ
ans=0

num=1
while num<l2[0]: #最小の棒までは０をappend
    box.append(0)
    num+=1
    
now=l2[0]
bounum=1
for i in range(1,n):
    if l2[i]!=now:
        box.append(bounum)
        next=now+1
        while next<l2[i]:
            box.append(bounum)
            next+=1 
        now=l2[i]
        bounum+=1
    else:
        bounum+=1
if len(box)!=l2[-1]+1:
    box.append(bounum) #boxの完成

for i in range(n-2):
    for j in range(i+1,n-1):
        c=l2[i]+l2[j]-1
        if c>l2[-1]:
            c=l2[-1]
        add=box[c]-(j+1)
        if add<0:
            add=0
        ans+=add

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy

n=int(input())
info=[]
for i in range(n):
    info.append(int(input()))
   
for i in range(n):
    info2=copy.deepcopy(info)
    del info2[i]
    print(max(info2))

Fixed submission:
n=int(input())
info=[]
for i in range(n):
    info.append(int(input()))

info2=sorted(info,reverse=True)
max1=info2[0]
max2=info2[1]

for i in range(n):
    if info[i]==max1:
        print(max2)
    else:
        print(max1)
Buggy python submission (verdict: Time Limit Exceeded):
L,R=map(int,input().split())
min=20000
for i in range(L,R): #L～R-1
    for j in range(i+1,R+1): #i+1～R
        a=(i*j)%2019
        if a<min:
            min=a
print(min)

Fixed submission:
L,R=map(int,input().split())
min=20000
newR=L+2019
if newR<R: #Rを小さくする
    R=newR
for i in range(L,R): #L～R-1
    for j in range(i+1,R+1): #i+1～R
        a=(i*j)%2019
        if a<min:
            min=a
print(min)
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
cd=int(c*d/(math.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))


Fixed submission:
import fractions
a,b,c,d=map(int,input().split())
cd=int(c*d/(fractions.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))

Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
cd=int(c*d/(math.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))

Fixed submission:
import fractions
a,b,c,d=map(int,input().split())
cd=int(c*d/(fractions.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d=map(int,input().split())
count=0
for i in range(a,b+1):
    if i%c!=0 and i%d !=0:
            count+=1
print(count)

Fixed submission:
import fractions
a,b,c,d=map(int,input().split())
cd=int(c*d/(fractions.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d=map(int,input().split())
count=0
for i in range(a,b+1):
    if i%c !=0:
        if i%d !=0:
            count+=1
print(count)

Fixed submission:
import fractions
a,b,c,d=map(int,input().split())
cd=int(c*d/(fractions.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))
Buggy python submission (verdict: Runtime Error):
30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720

Fixed submission:
n=int(input())
info=[]
time=0
ok=0
for i in range(n):
    a,b=map(int,input().split())
    info.append([a,b])
info2=sorted(info,key=lambda x:x[1])
for i in range(n):
    time+=info2[i][0]
    if time>info2[i][1]:
        ok=1
        break
print("Yes" if ok==0 else "No")
Buggy python submission (verdict: Time Limit Exceeded):
#ABC129-C
N,M=map(int,input().split())
a=[]
num=0 #N段までの行き方
check=0 #行けるかどうか
for i in range(M):
    a.append(int(input()))

for i in range(M-1):
    dif=a[i+1]-a[i]
    if dif==1:
        check=1
        break
        
f={}
f[0]=0 #番号を段数と一致させるため
if (1 in a)==True: #１が壊れているとき
    f[1]=0
else:
    f[1]=1
if (2 in a)==True: #２が壊れているとき
    f[2]=0
elif f[1]==0: #１が壊れているとき
    f[2]=1
else:
    f[2]=2

if check==0:
    for i in range(1,N-1): #1~N-2
        if any(i+2==a[k] for k in range(M)): #壊れている階段は、２段前に見つけておく。
            f[i+2]=0
            continue
        f[i+2]=f[i+1]+f[i]
    num=f[N]

#for i in range(101):
    #print(str(i)+":"+str(f[i]))
print(num%1000000007)

Fixed submission:
#ABC129-C
N,M=map(int,input().split())
a=[]
broke={} #N段目が壊れているか
broke[0]=0
for i in range(1,N+1):
    broke[i]=0

f={}
f[0]=0 #番号を段数と一致させるため
num=0 #N段までの行き方
check=0 #行けるかどうか

for i in range(M):
    a.append(int(input()))
    n=a[i]
    broke[n]=1 #ｎ段目が壊れていることを記憶
    f[n]=0

for i in range(M-1): #壊れている階段同士の差が１の場所があるか調べる。
    dif=a[i+1]-a[i]
    if dif==1:
        check=1
        break
        
if (1 in a)==True: #１が壊れているとき
    f[1]=0
else:
    f[1]=1
if (2 in a)==True: #２が壊れているとき
    f[2]=0
elif f[1]==0: #１が壊れているとき
    f[2]=1
else:
    f[2]=2

if check==0:
    for i in range(1,N-1): #1~N-2
        if broke[i+2]==1:
            continue
        f[i+2]=f[i+1]+f[i]
    num=f[N]

#for i in range(N+1):
    #print(str(i)+":"+str(f[i]))
print(num%1000000007)
#print(broke)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
info=[]
for i in range(m):
    b,c=map(int,input().split())
    info.append([c,b])
a=sorted(a) #小さい順に
info=sorted(info,reverse=True)
b=[] #n枚まで、大きい順に変えられるやつを記録
total=0
def add(num,s):
    global b
    for i in range(s):
        b.append(num)
        
for i in range(m):
    total+=info[i][1]
    if n<=total:
        total-=info[i][1]
        add(info[i][0],n-total)
    add(info[i][0],info[i][1])
l=len(b)
ans=0
for i in range(n):
    if i<=l-1:
        ans+=max(a[i],b[i])
    else:
        ans+=a[i]
print(ans)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
info=[]
for i in range(m):
    b,c=map(int,input().split())
    info.append([c,b])
a=sorted(a) #小さい順に
info=sorted(info,reverse=True)
b=[] #n枚まで、大きい順に変えられるやつを記録
total=0
def add(num,s):
    global b
    for i in range(s):
        b.append(num)
        
for i in range(m):
    total+=info[i][1]
    if n<=total:
        total-=info[i][1]
        add(info[i][0],n-total)
        break
    add(info[i][0],info[i][1])
l=len(b)
ans=0
for i in range(n):
    if i<=l-1:
        ans+=max(a[i],b[i])
    else:
        ans+=a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
info=[]
for i in range(m):
    b,c=map(int,input().split())
    info.append([c,b])
a=sorted(a) #小さい順に
info=sorted(info,reverse=True)
b=[] #n枚まで、大きい順に変えられるやつを記録
total=0
def add(num,s):
    global b
    for i in range(s):
        b.append(num)
        
for i in range(m):
    total+=info[i][1]
    if n<=total:
        total-=info[i][1]
        add(info[i][0],n-total)
    add(info[i][0],info[i][1])
l=len(b)
ans=0
for i in range(n):
    if i<=l-1:
        ans+=max(a[i],b[i])
    else:
        ans+=a[i]
print(ans)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
info=[]
for i in range(m):
    b,c=map(int,input().split())
    info.append([c,b])
a=sorted(a) #小さい順に
info=sorted(info,reverse=True)
b=[] #n枚まで、大きい順に変えられるやつを記録
total=0
def add(num,s):
    global b
    for i in range(s):
        b.append(num)
        
for i in range(m):
    total+=info[i][1]
    if n<=total:
        total-=info[i][1]
        add(info[i][0],n-total)
        break
    add(info[i][0],info[i][1])
l=len(b)
ans=0
for i in range(n):
    if i<=l-1:
        ans+=max(a[i],b[i])
    else:
        ans+=a[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

ans=1
n=int(input())
a=list(map(int,input().split()))
l=[0]
r=[0]
for i in range(n-1):
    l.append(fractions.gcd(l[i],a[i]))
    r.append(fractions.gcd(r[i],a[-(i+1)]))
for i in range(n):
    c=fractions.gcd(l[i],r[-(i+1)])
    if ans<c:
        ans=c
print(ans)

Fixed submission:
import fractions

ans=1
n=int(input())
a=list(map(int,input().split()))
l=[0]
r=[0]
for i in range(n-1):
    l.append(fractions.gcd(l[i],a[i]))
    r.append(fractions.gcd(r[i],a[-(i+1)]))
for i in range(n):
    c=fractions.gcd(l[i],r[-(i+1)])
    if ans<c:
        ans=c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def calc(num1,num2,t):
    if num1!=0:
        if num1>=t:
            num1-=t
            num2+=t
        else:
            num2+=num1
            num1=0
    return num1,num2
    

n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
num=[n,0,0,0,0,0]
time=0
while num[5]<n:
    num[4],num[5]=calc(num[4],num[5],e)
    num[3],num[4]=calc(num[3],num[4],d)
    num[2],num[3]=calc(num[2],num[3],c)
    num[1],num[2]=calc(num[1],num[2],b)
    num[0],num[1]=calc(num[0],num[1],a)
    time+=1
print(time)

Fixed submission:
import math

n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

num=math.ceil(n/(min(a,b,c,d,e)))
print(num+4)
Buggy python submission (verdict: Time Limit Exceeded):
def block():
    block=0
    count=0
    while count<=(n-1):
        if h[count]>=1:
            block+=1
            count+=1
            while count<=(n-1):
                if h[count]>=1:
                    count+=1
                else:
                    count+=1
                    break
    return block
                
n=int(input())
h=list(map(int,input().split()))
ans=0
while sum(h)>0:
    bl=block()
    mini=min(h)
    ans+=mini*bl
    for i in range(n):
        h[i]-=mini
    
print(ans)

Fixed submission:
N = int(input())
h = list(map(int,input().split()))
cnt = 0
 
while sum(h) > 0:
    min_h = max(h)
    i = h.index(min_h)
    #print(i)
    while i < len(h):
        if h[i] == min_h:
            h[i] -= 1
            i += 1
        else:
            break
    cnt += 1
 
print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
v=list(map(int,input().split()))
odd=[[0,0] for i in range(10**5+1)]
even=[[0,0] for i in range(10**5+1)]
for i in range(1,10**5+1):
    odd[i][1]=i
    even[i][1]=i
for i in range(n):
    if (i+1)%2==1:
        odd[v[i]][0]+=1
    else:
        even[v[i]][0]+=1
odd=sorted(odd,reverse=True)
even=sorted(even,reverse=True)
ans=0
if(odd[0][0]+even[0][0]==n): #odd[0][0]=n//2
    if(odd[0][1]==even[0][1]):
        ans=n//2
    else:
        ans=0

else:
    # odd 19,1 even 20,19のときに、(1+20)=21よりも(19+19)=38のほうがいいい。
    if(odd[0][1]==even[0][1]):
        if(odd[0][0]+even[1][0]<=odd[1][0]+even[0][0]):
            ans=(n//2-odd[1][0])+(n//2-even[0][0])
        else:
            ans=(n//2-odd[0][0])+(n//2-even[1][0])

    else:
        ans=(n//2-odd[0][0])+(n//2-even[0][0])
print(ans)


Fixed submission:
n=int(input())
n2=list(str(n))
for i in range(3):
    if n2[i]=="1":
        n2[i]="9"
    else:
        n2[i]="1"
new_n="".join(n2)
print(new_n)