Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
for k in range(m-1,-1,-1):
    while True:
        if s!=[]:
            #最小値を返す
            p=heapq.heappop(s)
            if p[0]+k<=m:
                #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            #最小値をヒープから取り出す
            p=heapq.heappop(q)
            ans+=-p
print(ans)




Fixed submission:
a,b=map(int, input().split())
print(max(a+b,a-b,a*b))

Buggy python submission (verdict: Runtime Error):
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0

for k in range(m-1,-1,-1):
    while True:
        if s!=[]:
            #最小値を返す
            p=heapq.heappop(s)
            if p[0]+k<=m:
                #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
                heapq.heappush(q,-p[1])
            else:
                heapq.heappush(s,p)
                break
        else:
            break
        if q!=[]:
            #最小値をヒープから取り出す
            p=heapq.heappop(q)
            ans+=-p
print(ans)




Fixed submission:
a,b=map(int, input().split())
print(max(a+b,a-b,a*b))

Buggy python submission (verdict: Runtime Error):
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
heapq.heapify(q)
for k in range(m-2,-1,-1):
    if s!=[]:
        #最小値を返す
        p=heapq.heappop(s)
        if p[0]+k<=m:
            #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        #最小値をヒープから取り出す
        p=heapq.heappop(q)
        ans+=-p
print(ans)


Fixed submission:
a,b=map(int, input().split())
print(max(a+b,a-b,a*b))

Buggy python submission (verdict: Runtime Error):
import heapq
n,m=map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
q = []
ans=0
#ヒープソート
heapq.heapify(s)
for k in range(m-2,-1,-1):
    if s!=[]:
        #最小値を返す
        p=heapq.heappop(s)
        if p[0]+k<=m:
            #heappush(list,item) listの葉にitemを追加して小さい要素を上に持ち上げる
            heapq.heappush(q,-p[1])
        else:
            heapq.heappush(s,p)
            break
    else:
        break
    if q!=[]:
        #最小値をヒープから取り出す
        p=heapq.heappop(q)
        ans+=-p
print(ans)


Fixed submission:
a,b=map(int, input().split())
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Time Limit Exceeded):
import heapq as hq
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    a[i][1]*=-1
hq.heapify(a)
k=1
ans=0
q=0
while a and k<=m:
    p=hq.heappop(a)
    if p[0]>k:
        hq.heappush(a,p)
        k+=1
    elif p[0]==k:
        ans-=p[1]
        k+=1
    elif p[0]<k:
        p[0]=k
        hq.heappush(a,p)
print(ans)

Fixed submission:
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
q = []
heapq.heapify(q)
heapq.heapify(ab)
total = 0
for i in range(m, -1, -1):
    while True:
        if len(ab) != 0:
            p = heapq.heappop(ab)
            if p[0] + i <= m:
                heapq.heappush(q, -p[1])
            else:
                heapq.heappush(ab, p)
                break
        else:
            break
    if len(q) != 0:
        p = heapq.heappop(q)
        total += -p
print(total)

Buggy python submission (verdict: Runtime Error):
n,m=map(int, input().split())
s=[[int(j) for j in input().split()] for i in range(n)]
ans=0
s.sort(reverse=True,key=lambda x:x[1])
for k in range(m):
    for i in range(n):
        if s[i][0]+k>m:
            print(s[i])
            s[i:i+1]=[]
            n=n-1
    if s==[]:
        break
    else:
        ans+=s[0][1]
        print(s[0])
        s[0:1]=[]
        n=n-1
print(ans)


Fixed submission:
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
q = []
heapq.heapify(q)
heapq.heapify(ab)
total = 0
for i in range(m, -1, -1):
    while True:
        if len(ab) != 0:
            p = heapq.heappop(ab)
            if p[0] + i <= m:
                heapq.heappush(q, -p[1])
            else:
                heapq.heappush(ab, p)
                break
        else:
            break
    if len(q) != 0:
        p = heapq.heappop(q)
        total += -p
