Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

N=int(input())
A=list(map(int,input().split()))
INF=10**18

dp=[[-INF for i in range(N+1)] for i in range(N+1)]
dp[0][0]=0
dp[1][0]=0
dp[2][0]=0
dp[1][1]=A[0]
dp[2][1]=A[1]

for i in range(3,N+1):
    for j in range((i//2),((i+1)//2)+1):
        dp[i][j]=max(dp[i-2][j-1]+A[i-1],dp[i-3][j-1]+A[i-1],dp[i-2][j],dp[i-3][j])


print(max(dp[N][N//2],dp[N-1][N//2],dp[N-2][N//2]))



Fixed submission:
# coding: utf-8

N=int(input())
A=list(map(int,input().split()))
INF=10**18

dp=[[-INF for i in range(2)] for j in range(N+1)]
dp[0][0]=0
dp[1][0]=0
dp[2][0]=0
dp[1][1]=A[0]
dp[2][1]=A[1]

for i in range(3,N+1):
    dp[i][0]=max(dp[i-2][0]+A[i-1],dp[i-2][1])
    if i%2==0:
        dp[i][0]=max(dp[i][0],dp[i-3][0]+A[i-1])
    else:
        dp[i][0]=max(dp[i][0],dp[i-3][1]+A[i-1])
    
    dp[i][1]=dp[i-2][1]+A[i-1]
    if i%2==0:
        dp[i][1]=max(dp[i][1],dp[i-3][1]+A[i-1])

if N%2==0:
    print(max(dp[N][1],dp[N-1][1]))
else:
    print(max(dp[N][0],dp[N-1][1],dp[N-2][1]))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

N=int(input())
A=list(map(int,input().split()))
INF=10**18

dp=[[-INF for i in range(N+1)] for i in range(N+1)]
dp[0][0]=0
dp[1][0]=0
dp[2][0]=0
dp[1][1]=A[0]
dp[2][1]=A[1]

for i in range(3,N+1):
    for j in range((i//2),((i+1)//2)+1):
        dp[i][j]=max(dp[i-2][j-1]+A[i-1],dp[i-3][j-1]+A[i-1],dp[i-2][j],dp[i-3][j])


print(max(dp[N][N//2],dp[N-1][N//2],dp[N-2][N//2]))



Fixed submission:
# coding: utf-8

N=int(input())
A=list(map(int,input().split()))
INF=10**18

dp=[[-INF for i in range(2)] for j in range(N+1)]
dp[0][0]=0
dp[1][0]=0
dp[2][0]=0
dp[1][1]=A[0]
dp[2][1]=A[1]

for i in range(3,N+1):
    dp[i][0]=max(dp[i-2][0]+A[i-1],dp[i-2][1])
    if i%2==0:
        dp[i][0]=max(dp[i][0],dp[i-3][0]+A[i-1])
    else:
        dp[i][0]=max(dp[i][0],dp[i-3][1]+A[i-1])
    
    dp[i][1]=dp[i-2][1]+A[i-1]
    if i%2==0:
        dp[i][1]=max(dp[i][1],dp[i-3][1]+A[i-1])

if N%2==0:
    print(max(dp[N][1],dp[N-1][1]))
else:
    print(max(dp[N][0],dp[N-1][1],dp[N-2][1]))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
K=int(input())

num=0
i=0

while num!=K:
    i+=1
    list_i=list(map(int,str(i)))
    flg=True
    for j in range(len(list_i)):
        if j>0:
            if abs(list_i[j-1]-list_i[j])>1:
                flg=False
    
    if flg:
        num+=1

print(i)

Fixed submission:
# coding: utf-8
K=int(input())

lun=[[] for i in range(10)]

for i in range(10):
    for j in range(10):
        if abs(i-j)<=1:
            lun[i].append(j)

lunlun=[[1,2,3,4,5,6,7,8,9]]

for i in range(9):
    lunlun.append([])

for i in range(9):
    for j in range(len(lunlun[i])):
        for k in range(len(lun[lunlun[i][j]%10])):
            lunlun[i+1].append(lunlun[i][j]*10+lun[lunlun[i][j]%10][k])
LUNLUN=[]

for i in range(10):
    LUNLUN.extend(lunlun[i])
LUNLUN.sort

print(LUNLUN[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
S=list(input())
Q=int(input())
re=1
for i in range(Q):
    q=input()
    if q=="1":
        re*=-1
    else:
        two,F,C=q.split()
        if re==1:
            if F=="1":
                S.insert(0,C)
            else:
                S.append(C)
        else:
            if F=="2":
                S.insert(0,C)
            else:
                S.append(C)

if re==-1:
    S.reverse()

ans="".join(S)
print(ans)



Fixed submission:
# coding: utf-8
from collections import deque
S=list(input())
Q=int(input())
Sque=deque(S)
re=1
for i in range(Q):
    q=input()
    if q=="1":
        re*=-1
    else:
        two,F,C=q.split()
        if re==1:
            if F=="1":
                Sque.appendleft(C)
            else:
                Sque.append(C)
        else:
            if F=="2":
                Sque.appendleft(C)
            else:
                Sque.append(C)
S=list(Sque)
if re==-1:
    S.reverse()

ans="".join(S)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
H,N=map(int,input().split())
AB=[[0,0]]
for i in range(N):
    AB.append(list(map(int,input().split())))
 
INF=10**9

dp=[INF for i in range(H+1)]
dp[0]=0

for i in range(1,N+1):
    for j in range(1,H+1):
        dp[j]=min(dp[j],dp[max(0,j-AB[i][0])] + AB[i][1])

print(dp[H])

Fixed submission:
# coding: utf-8
H,N=map(int,input().split())
AB=[[0,0]]
for i in range(N):
    AB.append(list(map(int,input().split())))

INF=10**9

dp=[[INF for i in range(H+1)] for j in range(N+1)]

for i in range(N+1):
    dp[i][0]=0


for i in range(1,N+1):
    for j in range(1,H+1):
        dp[i][j]=min(dp[i-1][j],dp[i-1][max(j-AB[i][0],0)] + AB[i][1],dp[i][max(j-AB[i][0],0)] + AB[i][1])
        #print(dp[i-1][j],dp[i-1][max(j-AB[i][0],0)] + AB[i][1],dp[i][max(j-AB[i][0],0)] + AB[i][1])
        


print(dp[N][H])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
H,N=map(int,input().split())
AB=[[0,0]]
for i in range(N):
    AB.append(list(map(int,input().split())))

INF=10**9

dp=[[INF for i in range(H+1)] for j in range(N+1)]

for i in range(N+1):
    dp[i][0]=0


for i in range(1,N+1):
    for j in range(1,H+1):
        dp[i][j]=min(dp[i-1][j],dp[i-1][max(j-AB[i][0],0)] + AB[i][1],dp[i][max(j-AB[i][0],0)] + AB[i][1])
        #print(dp[i-1][j],dp[i-1][max(j-AB[i][0],0)] + AB[i][1],dp[i][max(j-AB[i][0],0)] + AB[i][1])
        


print(dp[N][H])

Fixed submission:
# coding: utf-8
H,N=map(int,input().split())
AB=[[0,0]]
for i in range(N):
    AB.append(list(map(int,input().split())))

INF=10**9

dp=[[INF for i in range(H+1)] for j in range(N+1)]

for i in range(N+1):
    dp[i][0]=0


for i in range(1,N+1):
    for j in range(1,H+1):
        dp[i][j]=min(dp[i-1][j],dp[i-1][max(j-AB[i][0],0)] + AB[i][1],dp[i][max(j-AB[i][0],0)] + AB[i][1])
        #print(dp[i-1][j],dp[i-1][max(j-AB[i][0],0)] + AB[i][1],dp[i][max(j-AB[i][0],0)] + AB[i][1])
        


print(dp[N][H])
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N,D,A=map(int,input().split())
XH=[]
for i in range(N):
    XH.append(list(map(int,input().split())))

XH.sort()

bombs=[]
damage=0
ans=0

for i in range(N):
    if bombs:
        while bombs[0][1]<XH[i][0]:
            b=bombs.pop(0)
            damage-=b[0]
            if not(bombs):
                break
    
    hp=XH[i][1]-damage
    num_b=-(-hp//A)
    num_b=max(num_b,0)
    bom_d=A*num_b
    bom_l=XH[i][0]+2*D
    if num_b>0:
        bombs.append([bom_d,bom_l])
        damage+=bom_d
    ans+=num_b

print(ans)




Fixed submission:
# coding: utf-8
N,D,A=map(int,input().split())
XH=[]
for i in range(N):
    XH.append(list(map(int,input().split())))

XH.sort()

bombs=[]
damage=0
ans=0

for i in range(N):
    if bombs:
        while bombs[0][1]<XH[i][0]:
            b=bombs.pop(0)
            damage-=b[0]
            if not(bombs):
                break
    
    hp=XH[i][1]-damage
    num_b=-(-hp//A)
    num_b=max(num_b,0)
    bom_d=A*num_b
    bom_l=XH[i][0]+2*D
    if num_b>0:
        bombs.append([bom_d,bom_l])
        damage+=bom_d
    ans+=num_b

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N,D,A=map(int,input().split())
XH=[]
for i in range(N):
    XH.append(list(map(int,input().split())))

XH.sort()

bombs=[]
damage=0
ans=0

for i in range(N):
    if bombs:
        while bombs[0][1]<XH[i][0]:
            b=bombs.pop(0)
            damage-=b[0]
            if not(bombs):
                break
    
    hp=XH[i][1]-damage
    num_b=-(-hp//A)
    num_b=max(num_b,0)
    bom_d=A*num_b
    bom_l=XH[i][0]+2*D
    if num_b>0:
        bombs.append([bom_d,bom_l])
        damage+=bom_d
    ans+=num_b

print(ans)




Fixed submission:
# coding: utf-8
N,D,A=map(int,input().split())
XH=[]
for i in range(N):
    XH.append(list(map(int,input().split())))

XH.sort()

bombs=[]
damage=0
ans=0

for i in range(N):
    if bombs:
        while bombs[0][1]<XH[i][0]:
            b=bombs.pop(0)
            damage-=b[0]
            if not(bombs):
                break
    
    hp=XH[i][1]-damage
    num_b=-(-hp//A)
    num_b=max(num_b,0)
    bom_d=A*num_b
    bom_l=XH[i][0]+2*D
    if num_b>0:
        bombs.append([bom_d,bom_l])
        damage+=bom_d
    ans+=num_b

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
    
N,K=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7
A.sort()
ans=0

for i in range(N-K+1):
    ans+=A[-(i+1)]*cmb(N-(1+i),K-1)
    ans=ans%MOD
    ans-=A[i]*cmb(N-(1+i),K-1)
    ans=ans%MOD

print(ans)

Fixed submission:

N,K=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7
A.sort()

fac=[None for i in range(N)]
finv=[None for i in range(N)]
inv=[None for i in range(N)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)
        
ans=0
COMinit(N)

for i in range(N-K+1):
    ans+=A[-(i+1)]*COM(N-(1+i),K-1)
    ans=ans%MOD
    ans-=A[i]*COM(N-(1+i),K-1)
    ans=ans%MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import math

A,B=map(int,input().split())

print(A*B//math.gcd(A,B))

Fixed submission:
# coding: utf-8
# Your code here!
import fractions

A,B=map(int,input().split())

print(A*B//fractions.gcd(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N=int(input())
S=list(map(int,input()))

ans=0

for i in range(1000):
    Num=list(map(int,str(i).zfill(3)))
    flg=[False for i in range(3)]
    
    for j in range(N):
        if S[j]==Num[0] and not flg[0]:
            flg[0]=True
            continue
        if flg[0] and S[j]==Num[1] and not flg[1]:
            flg[1]=True
            continue
        if flg[1] and S[j]==Num[2]:
            flg[2]=True
            break
    if flg[2]:
        ans+=1

print(ans)

Fixed submission:
n=int(input())
s=list(input())
ans=0

for i in range(1000):
    num=list(str(i).zfill(3))
    k=0
    for j in range(n):
        if num[k]==s[j]:
            k+=1
            if k==3:
                break
    if k==3:
        ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())
ans=0

for i in range(1000):
    num=list(str(i).zfill(3))
    k=0
    for j in range(n):
        if num[k]==s[j]:
            k+=1
            if k==3:
                break
    if k==3:
        ans+=1

print(ans)
    
    

Fixed submission:
n=int(input())
s=list(input())
ans=0

for i in range(1000):
    num=list(str(i).zfill(3))
    k=0
    for j in range(n):
        if num[k]==s[j]:
            k+=1
            if k==3:
                break
    if k==3:
        ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,t=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab_r=list(reversed(ab))

dp1=[[0 for j in range(t)] for i in range(n+1)]
dp2=[[0 for j in range(t)] for i in range(n+1)]

for i in range(n):
    for j in range(t-1):
        if ab[i][0] <= j:
            dp1[i+1][j] = max(dp1[i][j],dp1[i][j-ab[i][0]]+ab[i][1])
        else:
            dp1[i+1][j] = dp1[i][j]
            
for i in range(n):
    for j in range(t-1):
        if ab_r[i][0] <= j:
            dp2[i+1][j] = max(dp2[i][j],dp2[i][j-ab_r[i][0]]+ab_r[i][1])
        else:
            dp2[i+1][j] = dp2[i][j]
            
m=0
for i in range(1,n+1):
    for j in range(t-1):
        m=max(m,dp1[i-1][j]+dp2[n-i][t-1-j]+ab[i-1][1])
print(m)


Fixed submission:
n,t=map(int,input().split())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab_r=list(reversed(ab))

dp1=[[0 for j in range(t)] for i in range(n+1)]
dp2=[[0 for j in range(t)] for i in range(n+1)]

for i in range(n):
    for j in range(t-1):
        if ab[i][0] <= j:
            dp1[i+1][j] = max(dp1[i][j],dp1[i][j-ab[i][0]]+ab[i][1])
        else:
            dp1[i+1][j] = dp1[i][j]
            
        if ab_r[i][0] <= j:
            dp2[i+1][j] = max(dp2[i][j],dp2[i][j-ab_r[i][0]]+ab_r[i][1])
        else:
            dp2[i+1][j] = dp2[i][j]
            
m=0
for i in range(1,n+1):
    for j in range(t-1):
        m=max(m,dp1[i-1][j]+dp2[n-i][t-1-j]+ab[i-1][1])
print(m)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
s=list(input())
k=int(input())
cnt=1
cnt2=0
tmp=0
flg=0
for i in range(len(s)):
    if tmp==s[i]:
        cnt+=1
    else:
        cnt2+=cnt//2
        cnt=1
    tmp=s[i]
cnt2+=cnt//2
if s[0]==s[-1]:
    m=0
    cnt3=0
    while s[m]==s[0]:
        cnt3+=1
        m+=1
        if m==len(s)-1:
            cnt+=3
            break
    n=1
    cnt4=0
    while s[-n]==s[0]:
        cnt4+=1
        n+=1
        if n==len(s):
            cnt4+=1
            break
    if cnt3%2==1 and cnt4%2==1:
        flg=1

if flg==1:
    ans=cnt2*k+k-1
else:
    ans=cnt2*k
print(ans)
    


Fixed submission:
# coding: utf-8
# Your code here!
s=list(input())
k=int(input())
cnt=1
cnt2=0
tmp=0
flg=0
flg2=0
flg3=0
for i in range(len(s)):
    if tmp==s[i]:
        cnt+=1
    else:
        cnt2+=cnt//2
        cnt=1
    tmp=s[i]
cnt2+=cnt//2

if len(s)==1:
    flg2=1
elif len(set(s))==1:
    flg3=1

elif s[0]==s[-1]:
    m=0
    cnt3=0
    while s[m]==s[0]:
        cnt3+=1
        m+=1
        if m==len(s)-1:
            cnt3+=1
            break
    n=1
    cnt4=0
    while s[-n]==s[0]:
        cnt4+=1
        n+=1
        if n==len(s):
            cnt4+=1
            break
    if cnt3%2==1 and cnt4%2==1:
        flg=1

if flg==1:
    ans=cnt2*k+k-1
elif flg2==1:
    ans=k//2
elif flg3==1:
    ans=(len(s)*k)//2
else:
    ans=cnt2*k
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

n=int(input())
ans=0
for i in range(n-1):
    ans+=i+1
    
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!

n=int(input())

ans=(n*(n-1))//2
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
N,K=map(int,input().split())
MOD=10**9+7

fac=[None for i in range(N)]
finv=[None for i in range(N)]
inv=[None for i in range(N)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)


COMinit(N)

for i in range(1,K+1):
    print(COM(N-K+1,i)*COM(K-1,i-1))



Fixed submission:
# coding: utf-8
N,K=map(int,input().split())
MOD=10**9+7

fac=[None for i in range(5000)]
finv=[None for i in range(5000)]
inv=[None for i in range(5000)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)


COMinit(5000)

for i in range(1,K+1):
    print(COM(N-K+1,i)*COM(K-1,i-1)% MOD)

#print(COM(0,0))

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n,k=map(int,input().split())
b=k
r=n-k
if k>r+1:
    m=r+2
ans=r+1
print(ans)
for i in range(2,k+1):
    ans=0
    for j in range(3):
        if i>=m:
            print(0)
            break
        if r-1>=i-j:
            tmp=cmb(r-1,i-j)
            p=1
            if j==1:
                p=2
            ans+=cmb(b-1,i-1)*tmp*p
            ans=ans%(10**9+7)
    print(ans)

        


Fixed submission:
# coding: utf-8
N,K=map(int,input().split())
MOD=10**9+7

fac=[None for i in range(5000)]
finv=[None for i in range(5000)]
inv=[None for i in range(5000)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)


COMinit(5000)

for i in range(1,K+1):
    print(COM(N-K+1,i)*COM(K-1,i-1)% MOD)

#print(COM(0,0))
Buggy python submission (verdict: Runtime Error):
n=int(input())
p=[]
l=[]
for i in range(n):
    p.append(list(map(int,input().split())))
        


for i in range(n):
    for j in range(i+1,n):
        l.append([p[j][0]-p[i][0],p[j][1]-p[i][1],p[i][0],p[i][1]])

m=0
for i in range(len(l)):
    cnt=0
    acnt=0
    bcnt=0
    tmp=0
    for j in range(len(l)):
        if l[i][0]==0:
            tmp=l[i][3]
            if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                if tmp==l[j][3]:
                    acnt+=1
                    if acnt>m:
                        m=acnt
        if l[i][1]==0:
            tmp=l[i][2]
            if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                if tmp ==l[j][2]:
                    bcnt+=1
                    if bcnt>m:
                        m=bcnt
        if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
            cnt+=1
            if cnt>m:
                m=cnt
        
ans=n
if m!=0:
    ans=n-m-1
if n==2:
    ans=1
print(ans)

Fixed submission:
n,k=map(int,input().split())
if n-k>=0:
    ans=n-k
else:
    ans=1
if k==1:
    ans=0
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
p=[]
l=[]
for i in range(n):
    p.append(list(map(int,input().split())))
        


for i in range(n):
    for j in range(i+1,n):
        l.append([p[j][0]-p[i][0],p[j][1]-p[i][1]])

m=0
for i in range(len(l)):
    cnt=0
    acnt=0
    bcnt=0
    tmp=0
    for j in range(len(l)):
        if l[i][0]==0:
            tmp=l[i][1]
            if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                if tmp==l[j][1]:
                    acnt+=1
                    if acnt>m:
                        m=acnt
        if l[i][1]==0:
            tmp=l[i][0]
            if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
                if tmp ==l[j][0]:
                    bcnt+=1
                    if bcnt>m:
                        m=bcnt
        if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
            cnt+=1
            if cnt>m:
                m=cnt
        
ans=n
if m!=0:
    ans=n-m-1
if n==2:
    ans=1
print(ans)

Fixed submission:
n,k=map(int,input().split())
if n-k>=0:
    ans=n-k
else:
    ans=1
if k==1:
    ans=0
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

def bin_ser(x):
    l=-1
    r=n+1
    while r-l>1:
        i=(l+r)//2
        
        if A[i]==x:
            return i
        
        if A[i]<x:
            l=i
        else:
            r=i
            
    return i

for i in range(m):
    B,C=map(int,input().split())
    k=bin_ser(C)
    for j in range(min(B,k)):
        A.insert(k,C)
        A.pop(0)

print(sum(A))

Fixed submission:
from operator import itemgetter as ite

n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[]
for i in range(m):
    BC.append(list(map(int,input().split())))
A.sort()
BC.sort(key=ite(1),reverse=True)

k=0
cnt=0

for i in range(n):
    if A[i]<BC[k][1]:
        A[i]=BC[k][1]
        cnt+=1
        if cnt==BC[k][0]:
            k+=1
            cnt=0
            if k==len(BC):
                break
    else:
        break

ans=sum(A)
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

def bin_ser(x):
    l=-1
    r=n+1
    while r-l>1:
        i=(l+r)//2
        
        if A[i]==x:
            return i
        
        if A[i]<x:
            l=i
        else:
            r=i
            
    return i

for i in range(m):
    B,C=map(int,input().split())
    k=bin_ser(C)
    for j in range(min(B,k)):
        A.insert(k,C)
        A.pop(0)

print(sum(A))

Fixed submission:
from operator import itemgetter as ite

n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[]
for i in range(m):
    BC.append(list(map(int,input().split())))
A.sort()
BC.sort(key=ite(1),reverse=True)

k=0
cnt=0

for i in range(n):
    if A[i]<BC[k][1]:
        A[i]=BC[k][1]
        cnt+=1
        if cnt==BC[k][0]:
            k+=1
            cnt=0
            if k==len(BC):
                break
    else:
        break

ans=sum(A)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
ans=0
for i in range(3001):
    if i*r>n:
        break
    for j in range(3001):
        if i*r+j*g>n:
            break
        if (n-(r*i+g*j))%b==0 or (n-(r*i+g*j))==0:
                ans+=1
print(ans)

Fixed submission:
r,g,b,n=map(int,input().split())
ans=0
for i in range(3001):
    if i*r>n:
        break
    for j in range(3001):
        if i*r+j*g>n:
            break
        if (n-(r*i+g*j))%b==0 or (n-(r*i+g*j))==0:
                ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
INF=10**10
a=[[INF for i in range(w)] for j in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=="#":
            a[i][j]=0
for i in range(h):
    for j in range(w):
        k=a[i][j]+1

        if i!=h-1:
            if k<a[i+1][j]:
                a[i+1][j]=k

        if j!=w-1:
            if k<a[i][j+1]:
                a[i][j+1]=k

for i_ in range(h):
    for j_ in range(w):
        i=h-1-i_
        j=w-1-j_
        k=a[i][j]+1
        if i!=0:
            if k<a[i-1][j]:
                a[i-1][j]=k

        if j!=0:        
            if k<a[i][j-1]:
                a[i][j-1]=k


arr=np.array(a)
ans=arr.max()
print(ans)

Fixed submission:
H,W,n=map(int,input().split())
h,w=map(int,input().split())
s=list(input())
t=list(input())
sr=0
sl=0
su=0
sd=0
tr=0
tl=0
tu=0
td=0

rl=W-w
ll=w-1
ul=h-1
dl=H-h
nr=w
nl=w
nu=h
nd=h
ans="YES"

for i in range(n):
    if s[i]=="R":
        nr+=1
        sr+=1
    if s[i]=="L":
        nl-=1
        sl+=1
    if s[i]=="U":
        nu+=1
        su+=1
    if s[i]=="D":
        nd-=1
        sd+=1
    if i!=0:
        if t[i-1]=="R":
            nl+=1
            if -lp<rl:
                tr+=1
        if t[i-1]=="L":
            nr-=1
            if -rp<ll:
                tl+=1
        if t[i-1]=="U":
            nd+=1
            if -dp<ul:
                tu+=1
        if t[i-1]=="D":
            nu-=1
            if -up<dl:
                td+=1
    rp=sr-tl
    lp=sl-tr
    up=su-td
    dp=sd-tu
    
    if rl<rp or ll<lp or ul<up or dl<dp:
        ans="NO"
print(ans)