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

Fixed submission:
N, M = [int(i) for i in input().split()]
A = sorted([s for s in input().split()], reverse=True)
numDict = {"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6}
dp = ["" for _ in range(N + 1)]

for i in range(N + 1):
    for strNum in A:
        if i - numDict[strNum] < 0:
            continue
        if i - numDict[strNum] == 0 and dp[i] == "":
            dp[i] = strNum
        preStrNum = dp[i - numDict[strNum]]
        if preStrNum != "":
            if len(preStrNum) + 1 > len(dp[i]):
                dp[i] = preStrNum + strNum

print("".join(sorted(dp[N], reverse=True)))

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
A = sorted([s for s in input().split()], reverse=True)
numDict = {"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6}
dp = ["" for _ in range(N + 1)]

for i in range(N + 1):
    for strNum in A:
        if i - numDict[strNum] == 0 and dp[i] == "":
            dp[i] = strNum

        preStrNum = dp[i - numDict[strNum]]
        if preStrNum != "":
            if len(preStrNum) + 1 > len(dp[i]):
                dp[i] = preStrNum + strNum

print("".join(sorted(dp[N], reverse=True)))

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
A = sorted([s for s in input().split()], reverse=True)
numDict = {"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6}
dp = ["" for _ in range(N + 1)]

for i in range(N + 1):
    for strNum in A:
        if i - numDict[strNum] == 0 and dp[i] == "":
            dp[i] = strNum

        preStrNum = dp[i - numDict[strNum]]
        if preStrNum != "":
            if len(preStrNum) + 1 > len(dp[i]) or \
            len(preStrNum) + 1 == len(dp[i]) and int(preStrNum[0]) > int(strNum):
                dp[i] = "{0}{1}".format(preStrNum, strNum)

print(dp[N])

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
A = sorted([s for s in input().split()], reverse=True)
numDict = {"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6}
dp = ["" for _ in range(N + 1)]

for i in range(N + 1):
    for strNum in A:
        if i - numDict[strNum] == 0 and dp[i] == "":
            dp[i] = strNum

        preStrNum = dp[i - numDict[strNum]]
        if preStrNum != "":
            if len(preStrNum) + 1 > len(dp[i]) or \
            len(preStrNum) + 1 == len(dp[i]) and preStrNum[0] > strNum:
                dp[i] = "{0}{1}".format(preStrNum, strNum)

print(dp[N])
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())

dp = [[float("inf")] * (N * 10 ** 3 + 1) for _ in range(2)]
dp[0][0], dp[1][0] = 0, 0
for i in range(N):
    index = i % 2
    w, v = map(int, input().split())
    for j in range(1, len(dp[0])):
        if j <= v:
            dp[index][j] = min(w, dp[index-1][j])
        else:
            dp[index][j] = min(w + dp[index-1][j-v], dp[index-1][j])

ans = 0
for i, w in enumerate(dp[N % 2 - 1]):
    if w <= W:
        ans = max(ans, i)
    else:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, W = map(int, input().split())

dp = np.ones([2, N * 10 ** 3 + 1], dtype=int) * float("inf")
dp[0][0], dp[1][0] = 0, 0
for i in range(N):
    index = i % 2
    w, v = map(int, input().split())
    for j in range(1, len(dp[0])):
        if j <= v:
            dp[index][j] = min(w, dp[index-1][j])
        else:
            dp[index][j] = min(w + dp[index-1][j-v], dp[index-1][j])

dp = np.minimum(dp[0], dp[1])
ans = 0
for i, w in enumerate(dp):
    if w <= W:
        ans = max(ans, i)
    else:
        break

print(ans)
Problem p02716 (python)

Fixed submission:
N=int(input())
A=[0]+list(map(int,input().split()))

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

dp[0][1]=-float("inf")
dp[2][1]=A[1]
dp[0][2]=0
dp[1][2]=max(A[1],A[2])
dp[2][2]=-float("inf")

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

print(dp[1][N])

Buggy submission (verdict: Runtime Error):
"""
F
"""
N=int(input())
A=list(map(int,input().split()))

left=[0]*N
right=[0]*N

left[0]=A[0]
left[1]=A[1]
for i in range(2,N):
    left[i]=A[i]+left[i-2]
right[-1]=A[-1]
right[-2]=A[-2]
for i in range(N-3,-1,-1):
    right[i]=A[i]+right[i+2]

ans=0
if N%2==0:
    ans=max(right[0],left[-1])
    for i in range(N-2):
        if i%2==0:
            continue
        ans=max(ans,left[i]+right[i+2])
    num=9/0
else:
    P=[0]*N
    Q=[0]*N
    P[-2]=A[-2]
    Q[-2]=A[-1]
    for i in range(-4,-N-1,-1):
        if i%2==0:
            P[i]=A[i]+max(P[i+2],Q[i+2])
            Q[i]=A[i+1]+Q[i+2]

    data=[0]*N
    for i in range(N):
        data[i]=max(P[i],Q[i])
    
    qqq=0
    for i in range(N-2):
        if i%2==0:
            #使わない
            ans=max(ans,qqq+data[i+1])
            qqq+=A[i]
    ans=max(ans,qqq)
    
print(ans)
Problem p02721 (python)

Fixed submission:
import sys

N,K,C=map(int,input().split())

S=list(input())
if C>=N-1:
    if K==1:
        if S.count("o")>=2:
            sys.exit()
        else:
            print(S.index("o")+1)
            sys.exit()
    else:
        sys.exit()
    
    
left=[0]*N
right=[0]*N

if S[0]=="o":
    left[0]=1
for i in range(1,C+1):
    left[i]=left[i-1]
    if S[i]=="o":
        left[i]=1
for i in range(C+1,N):
    if S[i]=="o":
        left[i]=max(left[i-1],left[i-C-1]+1)
    else:
        left[i]=left[i-1]

if S[-1]=="o":
    right[-1]=1
for i in range(N-2,N-C-2,-1):
    right[i]=right[i+1]
    if S[i]=="o":
        right[i]=1
for i in range(N-C-2,-1,-1):
    if S[i]=="o":
        right[i]=max(right[i+1],right[i+C+1]+1)
    else:
        right[i]=right[i+1]

data=[]
for i in range(N):
    if S[i]=="o":
        L=i-C-1
        R=i+C+1
        num=1
        if L>=0:
            num+=left[L]
        if R<N:
            num+=right[R]
        if num>K:
            sys.exit()
        if num==K:
            data.append(i)

for i in range(len(data)):
    if i==0:
        if data[i+1]-data[i]>C:
            print(data[i]+1)
    elif i==len(data)-1:
        if data[i]-data[i-1]>C:
            print(data[i]+1)
    else:
        if data[i+1]-data[i]>C and data[i]-data[i-1]>C:
            print(data[i]+1)

Buggy submission (verdict: Runtime Error):
import sys

N,K,C=map(int,input().split())

S=list(input())
left=[0]*N
right=[0]*N

if S[0]=="o":
    left[0]=1
for i in range(1,C+1):
    left[i]=left[i-1]
    if S[i]=="o":
        left[i]=1
for i in range(C+1,N):
    if S[i]=="o":
        left[i]=max(left[i-1],left[i-C-1]+1)
    else:
        left[i]=left[i-1]

if S[-1]=="o":
    right[-1]=1
for i in range(N-2,N-C-2,-1):
    right[i]=right[i+1]
    if S[i]=="o":
        right[i]=1
for i in range(N-C-2,-1,-1):
    if S[i]=="o":
        right[i]=max(right[i+1],right[i+C+1]+1)
    else:
        right[i]=right[i+1]

data=[]
for i in range(N):
    if S[i]=="o":
        L=i-C-1
        R=i+C+1
        num=1
        if L>=0:
            num+=left[L]
        if R<N:
            num+=right[R]
        if num>K:
            sys.exit()
        if num==K:
            data.append(i)

for i in range(len(data)):
    if i==0:
        if data[i+1]-data[i]>C:
            print(data[i]+1)
    elif i==len(data)-1:
        if data[i]-data[i-1]>C:
            print(data[i]+1)
    else:
        if data[i+1]-data[i]>C and data[i]-data[i-1]>C:
            print(data[i]+1)
Problem p02787 (python)

Fixed submission:
H,N=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]

inf=float("inf")
dp=[inf]*(H+1)
dp[0]=0
ans=inf
for i in range(N):
    A,B=AB[i]
    for j in range(max(0,H-A+1)):
        dp[j+A]=min(dp[j+A],dp[j]+B)
    for j in range(max(0,H-A+1),H):
        ans=min(ans,dp[j]+B)
ans=min(ans,dp[H])

print(ans)

Buggy submission (verdict: Runtime Error):
H,N=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]

inf=float("inf")
dp=[inf]*(H+1)
dp[0]=0
ans=inf
for i in range(N):
    A,B=AB[i]
    for j in range(H-A+1):
        dp[j+A]=min(dp[j+A],dp[j]+B)
    for j in range(H-A+1,H):
        ans=min(ans,dp[j]+B)
ans=min(ans,dp[H])

print(ans)
Problem p02839 (python)

Fixed submission:
h,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(h)]
B=[list(map(int,input().split())) for i in range(h)]
C=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        C[i][j]=abs(A[i][j]-B[i][j])
        
