Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
while n!=0:
    tmp=n%100
    x=tmp%10
    y=(tmp-x)//10

    if x<5 or (x==5 and y<5):
        ans+=x
    else:
        ans+=10-x
        n+=10-x

    n=n//10
print(ans)

Fixed submission:
def f(i):
    while True:
        a[i]=(a[i]+1)%10
        if a[i]==0: i+=1
        else: break

s=input()
a=[]
for i in range(len(s)-1,-1,-1):
    a.append(int(s[i]))
a.append(0)

ans=0
for i in range(len(a)-1):
    if a[i]<5: ans+=a[i]
    elif a[i]==5:
        if a[i+1]<5: ans+=5
        else:
            ans+=5
            f(i+1)

    else:
        ans+=10-a[i]
        f(i+1)

if a[-1]!=0: ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def f(i):
    a[i]=(a[i]+1)%10
    if a[i]==0: f(i+1)

n=int(input())
a=[]
tmp=10
while n!=0:
    a.append(n%tmp)
    n=n//tmp
a.append(0)

ans=0
for i in range(len(a)-1):
    if a[i]<5: ans+=a[i]
    elif a[i]==5:
        if a[i+1]<5: ans+=5
        else:
            ans+=5
            f(i+1)

    else:
        ans+=10-a[i]
        f(i+1)

if a[-1]!=0: ans+=1

print(ans)

Fixed submission:
def f(i):
    while True:
        a[i]=(a[i]+1)%10
        if a[i]==0: i+=1
        else: break

s=input()
a=[]
for i in range(len(s)-1,-1,-1):
    a.append(int(s[i]))
a.append(0)

ans=0
for i in range(len(a)-1):
    if a[i]<5: ans+=a[i]
    elif a[i]==5:
        if a[i+1]<5: ans+=5
        else:
            ans+=5
            f(i+1)

    else:
        ans+=10-a[i]
        f(i+1)

if a[-1]!=0: ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def f(i):
    a[i]=(a[i]+1)%10
    if a[i]==0: f(i+1)

n=int(input())
a=[]
tmp=10
while n!=0:
    a.append(n%tmp)
    n=n//tmp
a.append(0)

ans=0
for i in range(len(a)-1):
    if a[i]<5: ans+=a[i]
    elif a[i]==5:
        if a[i+1]<5: ans+=5
        else:
            ans+=5
            f(i+1)

    else:
        ans+=10-a[i]
        f(i+1)

if a[-1]!=0: ans+=1

print(ans)

Fixed submission:
def f(i):
    while True:
        a[i]=(a[i]+1)%10
        if a[i]==0: i+=1
        else: break

s=input()
a=[]
for i in range(len(s)-1,-1,-1):
    a.append(int(s[i]))
a.append(0)

ans=0
for i in range(len(a)-1):
    if a[i]<5: ans+=a[i]
    elif a[i]==5:
        if a[i+1]<5: ans+=5
        else:
            ans+=5
            f(i+1)

    else:
        ans+=10-a[i]
        f(i+1)

if a[-1]!=0: ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
ans=[10**10 for i in range(h+1)]+[0 for i in range(10**4)]
ans[0]=0
for i in range(n):
    a,b=map(int,input().split())
    tmp=0
    while tmp<=h:
        ans[tmp]=min(ans[tmp-a]+b,ans[tmp])
        tmp+=1
print(ans[h])

Fixed submission:
h,n=map(int,input().split())
ans=[10**10 for i in range(h+1)]+[0 for i in range(10**4)]
ans[0]=0
for i in range(n):
    a,b=map(int,input().split())
    tmp=0
    while tmp<=h:
        ans[tmp]=min(ans[tmp-a]+b,ans[tmp])
        tmp+=1
print(ans[h])
Buggy python submission (verdict: Time Limit Exceeded):
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)なるxを返す
def modinv(a):
    (inv, q, gcd_val) = egcd(a, MOD)
    return inv % MOD

MOD=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=1
a_m=0
a_M=0
for i in range(n-k,-1,-1):
    a_m+=a[i]*c
    a_m%=MOD
    a_M+=a[n-1-i]*c
    a_M%=MOD
    c=c*(n-i)*modinv(n-k+1-i)

ans=(a_M-a_m+MOD)%MOD
print(ans)

Fixed submission:
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)なるxを返す
def modinv(a):
    (inv, q, gcd_val) = egcd(a, MOD)
    return inv % MOD

MOD=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=1
a_m=0
a_M=0
for i in range(n-k,-1,-1):
    a_m+=a[i]*c
    a_m%=MOD
    a_M+=a[n-1-i]*c
    a_M%=MOD
    c=( c*(n-i)*modinv(n-k+1-i) )%MOD