print(total)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A=list(map(int,input().split()))
i=0
j=0
ask=0
while(j<N):
    while(i<N-1):
        x=A[i+1]-A[i]
        if x<-1:
            ask=1
            break
        elif x==-1:
            A[i]=A[i]-1
            break
        i=i+1
    j=j+1
    i=j
if ask==0:
    print('Yes')
else:
    print('No')


Fixed submission:
a, b, c = map(int, input().split())
c=max(c-a+b,0)
print(c)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A=list(map(int,input().split()))
i=0
ask=0
for x in A:
    if A[x+1]-A[x]<0:
        A[x]=A[x]-1
for x in A:
    if A[x]<0:
        ask=1
        break
if ask==0:
    print('Yes')
else:
    print('No')



Fixed submission:
N = int(input())
A=list(map(int,input().split()))
ask=0
#N-1~1までループ
for x in range(N-1,0,-1):
    if A[x]-A[x-1]<0:
        A[x-1]=A[x-1]-1
for x in range(1,N):
    if A[x]-A[x-1]<0:
        ask=1
        break
if ask==0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
mod=10**9+7
n=len(s)
for i in range(n):
    if s[i]!="?":
        s[i]=int(s[i])
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    if s[i]=="?":
        for k in range(10):
            for j in range(13):
                p=(k+10*j)%13
                dp[i+1][p]+=dp[i][j]
                dp[i+1][p]%=mod

    else:
        for j in range(13):
            p=(s[i]+10*j)%13
            dp[i+1][p]+=dp[i][j]
            dp[i+1][p]%=mod
print(dp[n][5])

Fixed submission:
s=list(input())
mod=10**9+7
n=len(s)
for i in range(n):
    if s[i]!="?":
        s[i]=int(s[i])
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    if s[i]=="?":
        for k in range(10):
            for j in range(13):
                p=(k+10*j)%13
                dp[i+1][p]+=dp[i][j]
                dp[i+1][p]%=mod

    else:
        for j in range(13):
            p=(s[i]+10*j)%13
            dp[i+1][p]+=dp[i][j]
            dp[i+1][p]%=mod
print(dp[n][5])
Buggy python submission (verdict: Time Limit Exceeded):
"""
セグメント木：蟻本P153
できること：a[i]の更新(O(log n))、a[L],...,a[R-1]の最小値など(O(log n))
入力：n,a(配列)
     'ide_ele' : 単位元(min:∞, 和:0, 積:1, gcd:0)
     'segfunc' : return min(x,y) とかにする
出力:'init(a)': 配列aで初期化。O(N)
     'update(k,x)': a[k]をxに変更 O(logN)
     'query(p,q)': [p,q)について "segfunc" したものを返す O(logN)
"""
n=int(input())
a=[int(input()) for i in range(n)]
#####segfunc######
def segfunc(x,y):
    return max(x,y)


def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = 0
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(a)
print(query(1,n))
for i in range(1,n):
    print(max(query(0,i),query(i+1,n)))

Fixed submission:
N= int(input())
A=[]
for x in range(0,N):
    A.append(int(input()))