dp=[[0]*w for i in range(h)]
m=80
dp[0][0] = (1<<m+C[0][0]) | (1<<m-C[0][0])

for i in range(h):
    for j in range(w):
        if i>=1:
            dp[i][j] |= (dp[i-1][j]<<m+C[i][j]) | (dp[i-1][j]<<m-C[i][j])
        if j>=1:
            dp[i][j] |= (dp[i][j-1]<<m+C[i][j]) | (dp[i][j-1]<<m-C[i][j])
            
b=list(bin(dp[h-1][w-1]))[::-1]
ans=float("inf")

for i in range(len(b)):
    if b[i]=="1":
        ans=min(ans,abs(m*(h+w-1)-i))

print(ans)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(map(int,input().split())) for i in range(h)]
B=[list(map(int,input().split())) for i in range(h)]
C=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        C[i][j]=abs(A[i][j]-B[i][j])
    
dp=[[0]*w for i in range(h)]
m=80
dp[0][0] = (1<<m+C[0][0]) | (1<<m-C[i][j])

for i in range(h):
    for j in range(w):
        if i>=1:
            dp[i][j] |= (dp[i-1][j]<<C[i][j]) | (dp[i-1][j]>>C[i][j])
        if j>=1:
            dp[i][j] |= (dp[i][j-1]<<C[i][j]) | (dp[i][j-1]>>C[i][j])
        