ans=(a_M-a_m+MOD)%MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def inv(a):
    m=10**9+7
    b=m
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % m


def main():
    MOD=10**9+7
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    frac=[1]
    for i in range(1,n+1):
        frac.append(frac[-1]*i%MOD)


    dp=[[0]*(n+1) for _ in range(k)]

    for x in range(a[0]+1):
        dp[0][x]=frac[n]*frac[n-x]*inv(frac[a[0]-x]*frac[n-a[0]]*frac[x])%MOD

    for i in range(k-1):
        ai=a[i+1]
        for j in range(n+1):
            for x in range(ai+1):
                p=j+x
                if p>n: break
                tmp=dp[i][j]
                tmp*=frac[n-x]*inv((frac[ai-x]*frac[n-ai]*frac[x])%MOD)%MOD
                dp[i+1][p]=(dp[i+1][p]+tmp)%MOD
    print(dp[k-1][n]%MOD)

if __name__ == "__main__":
    main()

Fixed submission:
def inv(a):
    m=10**9+7
    b=m
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % m


def main():
    MOD=10**9+7
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    frac=[1]
    for i in range(1,n+1):
        frac.append(frac[-1]*i%MOD)
    
    fracinv=[inv(frac[i]) for i in range(n+1)]


    dp=[[0]*(n+1) for _ in range(k)]

    for x in range(a[0]+1):
        dp[0][x]=frac[n]*frac[n-x]*inv(frac[a[0]-x]*frac[n-a[0]]*frac[x])%MOD

    for i in range(k-1):
        ai=a[i+1]
        for j in range(n+1):
            for x in range(ai+1):
                p=j+x
                if p>n: break
                tmp=dp[i][j]
                tmp=(tmp*frac[n-x]*fracinv[ai-x])%MOD
                tmp=(tmp*fracinv[n-ai]*fracinv[x])%MOD
                dp[i+1][p]=(dp[i+1][p]+tmp)%MOD
    print(dp[k-1][n]%MOD)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys

def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def f(n):
    return int(n)//2

n,m=map(int,input().split())
a=list(map(f,input().split()))


tmp=1
for i in range(n):
    tmp=(tmp*a[i])//gcd(tmp,a[i])


