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

Fixed submission:
a,b=map(int,input().split())
ans=0
for i in range(1,b,a-1):
  ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
ans=0
for i in rnage(0,b,a-1):
  ans+=1
print(ans+1)
Problem p02647 (python)

Fixed submission:
from collections import deque

n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(min(k,50)):
    P=[]
    M=[]
    cnt=0
    for a in range(n):
        if A[a]==n:
            cnt+=1
            continue
        P.append(a-A[a])
        M.append(a+A[a]+1)
    P.sort()
    M.sort()
    P=deque(P)
    M=deque(M)
    C=[]
    m=n
    for j in range(n):
        if P:
            while P[0]<=j:
                P.popleft()
                cnt+=1
                if not P:
                    break
        if M:
            while M[0]<=j:
                M.popleft()
                cnt-=1
                if not M:
                    break
        C.append(cnt)
        m=min(cnt,m)
    A=C
    if m==n:
        break
print(*A)

Buggy submission (verdict: Runtime Error):
from collections import deque

n,k=map(int,input().split())
A=list(map(int,input().split()))
#A=[0]*n
for i in range(min(k,50)):
    P=[]
    M=[]
    cnt=0
    for a in range(n):
        if A[a]==n:
            cnt+=1
            continue
        P.append(a-A[a])
        M.append(a+A[a]+1)
    P.sort()
    M.sort()
    P=deque(P)
    M=deque(M)
    C=[]
    m=n+100
    for j in range(n):
        if P:
            while P[0]<=j:
                P.popleft()
                cnt+=1
                if not P:
                    break
        while M[0]<=j:
            M.popleft()
            cnt-=1
        C.append(cnt)
        m=min(cnt,m)
    A=C
    if m==n:
        break
print(*A)
Problem p02733 (python)

Fixed submission:
h,w,k=map(int,input().split())
S=[]
for i in range(h):
    s=int(input(),2)
    S.append(s)
ans=h+w-2
for i in range(2**(h-1)):
    flag=False
    now=0 #区切った数
    cnt=0 #1の数
    y=0
    for j in range(h-1):
        if (i>>j)&1:
            y+=1
    C=[0]*(y+1) #1の数保存配列
    for x in range(w):
        T=[] #現在の列での1の数保存配列
        for j in range(h):      
            cnt+=(S[j]>>x)&1
            if cnt>k:
                flag=True
                break
            if (i>>j)&1: #横の区切り判定
                T.append(cnt)
                cnt=0
            if j==h-1: #最後の列
                T.append(cnt)
                cnt=0
        if flag:
            break
        for j in range(len(C)): #それぞれのブロックに対して
            if C[j]+T[j]>k:
                now+=1
                C=T
                break
            else:
                C[j]+=T[j]
    if flag:
        continue
    ans=min(ans,now+y)
print(ans)

Buggy submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
S=[]
for i in range(h):
    s=int(input(),2)
    S.append(s)
ans=100000
for i in range(2**(h-1)):
    now=0 #区切った数
    cnt=0 #1の数
    y=0
    for j in range(h-1):
        if (i>>j)&1:
            y+=1
    C=[0]*(y+1) #1の数保存配列
    for x in range(w):
        T=[]　#現在の列での1の数保存配列
        for j in range(h):      
            cnt+=(S[j]>>x)&1
            if (i>>j)&1: #横の区切り判定
                T.append(cnt)
                cnt=0
            if j==h-1: #最後の列
                T.append(cnt)
                cnt=0
        for j in range(len(C)):
            if C[j]+T[j]>k:
                now+=1
                C=T
                break
            else:
                C[j]+=T[j]
    ans=min(ans,now+y)
print(ans)
Problem p02789 (python)

Fixed submission:
n,m=map(int,input().split())
print("Yes" if n==m else "No")

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7

import fractions
def lcm(a,b):
    return a*b//fractions.gcd(a,b)

def power(a,p):
    T=[a]
    while 2**(len(T))<p:
        T.append(T[-1]**2%p)
    b=bin(p-2)
    ans=1
    for i in range(len(b)-2):
        if int(b[-i-1])==1:
            ans=ans*T[i]%p
    return ans   

l=A[0]
for i in range(n-1):
    l=lcm(l,A[i+1])
s=0
for i in range(n):
    s+=l*power(A[i],mod)%mod
    s%=mod