b=dp[h-1][w-1]
for i in range(m):
    if (b>>m+i)&1==1:
        ans=i
        break
for i in range(m):
    if (b>>m-i)&1==1:
        ans=min(ans,i)
        break

print(ans)
Problem p02840 (python)

Fixed submission:
import sys

n,x,d=map(int,input().split())
if d==0:
    if x==0:
        print(1)
    else:
        print(n+1)
    sys.exit()
    
lst=[]
for k in range(n+1):
    a=k*x%d
    l=k*x+d*k*(k-1)//2
    r=k*x+d*k*(2*n-k-1)//2
    lst.append([a,min(l,r),max(l,r)])
lst.sort()

data=[]
h=[[lst[0][1],lst[0][2]]]
for i in range(1,n+1):
    if lst[i][0]==lst[i-1][0]:
        h.append([lst[i][1],lst[i][2]])
    else:
        data.append(h)
        h=[[lst[i][1],lst[i][2]]]
data.append(h)
d=abs(d)

ans=0
for h in data:
    left,right=h[0]
    for i in range(1,len(h)):
        if h[i][0]<=right:
            right=max(right,h[i][1])
        else:
            ans+=(right-left)//d+1
            left,right=h[i]
    ans+=(right-left)//d+1

print(ans)

Buggy submission (verdict: Runtime Error):
n,x,d=map(int,input().split())
inf=float("inf")
data=[]
for k in range(n+1):
    z=2*k-n
    w=(2*n-k-1)*k-n*(n-1)//2
    y=(k-1)*k-n*(n-1)//2
    num_1=z*x+d*w
    num_2=z*x+d*y
    if num_1<num_2:
        data.append([num_1%(2*d),num_1,num_2])
    else:
        data.append([num_1%(2*d),num_2,num_1])
d=abs(d)
data.sort()
ans=(data[0][2]-data[0][1])//(2*d)+1
m=data[0][1]
for i in range(1,n+1):
    if data[i][0]==data[i-1][0]:
        if data[i][1]>m:
            ans+=(data[i][2]-data[i][1])//(2*d)+1
        else:
            if data[i][2]>m:
                ans+=(data[i][2]-m)//(2*d)
        m=max(m,data[i][2])
    else:
        ans+=(data[i][2]-data[i][1])//(2*d)+1
        m=data[i][2]