for i in range(n):
    if (tmp//a[i])%2==0:
        print(0)
        sys.exit()

ans=m//(tmp*2)
if m%(tmp*2)>=tmp: ans+=1
print(ans)

Fixed submission:
import math
import sys

def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def f(n):
    return int(n)//2

n,m=map(int,input().split())
a=list(map(f,input().split()))


tmp=1
for i in range(n):
    tmp=(tmp*a[i])//gcd(tmp,a[i])
    if tmp>m:
        print(0)
        sys.exit()


for i in range(n):
    if (tmp//a[i])%2==0:
        print(0)
        sys.exit()

ans=m//(tmp*2)
if m%(tmp*2)>=tmp: ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
import sys

def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def f(n):
    return int(n)//2

n,m=map(int,input().split())
a=list(map(f,input().split()))


tmp=1
for i in range(n):
    tmp=(tmp*a[i])//gcd(tmp,a[i])


for i in range(n):
    if (tmp/a[i])%2==0: print(0),sys.exit()

ans=m//(tmp*2)
if m%(tmp*2)>=tmp: ans+=1
print(ans)

Fixed submission:
import math
import sys

def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

def f(n):
    return int(n)//2

n,m=map(int,input().split())
a=list(map(f,input().split()))


tmp=1
for i in range(n):
    tmp=(tmp*a[i])//gcd(tmp,a[i])
    if tmp>m:
        print(0)
        sys.exit()


for i in range(n):
    if (tmp//a[i])%2==0:
        print(0)
        sys.exit()

ans=m//(tmp*2)
if m%(tmp*2)>=tmp: ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while (p<n and a[q]+a[p]<=md):
            p+=1
    except:
        p=n

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)

Fixed submission:
def f(i):
    return i
s,t=map(f,input().split())
print(t+s)

Buggy python submission (verdict: Runtime Error):
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
    except:
        print(ans)
        sys.exit()

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)

Fixed submission:
def f(i):
    return i
s,t=map(f,input().split())
print(t+s)

Buggy python submission (verdict: Runtime Error):
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
        if p==n: break
        cnt+=n-p
        ans+=a[q]*(n-p)*2
    except:
        print(0)
        sys.exit()


ans+=(m-cnt)*md
print(ans)

Fixed submission:
def f(i):
    return i
s,t=map(f,input().split())
print(t+s)

Buggy python submission (verdict: Runtime Error):
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

try:
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<=md:
            p+=1
        if p==n: break
        cnt+=n-p
        ans+=a[i]*(n-p)*2
    


except:
    print(0)

ans+=(m-cnt)*md
print(ans)

Fixed submission:
def f(i):
    return i
s,t=map(f,input().split())
print(t+s)
Buggy python submission (verdict: Runtime Error):
def Sieve_of_Eratosthenes(N):
    if N<2:
        prime = [False for i in range(N+1)]
        return prime
 
    prime = [True for i in range(N+1)]
    prime[0] = False
    prime[1] = False
 
    for i in range(2, int(N**0.5)+1):
        if prime[i]:
            for j in range(i*2, N+1, i):
                prime[j] = False
 
    return prime

prime=Sieve_of_Eratosthenes(10**5)
x=int(input())
while prime[x]==False:
    x+=1
print(x)

Fixed submission:
import sys
def sieve(N):
    if N<2:
        prime = [False for i in range(N+1)]
        return prime
 
    prime = [True for i in range(N+1)]
    prime[0] = False
    prime[1] = False
 
    for i in range(2, int(N**0.5)+1):
        if prime[i]:
            for j in range(i*2, N+1, i):
                prime[j] = False
 
    return prime

l=sieve(100057)
x=int(input())
while True:
    if l[x]==True:
        print(x)
        sys.exit()
    x+=1
Buggy python submission (verdict: Runtime Error):
def main():
    h,w=map(int,input().split())
    L=80*(h+w)+1
    a=[list(map(int,input().split())) for i in range(h)]
    b=[list(map(int,input().split())) for i in range(h)]


    x=[[abs(a[i][j]-b[i][j]) for j in range(w)] for i in range(h)]
    

    L=12800
    
    state=[[0 for j in range(w)] for i in range(h)]
    delta=x[0][0]
    state[0][0]=(2**L>>delta)|(2**L<<delta)

    for j in range(1,w):
        delta=x[0][j-1]
        state[0][j]=(state[0][j-1]>>delta)|(state[0][j-1]<<delta)

    for i in range(1,h):
        delta=x[i-1][0]
        state[i][0]=(state[i-1][0]>>delta)|(state[i-1][0]<<delta)

    for i in range(1,h):
        for j in range(1,w):
            delta=x[i][j]
            state[i][j]=(state[i][j-1]>>delta)|(state[i][j-1]<<delta)
            state[i][j]=(state[i-1][j]>>delta)|(state[i-1][j]<<delta)

    
    ans = 10**9
    for i in range(L*2):
        if state[h-1][w-1] & 1:
            ans = min(ans,abs(i-L))
        state[h-1][w-1]>>=1
    print(ans-1)



if __name__ == '__main__':
    main()


Fixed submission:
a=list(map(int,input().split()))
if sum(a)>=22: print('bust')
else: print('win')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

def func(s):
    return int(s)-1


N=int(input())
e=[list(map(func,input().split()))+[i] for i in range(N-1)]
e.sort()

x=[0 for i in range(N)]
for i in range(N-1):
    x[e[i][0]]+=1
    x[e[i][1]]+=1
print(max(x))

e2=[[0 for j in range(x[i])]for i in range(N)]
ans=[0 for i in range(N-1)]

for i in range(N-1):
    [p,q,r]=e[i]
    for j in range(x[p]):
        if e2[p][j]==0:
            e2[p][j]=1
            if j<x[q]: e2[q][j]=1
            ans[r]=j
            break
        
for i in range(N-1):
    print(ans[i]+1)



Fixed submission:
import sys
import math

def func(s):
    return int(s)-1


N=int(input())
e=[list(map(func,input().split()))+[i] for i in range(N-1)]
e.sort()

x=[0 for i in range(N)]
for i in range(N-1):
    x[e[i][0]]+=1
    x[e[i][1]]+=1
print(max(x))

e2=[[0 for j in range(x[i])]for i in range(N)]
ans=[0 for i in range(N-1)]

y=[0 for i in range(N)]

for i in range(N-1):
    [p,q,r]=e[i]

    e2[p][y[p]]=1
    if y[p]<x[q]: e2[q][y[p]]=1
    ans[r]=y[p]

    for j in range(y[p],x[p]):
        if e2[p][j]==0:
            y[p]=j
            break
    for j in range(y[q],x[q]):
        if e2[q][j]==0:
            y[q]=j
            break

for i in range(N-1):
    print(ans[i]+1)
Buggy python submission (verdict: Runtime Error):
import sys
import math

M=int(input())
ans=0
a=[list(map(int,input().split())) for i in range(M)]
b=[0 for i in range(M)]

for i in range(M):
    ans+=a[i][1]-1
    b[i]=a[i][0]*a[i][1]
    while b[i]>=10:
        ans+=b[i]//10
        b[i]=b[i]//10+b[i]%10


ans+=M-1 + sum(b)//10
print(int(ans))

Fixed submission:
import sys
import math

X,Y=map(int,input().split())
ans=0
if X==1:   ans+=300000
elif X==2: ans+=200000
elif X==3: ans+=100000

if Y==1:   ans+=300000
elif Y==2: ans+=200000
elif Y==3: ans+=100000

if X==1 and Y==1: ans+=400000
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

MOD=10**9+7

N,T=map(int,input().split())
l=[list(map(int,input().split())) for i in range(N)] 
l.sort(reverse=True)

dp1=[[-10**10 for i in range(T)] for i in range(N)]
dp2=[[0 for i in range(T)] for i in range(N)]

[a,b]=l[0]
dp1[0][0],dp2[0][0]=0,b
if a<T: dp1[0][a]=b

for i in range(1,N):
    [a,b]=l[i]
    m=min(a,T)
    for j in range(m):
        dp1[i][j]=dp1[i-1][j]
        dp2[i][j]=max(b,dp2[i-1][j])
    for j in range(m,T):
        p,q=dp1[i-1][j],dp1[i-1][j-a]+b
        if p<q:
            dp1[i][j]=q
            dp2[i][j]=dp2[i-1][j-a]
        elif p>q:
            dp1[i][j]=p
            dp2[i][j]=max(dp2[i-1][j],b)
        else:
            dp1[i][j]=p
            dp2[i][j]=max(dp2[i-1][j-a],dp2[i-1][j],b)

print(max( dp1[N-1][j]+dp2[N-1][j] for j in range(T) ) )

Fixed submission:
ans=0
n,t=map(int,input().split())
food=[]
for i in range(n):
    f=list(map(int,input().split()))
    food.append(f)
food=sorted(food)
dp=[0,0]+[-1]*(t-1)

for a,b in food:
    tmp=[dp[i] for i in range(t)]
    for i in range(t):
        if dp[i]==-1: continue
        j=i+a
        if j<t: tmp[j]=max(tmp[j],dp[i]+b)
        else: ans=max(ans,dp[i]+b)
    
    dp=[tmp[i] for i in range(t)]
print(max(ans,max(dp)))
Buggy python submission (verdict: Runtime Error):
import sys

N=int(input())

a=list(map(int,input().split()))
b=list(map(int,input().split()))
a=[[a[i],i] for i in range(N)]
b=[[b[i],i] for i in range(N)]
aa,bb=sorted(a),sorted(b)

for i in range(N):
    if aa[i][0]>bb[i][0]: print("No"),sys.exit()

for i in range(N-1):
    if aa[i][0]==aa[i+1][0] or bb[i][0]==bb[i+1][0]: print("Yes"),sys.exit()
    if bb[i][0]>=aa[i+1][0]: print("Yes"),sys.exit()


dicb={}
for i in range(N):
    dicb[bb[i][0]]=i
tmp=0
j=0
while tmp<N-2:
    j=dicb[b[j][0]]
    if j==0: print("Yes"),sys.exit()
    tmp+=1
print("No")

Fixed submission:
N=int(input())
if N%2==0: print(N//2-1)
else: print(N//2)
Buggy python submission (verdict: Runtime Error):
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**7 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([2**(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**7 else -1)

if __name__ == '__main__':
    main()

Fixed submission:
n=int(input())
print(1-(n//2)/n)

Buggy python submission (verdict: Runtime Error):
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**10 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([1<<(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()

Fixed submission:
n=int(input())
print(1-(n//2)/n)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
a=[]
for i in range(M):
    tmp=list(map(int,input().split()))
    tmpc=list(map(int,input().split()))
    c=0
    for j in range(len(tmpc)):
        c+=2**(tmpc[j]-1)
    tmp[1]=c
    a+=[tmp]


dp=[[10**10 for j in range(2**N)] for i in range(M)]
dp[0][0]=0
dp[0][a[0][1]]=a[0][0]


for i in range(1,M):
    dp[i]=dp[i-1]
    for j in range(2**N):
        if dp[i-1][j]<10**10:
            q=j|a[i][1]
            dp[i][q]=min(dp[i-1][j]+a[i][0],dp[i][q])

ans=dp[M-1][2**N-1]
print(ans if ans<10**10 else -1)

Fixed submission:
n=int(input())
print(1-(n//2)/n)
Buggy python submission (verdict: Runtime Error):
def main():
    def func(s):
        return ord(s)-ord('a')

    n=int(input())
    s=input()
    s=[func(s[i]) for i in range(n)]
    sign=0
    ans=0
    for i in range(n-1):
        if ans>(n-i)//2: break
        for j in range(i+1,n):
            if s[j]==s[i+sign] and i+2*sign<j:
                sign+=1
    
            else:
                ans=max(sign,ans)
                sign=0
                
        ans=max(sign,ans)
        sign=0

    ans=max(sign,ans)
    print(ans)
            

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    ans=["Sunny","Cloudy","Rainy"]
    print(ans[(ans.index(input())+1)%3])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    def func(s):
        return ord(s)-ord('a')

    n=int(input())
    s=input()
    s=[func(s[i]) for i in range(n)]
    sign=0
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            if s[j]==s[i+sign] and i+2*sign<j:
                sign+=1

            else:
                if sign>ans: ans=sign
                sign=0
        
        if sign>ans: ans=sign
        sign=0

    print(ans)
        

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    ans=["Sunny","Cloudy","Rainy"]
    print(ans[(ans.index(input())+1)%3])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    def func(s):
        return ord(s)-ord('a')

    n=int(input())
    s=input()
    s=[func(s[i]) for i in range(n)]
    sign=0
    ans=0
    for i in range(n-1):

        if ans>(n-i)/2: break

        for j in range(i+1,n):
            if s[j]==s[i+sign] and i+2*sign<j:
                sign+=1

            else:
                if sign>ans: ans=sign
                sign=0
        
        if sign>ans: ans=sign
        sign=0

    print(ans)
        

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    ans=["Sunny","Cloudy","Rainy"]
    print(ans[(ans.index(input())+1)%3])
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import bisect
    import math
    import sys

    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    a.sort()
    for i in range(m):
        tmp=a[n-1]//2
        bisect.insort_left(a,tmp)
        a.pop(n)
    print(sum(a))

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import bisect
    import math
    import sys
    import heapq
    def f(s):
        return -int(s)

    n,m=map(int,input().split())
    a=list(map(f,input().split()))
    heapq.heapify(a)

    for i in range(m):
        tmp=heapq.heappop(a)
        tmp=math.ceil(tmp/2)
        heapq.heappush(a,tmp)

    print(-sum(a))
    

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import bisect
    import math
    import sys

    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    a.sort()
    for i in range(m):
        tmp=a[n-1]//2
        a.insert(bisect.bisect_left(a,tmp),tmp)
        a.pop(n)
    print(sum(a))

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import bisect
    import math
    import sys
    import heapq
    def f(s):
        return -int(s)

    n,m=map(int,input().split())
    a=list(map(f,input().split()))
    heapq.heapify(a)

    for i in range(m):
        tmp=heapq.heappop(a)
        tmp=math.ceil(tmp/2)
        heapq.heappush(a,tmp)

    print(-sum(a))
    

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
sign=0
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        if s[j]==s[i+sign] and i+2*sign<j:
            sign+=1

        else:
            ans=max(sign,ans)
            sign=0
ans=max(sign,ans)
print(ans)

Fixed submission:
def main():

    n=int(input())
    s=input()

    i,j=0,1
    ans=0
    while j<n:
        if s[i:j] in s[j:]:
            if j-i>ans: ans=j-i
            j+=1
        else:
            i+=1
            j+=1

    print(ans)

            

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
p=list(map(int,input().split()))
locate=[0]*(n+1)

for i in range(n):
    locate[p[i]]=i

a=[-1,-1,n,n]
ans=0
for i in range(n,0,-1):
    k=locate[i]
    q=bisect.bisect_left(a,k)
    a.insert(q,k)
    c=(a[q]-a[q-1])*(a[q+2]-a[q+1])+(a[q-1]-a[q-2])*(a[q+1]-a[q])
    ans+=c*i
print(ans)

Fixed submission:
import bisect
n=int(input())
p=list(map(int,input().split()))
idx=[0]*(n+1)

for i,p_i in enumerate(p):
    idx[p_i]=i

right_idx=list(range(1,n+1))+[n,n]
left_idx =list(range(-1,n-1))+[-1,-1]
ans=0
for p in range(1,n+1):
    x=idx[p]
    r1=right_idx[x]
    r2=right_idx[r1]
    l1=left_idx[x]
    l2=left_idx[l1]

    ans+=p*( (x-l1)*(r2-r1) + (l1-l2)*(r1-x)  )
    right_idx[l1]=r1
    left_idx[r1]=l1
print(ans)