print(s)
Problem p02804 (python)

Fixed submission:
n,k=map(int,input().split())
A=sorted(map(int,input().split()))

def cmb(n,r,mod):
    if (r<0 or r>n):
        return 0
    r=min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod

mod=10**9+7
N=10**5
g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,N+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

ans=0
for i in range(n-k+1):
    ans+=cmb(n-1-i,k-1,10**9+7)*(A[-i-1]-A[i])%(10**9+7)
    ans%=10**9+7
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=sorted(map(int,input().split()))

nCr={}
def cmb(n,r):
    if r==0 or r==n: return 1
    if r==1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)]=(cmb(n-1,r)+cmb(n-1,r-1))%(10**9+7)
    return nCr[(n,r)]

ans=0
for i in range(n-k+1):
    ans+=cmb(n-1-i,k-1)*(A[-i-1]-A[i])%(10**9+7)
    ans%=10**9+7
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=sorted(map(int,input().split()))

nCr={}
def cmb(n,r):
    if r==0 or r==n: return 1
    if r==1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)]=(cmb(n-1,r)+cmb(n-1,r-1))%(10**9+7)
    return nCr[(n,r)]

ans=0
for i in range(n-k+1):
    ans+=cmb(n-1-i,n-k-i)*(A[-i-1]-A[i])%(10**9+7)
    ans%=10**9+7
print(ans)
Problem p02814 (python)

Fixed submission:
import sys
import fractions
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x: x//2, A))

def dev2(x):
    c=0
    while x%2==0:
        x=x//2
        c+=1
    return c

def lcm(a,b):
    return a*b//fractions.gcd(a,b)

if n==1:
    if A[0]<=m:
        print(int((m/A[0]+1)/2))
    else:
        print(0)
else:
    d=dev2(A[0])
    for i in range(n-1):
        if dev2(A[i+1]) != d:
            print(0)
            sys.exit()
    l=A[0]
    for i in range(n-1):
        l=lcm(l,A[i+1])
        if l>m:
            print(0)
            sys.exit()
    print(int((m/l+1)/2))

Buggy submission (verdict: Runtime Error):
import sys
import fractions
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x: x//2, A))

def dev2(x):
    c=0
    while x%2==0:
        x=x//2
        c+=1
    return c

def lcm(a,b):
    return a*b//fractions.gcd(a,b)

if n==1:
    if l<=m:
        print(int((m/l+1)/2))
    else:
        print(0)
else:
    d=dev2(A[0])
    for i in range(n-1):
        if dev2(A[i+1]) != d:
            print(0)
            sys.exit()     
    for i in range(n-1):
        l=lcm(A[i],A[i+1])
        if l>m:
            print(0)
            sys.exit()
    print(int((m/l+1)/2))

Buggy submission (verdict: Runtime Error):
import fractions
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x: x//2, A))

x=0 #2で割れる回数が同じかどうかの判定
T=A
while x==0:
    if (t%2 for t in T) == 0:
        T=list(map(lambda x: x/2, T))
    elif (t%2 for t in T) != 0:
        break
    else:
        x=1

def lcm(a,b):
    return a*b//fractions.gcd(a,b)

if x==1:
    print(0)
else:
    for i in range(n-1):
        l=lcm(A[i],A[i+1])
        if l>m:
            print(0)
            break
    if l<=m:
        print(int((m/l+1)/2))
Problem p02830 (python)

Fixed submission:
n=int(input())
s,t=input().split()
for i in range(n):
    print(s[i],end="")
    print(t[i],end="")

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
for i in range(n):
    print(s[i],end="")
    print(t[i],end="")
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n=int(input())
L=[[] for i in range(n)]
V=[]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    L[a].append(b)
    L[b].append(a)
    V.append([a,b])
k=max(len(l) for l in L)
C=[-1]*n
D=[-1]*n
def dfs(s,p=-1,d=0): #深さ優先探索(親,上の辺の色,深さ)
    c=C[s]
    for i in L[s]: #子に対して
        if i!=p: #親と一緒じゃないとき
            c=(c+1)%k
            C[i]=c
            D[i]=d
            dfs(i,s,d+1) #色をつけ、スタートを更新し、再探索