print(ans)
Problem p02845 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=1
data=[0,0,0]
for u in a:
    cnt=0
    k=-1
    for i in range(3):
        if u==data[i]:
            k=i
            cnt+=1
    ans=ans*cnt%mod
    if k!=-1:
        data[k]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=1
data=[0,0,0]
for u in a:
    cnt=0
    for i in range(3):
        if u==data[i]:
            k=i
            cnt+=1
    ans=ans*cnt%mod
    data[k]+=1
print(ans)
Problem p02882 (python)

Fixed submission:
import math
a,b,x=map(int,input().split())
if a*a*b>=x*2:
    c=2*x/(a*b)
    d=c**2+b**2
    d=d**(1/2)
    ans=math.acos(c/d)
    print(ans*180/3.1415926535)
else:
    x=a*a*b-x
    c=2*x/(a*a)
    d=c**2+a**2
    d=d**(1/2)
    ans=math.acos(a/d)
    print(ans*180/3.1415926535)

Buggy submission (verdict: Runtime Error):
import numpy as np
a,b,x=map(int,input().split())
if a*a*b>=x*2:
    c=2*x/(a*b)
    d=c**2+b**2
    d=d**(1/2)
    ans=np.arccos(c/d)
    print(ans*180/3.1415926535)
else:
    x=a*a*b-x
    c=2*x/(a*a)
    d=c**2+a**2
    d=d**(1/2)
    ans=np.arccos(a/d)
    print(ans*180/3.1415926535)
Problem p02902 (python)

Fixed submission:
N,M=map(int,input().split())
data=[[] for i in range(N+1)]
for i in range(M):
    A,B=map(int,input().split())
    data[A].append(B)
lst=[]
for i in range(1,N+1):
    flag=[0]*(N+1)
    parent=[0]*(N+1)
    que=[i]
    while que:
        h=[]
        for u in que:
            for v in data[u]:
                if flag[v]==0:
                    flag[v]=1
                    parent[v]=u
                    h.append(v)
        que=h
    if parent[i]==0:
        continue
    lsls=[i]
    zzz=i
    while True:
        zzz=parent[zzz]
        if zzz==i:
            break
        lsls.append(zzz)
    lst.append(lsls)
inf=float("inf")
k=inf
ans=None
for u in lst:
    if k>len(u):
        ans=u
        k=len(u)
if k==inf:
    print(-1)
else:
    print(k)
    for v in ans:
        print(v)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
data=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    data[a].append(b)
lst=[]
for i in range(1,n+1):
    h=[str(i)]
    while h:
        H=[]
        for u in h:
            a=int(u[-1])
            for v in data[a]:
                if v==i:
                    lst.append(int(u))
                    break
                else:
                    H.append(u.join(str(v)))
            else:
                continue
            break
        else:
            h=H
            continue
        break
print(lst)
lst.sort()
li=[]
flag=[0]*(n+1)
for u in lst:
    u=list(str(u))
    for v in u:
        if flag[int(v)]==1:
            break
    else:
        for v in u:
            flag[int(v)]=1
        li.append(u)
print(li)
for u in li:
    a=int(u[0])
    que=[a]
    while h:
        H=[]
        for i in que:
            if i==a:
                break
            H+=data[i]
        else:
            h=H
            continue
        break
    for i in u:
        if i in h:
            break
    else:
        print(len(u))
        for i in u:
            print(i)
        break
else:
    print(-1)