B=sorted(A)
for x in range(0,N):
    if A[x]==B[N-1]:
        print(B[N-2])
    else:
        print(B[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N= int(input())
A=[]
B=[]
for x in range(0,N):
    A.append(int(input()))
    B.append(A[x])
for x in range(0,N):
    A[x]=0
    print(max(A))
    A[x]=B[x]

Fixed submission:
N= int(input())
A=[]
for x in range(0,N):
    A.append(int(input()))
B=sorted(A)
for x in range(0,N):
    if A[x]==B[N-1]:
        print(B[N-2])
    else:
        print(B[N-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=sorted(list(map(int,input().split())))

if n%3==0:
    for j in range(3):
        for i in range(j*(n//3),(j+1)*(n//3)-1):
            if a[i]!=a[i+1]:
                print("No")
                exit()
    if x[0]^x[n//3]==x[2*n//3]:
        print("Yes")
    else:
        print("No")
    exit()
for i in range(0,n-1):
    if a[i]!=a[i+1]:
        print("No")
        exit()
print("Yes")

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))

if n%3==0:
    for j in range(3):
        for i in range(j*(n//3),(j+1)*(n//3)-1):
            if a[i]!=a[i+1]:
                print("No")
                exit()
    if a[0]^a[n//3]==a[2*n//3]:
        print("Yes")
    else:
        print("No")
    exit()
for i in range(0,n-1):
    if a[i]!=a[i+1]:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
n,k=map(int, input().split())
a=list(map(int, input().split()))
ans=0
s=0
j=0
#尺取り法（未満）
for i in range(n):
    #どこまでいけるか
    while(j<n and s+a[j]<k):
        s+=a[j]
        j+=1
    #ずらす
    ans+=j-i
    s-=a[i]
print(n*(n+1)//2-ans)


Fixed submission:
x,a=map(int, input().split())
if x<a:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Runtime Error):
def dp(n):
    d=[0]*(n+1)
    if n==1:
        return 1
    else:
         d[0]=1
         if a[1]==0:
            d[1]=1
         else:
            d[1]=0
         for i in range(2,n+1):
            if a[i]==0:
                d[i]=(d[i-1]+d[i-2])%1000000007
            else:
                d[i]=0
         return d[n]

n,m=map(int, input().split())
a=[0]*(n+1)
for i in range(0,m):
    k=int(input())
    a[k]=1
print(dp(n))

Fixed submission:
a,b,c=map(int,input().split())
print(min(a+b,b+c,c+a))
Buggy python submission (verdict: Runtime Error):
n=int(input())
w= list(map(int, input().split()))
s=sum(w)
t=0
ans=abs(s-2*a[0])
for i in range(n-1):
  t+=a[i]
  ans=min(ans,abs(s-2*t))
print(ans)

Fixed submission:
n=int(input())
w= list(map(int, input().split()))
s=sum(w)
t=0
ans=abs(s-2*w[0])
for i in range(n-1):
  t+=w[i]
  ans=min(ans,abs(s-2*t))
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
dp=[1]*n
cor=[1]*n
for i in range(m):
    cor[int(input())]=0
if cor[0]==0:
    dp[0]=0
if cor[1]==0:
    dp[1]=0
for i in range(2,n):
    dp[i]=(dp[i-1]+dp[i-2])%1000000007
    if cor[i]==0:
        dp[i]=0
print((dp[n-1]+dp[n-2])%1000000007)
#print(dp)

Fixed submission:
def dp(n):
    d=[0]*(n+1)
    if n==1:
        return 1
    else:
         d[0]=1
         if a[1]==0:
            d[1]=1
         else:
            d[1]=0
         for i in range(2,n+1):
            if a[i]==0:
                d[i]=d[i-1]+d[i-2]
            else:
                d[i]=0
         return d[n]

n,m=map(int, input().split())
a=[0]*(n+1)
for i in range(0,m):
    k=int(input())
    a[k]=1
print(dp(n)%1000000007)
Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
s=input()
a-=1
b-=1
c-=1
d-=1
x=[]
cnt=1
y=s[0]
g=[0,0,0,0]
for i in range(1,n):
    if s[i]==y:
        cnt+=1
    else:
        x.append([cnt,y])
        cnt=1
        y=s[i]
    if i==a:
        g[0]=len(x)
    if i==b:
        g[1]=len(x)
    if i==c:
        g[2]=len(x)
    if i==d:
        g[3]=len(x)
x.append([cnt,y])
for i in x:
    if i[0]>=2 and i[1]=='#':
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
for i in range(g[1],min(g[2]-1):
    if x[i][1]=="." and x[i][0]>=3:
        print("Yes")
        exit()
print("No")


Fixed submission:
n,a,b,c,d=map(int,input().split())
s=input()
a-=1
b-=1
c-=1
d-=1
x=[]
for i in range(a,max(c,d)):
    if s[i]==s[i+1]=="#":
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
ans=0
for i in range(b-1,d+2):
    if s[i]==".":
        ans+=1
    else:
        if ans>=3:
            print("Yes")
            exit()
        ans=0
if ans>=3:
    print("Yes")
    exit()
"""
if s[b+1]=="." and s[b-1]==".":
    print("Yes")
    exit()
if s[d-1]=="." and s[d+1]==".":
    print("Yes")
    exit()
"""
print("No")

Buggy python submission (verdict: Runtime Error):
n,a,b,c,d=map(int,input().split())
s=input()
a-=1
b-=1
c-=1
d-=1
x=[]
cnt=1
y=s[0]
g=[0,0,0,0]
for i in range(1,n):
    if s[i]==y:
        cnt+=1
    else:
        x.append([cnt,y])
        cnt=1
        y=s[i]
    if i==a:
        g[0]=len(x)
    if i==b:
        g[1]=len(x)
    if i==c:
        g[2]=len(x)
    if i==d:
        g[3]=len(x)
x.append([cnt,y])
for i in x:
    if i[0]>=2 and i[1]=='#':
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
for i in range(g[1],g[2]):
    if i[1]=="." and i[0]>=3:
        print("Yes")
        exit()
print("No")
#print(x)
#print(g)

Fixed submission:
n,a,b,c,d=map(int,input().split())
s=input()
a-=1
b-=1
c-=1
d-=1
x=[]
for i in range(a,max(c,d)):
    if s[i]==s[i+1]=="#":
        print("No")
        exit()
if a<b and c<d:
    print("Yes")
    exit()
ans=0
for i in range(b-1,d+2):
    if s[i]==".":
        ans+=1
    else:
        if ans>=3:
            print("Yes")
            exit()
        ans=0
if ans>=3:
    print("Yes")
    exit()
"""
if s[b+1]=="." and s[b-1]==".":
    print("Yes")
    exit()
if s[d-1]=="." and s[d+1]==".":
    print("Yes")
    exit()
"""
print("No")
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t)):
            tmp-=a[j]
            res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)

Fixed submission:
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        if 2*t-k>=0:
            if i>n:
                a=get(t,n)
            else:
                a=get(t,i)
            tmp=sum(a)
            for j in range(min(k-t,t)):
                tmp-=a[j]
                res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)

Fixed submission:
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        if 2*t-k>=0:
            a=get(t,i)
            tmp=sum(a)
            for j in range(k-t):
                tmp-=a[j]
                res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)

Fixed submission:
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
a=list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
    for j in range(bc[i][0]):
        a.append(bc[i][1])
a.sort(reverse=True)
ans=0
for i in range(n):
    ans+=a[i]
print(ans)


Fixed submission:
n,m=map(int, input().split())
a=list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
x=[]
for i in range(n):
    x.append([a[i],1])
for i in range(m):
    x.append([bc[i][1],bc[i][0]])
x.sort(reverse=True)
ans=0
count=n
for i in range(n):
    if x[i][1]<count:
        ans+=x[i][0]*x[i][1]
    else:
        ans+=x[i][0]*count
    count-=x[i][1]
    if count<=0:
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
n,m=map(int, input().split())
a=list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
a.sort()
bc.sort(reverse=True, key=lambda x:x[1])
count=0
for i in range(m):
    for j in range(count,count+bc[i][0]):
        if a[j]<bc[i][1]:
            a[j]=bc[i][1]
            count+=1
print(sum(a))

Fixed submission:
n,m=map(int, input().split())
a=list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
x=[]
for i in range(n):
    x.append([a[i],1])
for i in range(m):
    x.append([bc[i][1],bc[i][0]])
x.sort(reverse=True)
ans=0
count=n
for i in range(n):
    if x[i][1]<count:
        ans+=x[i][0]*x[i][1]
    else:
        ans+=x[i][0]*count
    count-=x[i][1]
    if count<=0:
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        self.rnk = [0] * (n + 1)

    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1


import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline

n, m = map(int, input().split())
u = UnionFind(n)
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    u.Unite(a, b)
print(len(set(u.Find_Root(i) for i in range(n))))


Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n + 1)
        self.rnk = [0] * (n + 1)

    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1


import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline

n, m = map(int, input().split())
u = UnionFind(n)
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    u.Unite(a, b)
print(len(set(u.Find_Root(i) for i in range(n))))
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n= map(int, input().split())
ans=0
for i in range(n//r+1):
    for j in range(n//g+1):
        if (n-i*r-j*g)%b==0 and n-i*r-j*g>=0:
            ans+=1
print(ans)

Fixed submission:
r,g,b,n= map(int, input().split())
ans=0
for i in range(n//r+1):
    for j in range(n//g+1):
        if (n-i*r-j*g)%b==0 and n-i*r-j*g>=0:
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ba,a,b,ab=0,0,0,0
for i in range(n):
    s=input()
    if s[0]=='B' and s[-1]=='A':
        ba+=1
    elif s[0]=='B':
        b+=1
    elif s[-1]=='A':
        a+=1
    for i in range(len(s)-1):
        if s[i]=='A' and s[i+1]=='B':
            ab+=1

print(min(a,b)+x+ab)


Fixed submission:
n=int(input())
ba,a,b,ab=0,0,0,0
for i in range(n):
    s=input()
    if s[0]=='B' and s[-1]=='A':
        ba+=1
    elif s[0]=='B':
        b+=1
    elif s[-1]=='A':
        a+=1
    for i in range(len(s)-1):
        if s[i]=='A' and s[i+1]=='B':
            ab+=1
if a==b and a==0 and ba!=0:
	ba-=1
print(min(a,b)+ba+ab)
Buggy python submission (verdict: Runtime Error):
s=input()
t="keyence"
k=0
for i in range(len(s)):
    if t[k]==s[i]:
        k+=1
if k==len(t):
    print("YES")
else:
    print("NO")

Fixed submission:
s=input()
key="keyence"
n=len(s)
for i in range(n-1):
    for j in range(1,n):
        if s[:i]+s[j:]==key:
            print("YES")
            exit()
print("NO")
Buggy python submission (verdict: Runtime Error):
"""
重さと価値がそれぞれw_i,v_iであるようなn個の品物がある.
これらの品物の中から, 重さの総和がWを超えないように選んだ時の,
価値の総和の最大値を求めよ.
1<=n<=100, 1<=w_i<=10^7, 1<=v_i<=100, 1<=limit_w<=10^9
"""
#-------------------------------------------------------------------------------

#入力
INF = 2000000000
"""
メモ : Pythonでは無限大を表す float('inf') があるが, 処理がかなり重たいので
       代わりにsum(v)より真に大きい 2*10^9 を INFとする.
       (https://atcoder.jp/contests/dp/tasks/dp_e において,PyPyを使用して,
        前者だと1060ms, 後者だと570msで2倍近く差が出ている.)
"""
n ,limit_w = map(int, input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())
sum_v = sum(v)
dp = [[INF for i in range(sum_v + 1)] for j in range(n + 1)] 
# dp[i][j]には重さが入る.
# dp[i][j]=(i番目までの品物から価値がちょうどｊになるための重さの最小値)

# ここからメイン
dp[0][0] = 0
for i in range(n):
    for j in range(sum_v + 1):
        if j < v[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
            
# n個まで使って,重さがlimit_wを超えないで価値が最大のものを求める.
ans = 0
for i in range(sum_v + 1):
    if dp[n][i] <= limit_w:
        ans = i
print(ans)


Fixed submission:
n= int(input())
h= list(map(int, input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2])
#print(dp)
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n,k= map(int, input().split())
h= list(map(int, input().split()))
dp=[2000000000]*n
dp[0]=0
for i in range(1,k+1):
    for j in range(0,i):
        dp[i]=min(abs(h[i]-h[0])+dp[j],dp[i])
for i in range(k+1,n):
    for j in range(1,k+1):
        dp[i]=min(abs(h[i]-h[i-j])+dp[i-j],dp[i])
#print(dp)
print(dp[n-1])

Fixed submission:
n,k= map(int, input().split())
h= list(map(int, input().split()))
dp=[2000000000]*n
dp[0]=0
for i in range(1,min(n,k+1)):
    for j in range(0,i):
        dp[i]=min(abs(h[i]-h[0])+dp[j],dp[i])
if n>k:
    for i in range(k+1,n):
        for j in range(1,k+1):
            dp[i]=min(abs(h[i]-h[i-j])+dp[i-j],dp[i])
#print(dp)
print(dp[n-1])