dfs(0)
print(k)
for v in V:
    if D[v[0]]>D[v[1]]:
        print(C[v[0]]+1)
    else:
        print(C[v[1]]+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
L=[[] for i in range(n)]
V=[]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    L[a].append(b)
    L[b].append(a)
    V.append([a,b])
k=max(len(l) for l in L)
C=[-1]*n
D=[-1]*n
def dfs(s,p=-1,d=0): #深さ優先探索(親,上の辺の色,深さ)
    c=C[s]
    for i in L[s]: #子に対して
        if i!=p: #親と一緒じゃないとき
            c=(c+1)%k
            C[i]=c
            D[i]=d
            dfs(i,s,d+1) #色をつけ、スタートを更新し、再探索

dfs(0)
print(k)
for v in V:
    if D[v[0]]>D[v[1]]:
        print(C[v[0]]+1)
    else:
        print(C[v[1]]+1)
Problem p02900 (python)

Fixed submission:
import fractions
a,b=map(int,input().split())
g=fractions.gcd(a,b)

import math
def findFactors(n):
    now=n
    f=[]
    while now%2==0:
        now//=2
        f.append(2)
    p=3
    while p<=math.sqrt(n):
        while now%p==0:
            now//=p
            f.append(p)
        p+=2
        if now==1:
            break
    if now>math.sqrt(n):
        f.append(now)
    return f

if g==1:
    print(1)
else:
    f=set(findFactors(g))
    print(len(f)+1)

Buggy submission (verdict: Runtime Error):
import fractions
a,b=map(int,input().split())
g=fractions.gcd(a,b)

def make_eratosthenes(n):
    A=[0]*n
    A[0],A[1]=-1,-1 #0と1は対象外
    for i in range(2,n):
        if A[i]==0:
            j=i
            while j<n:
                A[j]=i
                j+=i
    return A

E=make_eratosthenes(g+100)
l={}
now=g
f=[] #素因数格納配列
while now>1:
    f.append(E[now])
    now//=E[now]

f=set(f)
print(len(f)+1)
Problem p02910 (python)

Fixed submission:
import sys
S=input()
n=len(S)
if n>1:
    for i in range(n//2):
        s=S[2*i]
        if s=="L":
            print("No")
            sys.exit()
        s=S[2*i+1]
        if s=="R":
            print("No")
            sys.exit()
if n%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
S=input()
if len(S)>1:
    for i in range(n//2):
        s=S[2*i]
        if s=="L":
            print("No")
            sys.exit()
        s=S[2*i+1]
        if s=="R":
            print("No")
            sys.exit()
if len(S)%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
S=input()
if len(S)>1:
    for i in range(n//2):
        s=S[2*i]
        if s=="L":
            print("No")
            sys.exit()
        s=S[2*i+1]
        if s=="R":
            print("No")
            sys.exit()
if n%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
S=input()
if len(S)>1:
    for i in range(n//2):
        s=S[2*i]
        if s=="L":
            print("No")
            sys.exit()
        s=S[2*i+1]
        if s=="R":
            print("No")
            sys.exit()
if n%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
S=input()
if n>1:
    for i in range(n//2):
        s=S[2*i]
        if s=="L":
            print("No")
            sys.exit()
        s=S[2*i+1]
        if s=="R":
            print("No")
            sys.exit()
if n%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
S=input()
for i in range(n//2):
    s=S[2*i]
    if s=="L":
        print("No")
        sys.exit()
    s=S[2*i+1]
    if s=="R":
        print("No")
        sys.exit()
if n%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")
Problem p02936 (python)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque

def main():
    n,q=map(int,input().split())
    G=[[] for i in range(n)] #隣接配列
    P=[0]*n #親のポイント
    for i in range(n-1):
        a,b=map(int,input().split())
        a-=1
        b-=1
        G[a].append(b)
        G[b].append(a)
    for i in range(q):
        p,x=map(int,input().split())
        p-=1
        P[p]+=x
    
    Chk=[0]*n #訪問済みチェック
    q=deque([0])
    while q: #qが空になるまで(BFS:幅優先探索)
        now=q.popleft() #取り出す
        Chk[now]=1 #訪問済みにする
        for i in G[now]: #子に対し
            if Chk[i]==0: #未訪問のとき
                P[i]+=P[now] #ポイント加算
                q.append(i) #親としてqに入れる

    print(*P)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

n,q=map(int,input().split())
G=[[] for i in range(n)] #隣接配列
P=[0]*n #親のポイント
Ga_append=G[a].append
Gb_append=G[b].append
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    Ga_append(b)
    Gb_append(a)
for i in range(q):
    p,x=map(int,input().split())
    p-=1
    P[p]+=x
    

def dfs(s,p=-1):        
    for i in G[s]:
        if i!=p:
            P[i]+=P[s]
            dfs(i,s)

dfs(0)
print(*P)
Problem p02960 (python)

Fixed submission:
S=input()
n=len(S)
R=[0]*13
cnt=[0]*13
Pow=[[] for i in range(6)]
mod=10**9+7

for i in range(6):
    c=10**i
    for j in range(10):
        Pow[i].append(c*j%13)
ans=0
flag=0
for i in range(n):
    if S[n-i-1]=="?":
        P=Pow[i%6]
        if flag==0:
            for p in P:
                R[p]=1
                flag=1
        else:
            for j in range(10):
                for k in range(13):
                    cnt[(k+P[j])%13]+=R[k]%mod
            R=cnt
            cnt=[0]*13
    else:
        x=int(S[n-i-1])
        ans+=Pow[i%6][x]
ans%=13
if flag==0:
    if ans==5:
        print(1)
    else:
        print(0)
else:
    print(R[(18-ans)%13]%mod)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

S=input()
n=len(S)
R=[0]*13
cnt=[0]*13
Pow=[[] for i in range(6)]
mod=10**9+7

for i in range(6):
    c=10**i
    for j in range(10):
        Pow[i].append(c*j%13)
ans=0
flag=0
for i in range(n):
    if S[n-i-1]=="?":
        P=Pow[i%6]
        if flag==0:
            for p in P:
                R[p]=1
                flag=1
        else:
            for j in range(10):
                for k in range(13):
                    cnt[(k+P[j])%13]+=R[k]%mod
            R=cnt
            cnt=[0]*13
    else:
        x=int(S[n-i-1])
        ans+=Pow[i%6][x]
ans%=13
print(R[(18-ans)%13]%mod)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

S=input()
n=len(S)
R=[0]*13 #剰余テーブル
cnt=[0]*13
Pow=[[] for i in range(6)] #10の累乗の剰余テーブル
mod=10**9+7

for i in range(6):
    c=10**i
    for j in range(10):
        Pow[i].append(c*j%13)
print(Pow)
ans=0
flag=0
for i in range(n):
    if S[n-i-1]=="?":
        P=Pow[i%6] #当該の剰余テーブル
        if flag==0:
            for p in P:
                R[p]=1
                flag=1
        else:
            for j in range(10):
                for k in range(13):
                    cnt[(k+P[j])%13]+=R[k]%mod
            R=cnt
            cnt=[0]*13
    else:
        x=int(S[n-i-1])
        ans+=Pow[i%6][x]
        print(x,ans)
    print(R,i)
    print(sum(R))
ans%=13
print(R[(18-ans)%13]%mod)
Problem p02995 (python)

Fixed submission:
import fractions
def lcm(a,b):
    return a*b//fractions.gcd(a,b)

a,b,c,d=map(int,input().split())

P=[c,d,lcm(c,d)]
A=[]
for p in P:
    if a%p==0:
        left=a//p
    else:
        left=a//p+1
    right=b//p
    if left<=right:
        A.append(right-left+1)
    else:
        A.append(0)
print(b-a+1-A[0]-A[1]+A[2])

Buggy submission (verdict: Runtime Error):
import fractions
def lcm(a,b):
    return a*b//fractions.gcd(a,b)

a,b,c,d=map(int,input().split())

P=[c,d,lcm(c,d)]
A=[]
for p in P:
    if a%p==0:
        left=a//p
    else:
        left=a//p+1
    right=b//p
    if left<=right:
        A.append(right-left+1)
print(b-a+1-A[0]-A[1]+A[2])
Problem p03032 (python)

Fixed submission:
import heapq as hq

N,K=map(int,input().split())
V=list(map(int,input().split()))

ans=0
for i in range(1,min(N,K)+1): #取り出す個数
    for j in range(i+1):
        A=[]
        hq.heapify(A) #左から取り出す個数
        for k in range(j):
            hq.heappush(A,V[k])
        for k in range(i-j):
            hq.heappush(A,V[N-k-1])
        p=min(i,K-i) #しまえる個数
        while p>0:
            if A[0]<0:
                hq.heappop(A)
                p-=1
            else:
                break
        ans=max(sum(A),ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as hq

N,K=map(int,input().split())
V=list(map(int,input().split()))

ans=0
for i in range(1,min(N,K)+1): #取り出す個数
    for j in range(i+1):
        A=[]
        hq.heapify(A) #左から取り出す個数
        for k in range(j):
            hq.heappush(A,V[k])
        for k in range(i-j):
            hq.heappush(A,V[n-k-1])
        p=min(i,K-i) #しまえる個数
        while p>0:
            if A[0]<0:
                hq.heappop(A)
                p-=1
            else:
                break
        ans=max(sum(A),ans)
print(ans)
Problem p03037 (python)

Fixed submission:
import sys

n,m=map(int,input().split())
l=0
r=n+1
for i in range(m):
    a,b=map(int,input().split())
    l=max(l,a)
    r=min(r,b)
    if l>r:
        print(0)
        sys.exit()
print(r-l+1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=0
r=n+1
for i in range(m):
    a,b=map(int,input().split())
    l=max(l,a)
    r=min(r,b)
    if l>r:
        print(0)
        sys.exit()
print(r-l+1)
Problem p03044 (python)

Fixed submission:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**8)

n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    G[u].append([v,w])
    G[v].append([u,w])

A=[0]*n
def dfs(s,p=-1):
    for g in G[s]:
        if g[0]!=p:
            A[g[0]]=A[s]+g[1]
            dfs(g[0],s)

dfs(0)
for a in A:
    if a%2==0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    G[u].append([v,w])
    G[v].append([u,w])

A=[0]*n
def dfs(s,p=-1):
    for g in G[s]:
        if g[0]!=p:
            A[g[0]]=A[s]+g[1]
            dfs(g[0],s)

dfs(0)
for a in A:
    if a%2==0:
        print(0)
    else:
        print(1)
Problem p03074 (python)

Fixed submission:
n,k=map(int,input().split())
S=input()

now=S[0]
cnt=1
A=[] #個数配列
for i in range(n-1):
    if S[i+1]==now:
        cnt+=1
    else:
        A.append(cnt)
        cnt=1
        now=S[i+1]
if cnt>0:
    A.append(cnt)
l=len(A)
    
if S[0]=="0":
    if l<=2*k:
        ans=n
    elif 2*k+1<=l<=2*k+2:
        ans=max(sum(A[:2*k]),sum(A[1:]))
    else:
        ans=max(sum(A[:2*k]),sum(A[1:2*k+2]))
        cnt=sum(A[1:2*k+2])
        for i in range((l-2*k-2)//2):
            cnt-=A[2*i+1]+A[2*i+2]
            cnt+=A[2*k+2*i+2]+A[2*k+2*i+3]
            ans=max(cnt,ans)
        if l%2!=0:
            ans=max(sum(A[l-2*k:]),ans)
else:
    if l<=2*k+1:
        ans=n
    else:
        ans=sum(A[:2*k+1])
        cnt=ans
        for i in range((l-2*k-1)//2):
            cnt-=A[2*i]+A[2*i+1]
            cnt+=A[2*k+2*i+1]+A[2*k+2*i+2]
            ans=max(cnt,ans)
        if l%2==0:
            ans=max(sum(A[l-2*k:]),ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
S=input()

now=S[0]
cnt=1
A=[] #個数配列
for i in range(n-1):
    if S[i+1]==now:
        cnt+=1
    else:
        A.append(cnt)
        cnt=1
        now=S[i+1]
if cnt>0:
    A.append(cnt)
l=len(A)
    
if S[0]=="0":
    if l<=2*k:
        ans=n
    elif 2*k+1<=l<=2*k+2:
        ans=max(sum(A[:2*k]),sum(A[1:]))
    else:
        ans=max(sum(A[:2*k]),sum(A[1:2*k+2]))
        cnt=ans
        for i in range((l-2*k-2)//2):
            cnt-=A[2*i+2]+A[2*i+3]
            cnt+=A[2*k+2*i+2]+A[2*k+2*i+3]
            ans=max(cnt,ans)
        if l%2!=0:
            ans=max(A[l-2*k:],ans)
else:
    if l<=2*k+1:
        ans=n
    else:
        ans=sum(A[:2*k+1])
        cnt=ans
        for i in range((l-2*k-1)//2):
            cnt-=A[2*i]+A[2*i+1]
            cnt+=A[2*k+2*i+1]+A[2*k+2*i+2]
            ans=max(cnt,ans)
        if l%2!=1:
            ans=max(A[l-2*k-1:],ans)
print(ans)
Problem p03148 (python)

Fixed submission:
import heapq as hq

n,k=map(int,input().split())
A=[]
S0=[] #種類が増えない寿司
S1=[] #種類が増える寿司
for i in range(n):
    t,d=map(int,input().split())
    A.append([t,d])
A=list(reversed(sorted(A)))

now=0
for i in range(n):
    t=A[i][0]
    d=A[i][1]
    if now==t:
        S0.append(-d)
    else:
        S1.append(-d)
        now=t
hq.heapify(S0)
hq.heapify(S1)
C=[] #消し得る寿司のストック(S0から出したもの)

x=0 #おいしさの合計
y=0 #種類数
for i in range(k):
    if len(S0)==0:
        x+=-hq.heappop(S1)
        y+=1
        continue
    if len(S1)==0:
        s0=-hq.heappop(S0)
        x+=s0
        hq.heappush(C,s0)
        continue
    if S1[0]<=S0[0]:
        x+=-hq.heappop(S1)
        y+=1
    else:
        s0=-hq.heappop(S0)
        x+=s0
        hq.heappush(C,s0)
ans=x+y**2

for i in range(min(len(S1),len(C))):
    c=hq.heappop(C)
    s1=-hq.heappop(S1)
    x+=s1-c
    y+=1
    ans=max(x+y**2,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq as hq

n,k=map(int,input().split())
A=[]
S0=[] #種類が増えない寿司
S1=[] #種類が増える寿司
for i in range(n):
    t,d=map(int,input().split())
    A.append([t,d])
A=list(reversed(sorted(A)))

now=0
for i in range(n):
    t=A[i][0]
    d=A[i][1]
    if now==t:
        S0.append(-d)
    else:
        S1.append(-d)
        now=t
hq.heapify(S0)
hq.heapify(S1)
C=[] #消し得る寿司のストック(S0から出したもの)

x=0 #おいしさの合計
y=0 #種類数
for i in range(k):
    if S1[0]<=S0[0]:
        x+=-hq.heappop(S1)
        y+=1
    else:
        s0=-hq.heappop(S0)
        x+=s0
        hq.heappush(C,s0)
ans=x+y**2

for i in range(min(len(S1),len(C))):
    c=hq.heappop(C)
    s1=-hq.heappop(S1)
    x+=s1-c
    y+=1
    ans=max(x+y**2,ans)
print(ans)
Problem p02687 (python)

Fixed submission:
s=input()
if(s=="ABC"):
    print("ARC")
else:
    print("ABC")

Buggy submission (verdict: Runtime Error):
s=input()
if(s="ABC"):
    print("ARC")
else:
    print("ABC")

Buggy submission (verdict: Runtime Error):
s=inpput()
if(s="ABC"):
    print("ARC")
else:
    print("ABC")
Problem p02756 (python)

Fixed submission:
s=list(input())
q=int(input())
start=[]
owari=[]
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            start.append(data[2])
        else:
            owari.append(data[2])
    else:
        if(r==1):
            owari.append(data[2])
        else:
            start.append(data[2])

if(r==1):
    start.reverse()
    print(''.join(start),end='')
    print(''.join(s),end='')
    print(''.join(owari),end='')
else:
    owari.reverse()
    s.reverse()
    print(''.join(owari),end='')
    print(''.join(s),end='')
    print(''.join(start),end='')

Buggy submission (verdict: Runtime Error):
s=list(input())
q=int(input())
start=[]
owari=[]
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            start.append(data[2])
        else:
            owari.append(data[2])
    else:
        if(r==1):
            owari.append(data[2])
        else:
            start.append(data[2])
    print(start,owari,r)

if(r==1):
    start.reverse()
    print(''.join(start),end='')
    print(''.join(s),end='')
    print(''.join(owari),end='')
else:
    owari.reverse()
    s.reverse()
    print(''.join(owari),end='')
    print(''.join(s),end='')
    print(''.join(start),end='')