Problem p02905 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
V=max(A)
mod=998244353
data=[0]*(V+1)
data[1]=1
for i in range(2,V+1):
    data[i]=-(mod//i)*data[mod%i]%mod
for i in range(1,V+1):
    for j in range(2,V//i+1):
        data[i*j]=(data[i*j]-data[i])%mod
lst=[0]*(V+1)
for a in A:
    lst[a]+=1
mod_2=pow(2,mod-2,mod)
ans=0
for i in range(1,V+1):
    sum_1=0
    sum_2=0
    for j in range(1,V//i+1):
        zzz=i*j
        sum_1+=zzz*lst[zzz]
        sum_2+=zzz**2*lst[zzz]
    ans=(ans+(sum_1**2-sum_2)*data[i]*mod_2)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
#AGC C
import math
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n-1):
    for j in range(i+1,n):
        s=(s+(a[i]*a[j])//(math.gcd(a[i],a[j])))%998244353
print(s)
Problem p02921 (python)

Fixed submission:
s=input()
t=input()
a=0
for i in range(3):
  if s[i]==t[i]:
    a+=1
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
print((int((n-1)*n)/2))
Problem p02936 (python)

Fixed submission:
#D
n,q=map(int,input().split())
data=[[] for i in range(n+1)]
counter=[0]*(n+1)
for i in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
h=[1]
done=[0]*(n+1)
while h:
    a=h.pop()
    for l in data[a]:
        if done[l]==0:
            counter[l]+=counter[a]
            h.append(l)
    done[a]=1
print(*counter[1:])

Buggy submission (verdict: Runtime Error):
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
	a,b=map(int,input().split())
 	g[a].append(b)
 	g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 	v,val=map(int,input().split())
 	cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 	v=q.pop()
 	checked[v]=1 #頂点を見たかどうかのフラグを更新する
 	for u in g[v]:
   		if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     		continue
   		cnt[u]+=cnt[v]
   	q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Buggy submission (verdict: Runtime Error):
#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n)]
counter=[0 for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
        data[a].append(b)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
for i in range(1,n):
    if data[i]:
        for j in range(len(data[i])):
            counter[data[i][j]]+=counter[i]
counter=deque(counter)
counter.popleft()
print(*counter)

Buggy submission (verdict: Runtime Error):
#D
from collections import deque
n,q=map(int,input().split())
data=[[] for i in range(n)]
counter=[0 for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
        data[a].append(b)
for i in range(q):
    p,x=map(int,input().split())
    counter[p]+=x
for i in range(1,n):
    if data[i]:
        for j in range(len(data[i])):
            counter[data[i][j]]+=counter[i]
counter=deque(counter)
counter.popleft()
print(*counter)
Problem p02945 (python)

Fixed submission:
num = input().split()
A = int(num[0])
B = int(num[1])
s = [A+B,A-B,A*B]
print(max(s))

Buggy submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
for i in range(0,N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            t +=1
print(t)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
while len(s)>0:
    a = s.count(s[0])
    if a==1:
        continue
    else:
        a = (a*(a-1))/2
        t = t+a
    s.remove(s[0])
print(t)
Problem p03027 (python)

Fixed submission:
mod=10**6+3

inv=[0]*mod
inv[1]=1
for i in range(2,mod):
    inv[i]=-(mod//i)*inv[mod%i]%mod

data=[1]
for i in range(1,mod):
    data.append(data[-1]*i%mod)

Q=int(input())
xdn=[list(map(int,input().split())) for i in range(Q)]

for x,d,n in xdn:
    if d==0:
        print(pow(x,n,mod))
        continue
    if x==0:
        print(0)
        continue
    k=x*inv[d]%mod
    if k+n-1>=mod:
        print(0)
    else:
        print(pow(d,k+n-1,mod)*data[k+n-1]*inv[pow(d,k-1,mod)*data[k-1]%mod]%mod)

Buggy submission (verdict: Runtime Error):
mod=10**6+3

inv=[0]*mod
inv[1]=1
for i in range(2,mod):
    inv[i]=-(mod//i)*inv[mod%i]%mod

data=[1]
for i in range(1,mod):
    data.append(data[-1]*i%mod)

Q=int(input())
xdn=[list(map(int,input().split())) for i in range(Q)]

for x,d,n in xdn:
    k=x*inv[d]%mod
    if k+n-1>=mod:
        print(0)
    else:
        print(pow(d,k+n-1,mod)*data[k+n-1]*inv[pow(d,k-1,mod)*data[k-1]%mod]%mod)
Problem p03032 (python)

Fixed submission:
#D
from heapq import heappush,heappop
from collections import deque
import sys
n,k=map(int,input().split())
v=deque(list(map(int,input().split())))
w=[[] for i in range(n)]
answer=-100000000
for i in range(min(n+1,k+1)):
    for j in range(min(n-i+1,k-i+1)):
        h=[]
        
        for a in range(i):
            heappush(h,v[a])
        for a in range(j):
            heappush(h,v[n-1-a])
        for a in range(k-i-j):
            if h and h[0]<0:
                heappop(h)
            else:
                break
        answer=max(answer,sum(h))
print(answer)

Buggy submission (verdict: Runtime Error):
#D
from heapq import heappush,heappop
from collections import deque
n,k=map(int,input().split())
v=deque(list(map(int,input().split())))
w=[[] for i in range(n)]
answer=-100000000
for i in range(k+1):
    for j in range(k-i+1):
        h=[]
        for a in range(i):
            heappush(h,v[a])
        for a in range(j):
            heappush(h,v[n-1-a])
        for a in range(k-i-j):
            if h and h[0]<0:
                heappop(h)
            else:
                break
        answer=max(answer,sum(h))
print(answer)
Problem p03040 (python)

Fixed submission:
from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)

Buggy submission (verdict: Runtime Error):
from bisect import bisect,insort
import itertools
q=int(input())
query=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
a_sum=0
b_sum=0
A=[]
count=0
for u in query:
    if u[0]==2:
        if count%2==1:
            print(A[num],a_sum+b_sum-A[num])
        else:
            print(A[num-1],a_sum+b_sum)
    else:
        count+=1
        a,b=u[1],u[2]
        b_sum+=b
        c=bisect(A,a)
        num=count//2
        if c>=num:
            if count%2==0:
                a_sum+=-2*A[num-1]+a
            else:
                a_sum+=a
            itertools.chain(A[:c],[a],A[c:])
        else:
            if count%2==0:
                a_sum+=-a
            else:
                a_sum+=-a+2*A[num-1]
            itertools.chain(A[:c],[a],A[c:])
Problem p03049 (python)

Fixed submission:
N=int(input())
s=[input() for _ in range(N)]
cnt=0

A_count=0
B_count=0
BA_count=0
for u in s:
    cnt+=u.count("AB")
    if u[0]=="B":
        B_count+=1
    if u[-1]=="A":
        A_count+=1
    if u[0]=="B" and u[-1]=="A":
        BA_count+=1
if A_count==B_count==BA_count:
    if A_count==0:
        print(cnt)
    else:
        print(cnt+A_count-1)
else:
    print(cnt+min(A_count,B_count))

Buggy submission (verdict: Runtime Error):
N=int(input())
s=[input() for _ in range(N)]
cnt=0

A_count=0
B_count=0
BA_count=0
for u in s:
    cnt+=u.count("AB")
    if u[0]=="B":
        B_count+=1
    if u[-1]=="A":
        A_count+=1
    if u[0]=="B" and u[-1]=="A":
        BA_count+=1
if A_count==B_count==BA_count:
    if A_count==0:
        print(cnt)
    else:
        print(cnt+A_count-1)
else:
    print(cnt+min(A_count,B,count))
Problem p03061 (python)

Fixed submission:
#C
import sys
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
if len(a)==2:
    print(max(a))
    sys.exit()
g=gcd(a[0],a[1])
b=[]
for i in range(2,n):
    l=gcd(g,a[i])
    if l!=g:
        b.append(i)
        g=l
s=[]
g=gcd(a[0],a[2])
for i in range(3,n):
    g=gcd(g,a[i])
s.append(g)
g=gcd(a[1],a[2])
for i in range(3,n):
    g=gcd(g,a[i])
s.append(g)
for i in range(len(b)):
    g=gcd(a[0],a[1])
    for j in range(2,n):
        if j==b[i]:
            continue
        g=gcd(g,a[j])
    s.append(g)
print(max(s))

Buggy submission (verdict: Runtime Error):
#C
import sys
from math import gcd
n=int(input())
a=list(map(int,input().split()))
if len(a)==2:
    print(max(a))
    sys.exit()
g=gcd(a[0],a[1])
b=[]
for i in range(2,n):
    l=gcd(g,a[i])
    if l!=g:
        b.append(i)
        g=l
s=[]
g=gcd(a[0],a[2])
for i in range(3,n):
    g=gcd(g,a[i])
s.append(g)
g=gcd(a[1],a[2])
for i in range(3,n):
    g=gcd(g,a[i])
s.append(g)
for i in range(len(b)):
    g=gcd(a[0],a[1])
    for j in range(2,n):
        if j==b[i]:
            continue
        g=gcd(g,a[j])
    s.append(g)
print(max(s))