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

Fixed submission:
import bisect as bi

a,b,q=map(int,input().split())

INF=10**15

S=[-INF]+[int(input()) for i in range(a)]+[INF]
T=[-INF]+[int(input()) for i in range(b)]+[INF]
X=[int(input()) for i in range(q)]

for i in range(q):
    d=bi.bisect_right(S,X[i])
    e=bi.bisect_right(T,X[i])
    as0=abs(X[i]-S[d-1])
    as1=abs(X[i]-S[d])
    at0=abs(X[i]-T[e-1])
    at1=abs(X[i]-T[e])
    ans=min(max(as0,at0),max(as1,at1),2*as0+at1,as0+2*at1,2*at0+as1,at0+as1*2)
    print(ans)

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

a,b,q=map(int,input().split())

ST=[]
for i in range(a):
    k=int(input())
    ST.append([k,0,0])
for i in range(b):
    k=int(input())
    ST.append([k,1,0])

ST.sort()

le0=-1
le1=-1
ri0=1
ri1=1

for i in range(a+b):
    if ST[i][1]==0 :
        pa=1
        
        moyori=np.inf

        if le1>=0:
            moyori=min(moyori,abs(ST[i][0]-ST[le1][0]))
        if ri1<=i :
            ri1=i+1
            while ri1<=a+b-1 and ST[ri1][1]==ty :
                ri1+=1
        if ri1<=a+b-1:
            moyori=min(moyori,abs(ST[i][0]-ST[ri1][0]))
        ST[i][2]=moyori
        le0=i
    else:
        pa=0
        
        moyori=np.inf

        if le0>=0:
            moyori=min(moyori,abs(ST[i][0]-ST[le0][0]))
        if ri0<=i :
            ri0=i+1
            while ri0<=a+b-1 and ST[ri0][1]==ty :
                ri0+=1
        if ri0<=a+b-1:
            moyori=min(moyori,abs(ST[i][0]-ST[ri0][0]))
        ST[i][2]=moyori
        le1=i



#print(ST)

for i in range(q):
    k=int(input())
    ST.append([k,2,0,i])

ST.sort()

ANS=[]
le0=-1
le1=-1
ri0=1
ri1=1
for i in range(a+b+q):
    if ST[i][1]==0 :
        le0=i
    elif ST[i][1]==1 :
        le1=i
    elif ST[i][1]==2 :
        moyori=np.inf
    
            
        if le0>=0:
            moyori=min(moyori,abs(ST[i][0]-ST[le0][0])+ST[le0][2])
            #print("L"+str(le[typ]))
            #print(moyori)
        if ri0<=i :
            ri0=i+1
            while ri0<=a+b+q-1 and (ST[ri0][1]==1 or ST[ri0][1]==2):
                ri0+=1
        if ri0<=a+b+q-1 :
            moyori=min(moyori,abs(ST[i][0]-ST[ri0][0])+ST[ri0][2])
            #print("R"+str(ri[typ]))
            #print(moyori)

        if le1>=0:
            moyori=min(moyori,abs(ST[i][0]-ST[le1][0])+ST[le1][2])
            #print("L"+str(le[typ]))
            #print(moyori)
        if ri1<=i :
            ri1=i+1
            while ri1<=a+b+q-1 and (ST[ri1][1]==0 or ST[ri1][1]==2):
                ri1+=1
        if ri1<=a+b+q-1 :
            moyori=min(moyori,abs(ST[i][0]-ST[ri1][0])+ST[ri1][2])
            #print("R"+str(ri[typ]))
            #print(moyori)



        ST[i][2]=moyori
        ANS.append([ST[i][3],moyori])

ANS.sort()

#print(ST)

for i in range(q):
    print(ANS[i][1])
Problem p03132 (python)

Fixed submission:
L=int(input())
A=[int(input()) for i in range(L)]
su=sum(A)
#print(A)

DP=[[0 for i in range(5)] for j in range(L+1)]

mod=A[0]%2
if A[0]==0 :
    mod=2
DP[1]=[A[0],min(A[0],mod%2),min(A[0],mod%2,(mod+1)%2),min(A[0],mod%2,(mod+1)%2),min(A[0],mod%2,(mod+1)%2)]

for i in range(2,L+1):
    mod=A[i-1]%2
    if A[i-1]==0 :
        mod=2
    DP[i][0]+=DP[i-1][0]+A[i-1]
    DP[i][1]+=min(DP[i-1][0],DP[i-1][1])+mod
    DP[i][2]+=min(DP[i-1][j] for j in range(3))+(mod+1)%2
    DP[i][3]+=min(DP[i-1][j] for j in range(4))+mod
    DP[i][4]+=min(DP[i-1][j] for j in range(5))+A[i-1]

#print(DP)
print(min(DP[L]))

Buggy submission (verdict: Runtime Error):
L=int(input())
A=[int(input()) for i in range(L)]
su=sum(A)
#print(A)

DP=[[0 for i in range(5)] for j in range(L)]

mod=A[0]%2
if A[0]==0 :
    mod=2
DP[1]=[A[0],min(A[0],mod%2),min(A[0],mod%2,(mod+1)%2),min(A[0],mod%2,(mod+1)%2),min(A[0],mod%2,(mod+1)%2)]

for i in range(2,L):
    mod=A[i]%2
    if A[i]==0 :
        mod=2
    DP[i][0]+=DP[i-1][0]+A[i]
    DP[i][1]+=min(DP[i-1][0],DP[i-1][1])+mod
    DP[i][2]+=min(DP[i-1][j] for j in range(3))+(mod+1)%2
    DP[i][3]+=min(DP[i-1][j] for j in range(4))+mod
    DP[i][4]+=min(DP[i-1][j] for j in range(5))+A[i]

#print(DP)
print(min(DP[L-1]))

Buggy submission (verdict: Runtime Error):
L=int(input())
A=[int(input()) for i in range(L)]
su=sum(A)
#print(A)

DP=[[0 for i in range(5)] for j in range(L)]

DP[1]=[A[0],min(A[0],A[0]%2),min(A[0],A[0]%2,(A[0]+1)%2),min(A[0],A[0]%2,(A[0]+1)%2),min(A[0],A[0]%2,(A[0]+1)%2)]

for i in range(2,L):
    mod=A[i]%2
    if A[i]==0 :
        mod=2
    DP[i][0]+=DP[i-1][0]+A[i]
    DP[i][1]+=min(DP[i-1][0],DP[i-1][1])+mod
    DP[i][2]+=min(DP[i-1][j] for j in range(3))+(mod+1)%2
    DP[i][3]+=min(DP[i-1][j] for j in range(4))+mod
    DP[i][4]+=min(DP[i-1][j] for j in range(5))+A[i]

#print(DP)
print(min(DP[L-1]))
Problem p03238 (python)

Fixed submission:
n=int(input())

 
if n==1 :
    print("Hello World")
else :
    a=input()
    b=input()
    print(int(a)+int(b))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=input()
b=input()

if n==1 :
    print("Hello World")
else :
    print(int(a)+int(b))
Problem p03244 (python)

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

A = [[0] * (10**5+1) for i in range(2)]

for i in range(n):
    A[i%2][V[i]] += 1

C = [[0] * (10**5+1) for i in range(2)]  # A[0][:i], A[1][:i]の最大値
for i in range(1, len(C[0])):
    C[0][i] = max(C[0][i-1], A[0][i])
    C[1][i] = max(C[1][i-1], A[1][i])

# print(A[0][:150])
# print(A[1][:150])
# print(C[:150])

ans = 0
for i in range(1, len(C[0])):
    ans = max(ans, C[1][i-1] + A[0][i])
    ans = max(ans, C[0][i-1] + A[1][i])

print(n - ans)

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

A=[[0,i] for i in range(10**5)]
B=[[0,i] for i in range(10**5)]

for i in range(0,n,2):
    A[V[i]][0]+=1
for i in range(1,n,2):
    B[V[i]][0]+=1

A.sort(reverse=1)
B.sort(reverse=1)

#print(A[:10])
#print(B[:10])

Ma=[]
Mb=[]

ma=A[0][0]
mb=B[0][0]
i=0
j=0
while A[i][0]==ma :
    Ma.append(A[i][1])
    i+=1

while B[j][0]==mb :
    Mb.append(B[j][1])
    j+=1

if Ma==Mb :
    print(min(n-ma-B[j][0],n-mb-A[i][0]))
else :
    print(n-ma-mb)
Problem p03263 (python)

Fixed submission:
h,w=map(int,input().split())

A=[]
for i in range(h):
    A.append(list(map(int,input().split())))

if h==1 and w==1 :
    print(0)
else:


    aa=0
    C=[]
    ha=0
    s=1
    a=0
    b=0
    for i in range(h*w):
        if A[a][b]%2==1 :
            ha=(ha+1)%2
        if ha==1:
            if b+s<w and b+s>=0 :
                C.append([a,b,a,b+s])
            elif a<h :
                C.append([a,b,a+1,b])
        if ha==0 :
            aa=len(C)

        if b+s<w and b+s>=0 :
            b+=s
        else:
            a+=1
            s = -s

            
    print(aa)

    for i in range(aa):
        print(str(C[i][0]+1)+" "+str(C[i][1]+1)+" "+str(C[i][2]+1)+" "+str(C[i][3]+1))

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

A=[]
for i in range(h):
    A.append(list(map(int,input().split())))

C=[]
ha=0
s=1
a=0
b=0
for i in range(h*w):
    if A[a][b]%2==1 :
        ha=(ha+1)%2
    if ha==1:
        if b+s<w and b+s>=0 :
            C.append([a,b,a,b+s])
        elif a<h :
            C.append([a,b,a+1,b])
    if ha==0 :
        aa=len(C)

    if b+s<w and b+s>=0 :
        b+=s
    else:
        a+=1
        s = -s

        
print(aa)

for i in range(aa):
    print(str(C[i][0]+1)+" "+str(C[i][1]+1)+" "+str(C[i][2]+1)+" "+str(C[i][3]+1))

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

A=[]
for i in range(h):
    A.append(list(map(int,input().split())))

C=[]
ha=0
s=1
a=0
b=0
for i in range(h*w):
    if A[a][b]%2==1 :
        ha=(ha+1)%2
    if ha==1:
        if b+s<w and b+s>=0 :
            C.append([a,b,a,b+s])
        elif a<h :
            C.append([a,b,a+1,b])
    if ha==0 :
        aa=len(C)

    if b+s<w and b+s>=0 :
        b+=s
    else:
        a+=1
        s = -s

        
print(aa)

for i in range(aa):
    print(str(C[i][0]+1)+" "+str(C[i][1]+1)+" "+str(C[i][2]+1)+" "+str(C[i][3]+1))
Problem p03296 (python)

Fixed submission:
a=int(input())
N=[0 for i in range(a)]
b=input()
#print(b)
N=b.split()
for i in range(a):
  N[i]=int(N[i])

#print(N)
  
a2ans=0
a2ans2=0
for i in range(a-1):
  if N[i]==N[i+1]:
    a2ans2+=1
    #print(a2ans2)
  else :
    if a2ans2%2==1 :
      a2ans2+=1
    
    a2ans+=a2ans2/2
    a2ans2=0


if a2ans2%2==1 :
  a2ans2+=1
#print(a2ans2)
a2ans+=a2ans2/2
a2ans2=0



print(int(a2ans))

Buggy submission (verdict: Runtime Error):
a=int(input())
N=[0 for i in range(a)]
b=input()
for i in range(a):
  N[i]=int(b.aplit())

2ans=0
2ans2=0
for i in range(a-1):
  if N[i]==N[i+1]:
    2ans2+=1
  else :
    if 2ans2%2==1 :
      2ans2+=1
    ans+=2ans2/2
    2ans2=0
return 2ans
Problem p03354 (python)

Fixed submission:
n, m = map(int, input().split())
P = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(m)]

for i in range(n):
    P[i] -= 1
for i in range(m):
    for j in range(2):
        X[i][j] -= 1

M = [[] for i in range(n)]

for i in range(m):
    M[X[i][0]].append(X[i][1])
    M[X[i][1]].append(X[i][0])

G = [0] * n
clr = 0

for i in range(n):
    if G[i] == 0 and len(M[i]) > 0:
        clr += 1
        G[i] = clr
        
        Q = M[i][:]
        st = 0
        while st < len(Q):
            if G[Q[st]] == 0:
                G[Q[st]] = clr
                for item in M[Q[st]]:
                    Q.append(item)

            st += 1

# print(G)

ans = 0
for i in range(n):
    if G[i] == 0 and i == P[i]:
        ans += 1

G2 = [[[], []] for i in range(clr+1)]

for i in range(n):
    G2[G[i]][0].append(i)
    G2[G[i]][1].append(P[i])
# print(G2)
# print(ans)

for i in range(1, clr+1):
    ans += len(G2[i][0]) * 2 - len(set(G2[i][0] + G2[i][1]))

print(ans)

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



import networkx as nx

G = nx.Graph()

for i in range(n):
    G.add_node(i+1)
    
#print(G.nodes())

for i in range(m):
    G.add_edge(X[i][0],X[i][1])
    G[X[i][0]][X[i][1]]["capacity"] = 1.0

#print(G.edges())

#print(nx.maximum_flow(G, 1, 2)[0])



#print(G.successors(1))

co=0
for i in range(n):
    #print(nx.maximum_flow(G, i+1, P[i])[0])
    if i+1==P[i] or nx.maximum_flow(G, i+1, P[i])[0]==1.0:
        co+=1
    #elif nx.maximum_flow(G, i+1, P[i])[0]==1.0 :
    #    co+=1
print(co)
Problem p03372 (python)

Fixed submission:
n, c = map(int, input().split())
XR = [list(map(int,input().split())) for i in range(n)]
XL = [[c-XR[i][0], XR[i][1]] for i in range(n)]
XL.sort()

CR = []
cal = 0
for i in range(n):
    dis = XR[i][0]
    cal += XR[i][1]
    CR.append([cal-dis, dis])


CSR = [CR[0][0]]
for i in range(n-1):
    CSR.append(max(CSR[i], CR[i+1][0]))

CL = []
cal = 0
for i in range(n):
    dis = XL[i][0]
    cal += XL[i][1]
    CL.append([cal-dis, dis])


CSL = [CL[0][0]]
for i in range(n-1):
    CSL.append(max(CSL[i], CL[i+1][0]))


# print(CSR)
# print(CSL)
# print(CR)
# print(CL)

ans = max(max(CSR), max(CSL))
for i in range(n-1):
    # print(CL[i][0]-CL[i][1]+CSR[n-2-i], CL[i][0],CL[i][1],CSR[n-2-i])
    ans = max(ans, CL[i][0]-CL[i][1]+CSR[n-2-i])
    ans = max(ans, CR[i][0]-CR[i][1]+CSL[n-2-i])

print(max(ans, 0))

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

ans=0

B1=[] #時計回り、引き返さない
su=0
for i in range(n):
    su+=A[i][1]
    B1.append(su-A[i][0])

#print(B1)

ans=max(ans,max(B1))

B2=[] #反時計回り、引き返さない
su=0
for i in range(n-1,-1,-1):
    su+=A[i][1]
    B2.append(su-(c-A[i][0]))

#print(B2)


ans=max(ans,max(B2))


B3=[] #時計回り、引き返す(半周以上周ってから引き返してはいけない)
B4=[] #反時計回り、引き返す（同上）

for i in range(n):
    if A[i][0]<=(c-0.1)//2 :
        B3.append(B1[i]-A[i][0])

#print(B3)

for i in range(n-1,-1,-1):
    j=0
    if (c-A[i][0])<=(c-0.1)//2 :
        B4.append(B2[j]-(c-A[i][0]))
    j+=1

#print(B4)

if len(B3)>0 :
    aa=B3.index(max(B3))
    #print(max(B3)+max(B2[:n-aa-1]))
    ans=max(ans,max(B3)+max(B2[:n-aa-1]))
if len(B4)>0 :
    bb=B4.index(max(B4))
    #print(max(B4)+max(B1[:n-bb-1]))
    ans=max(ans,max(B4)+max(B1[:n-bb-1]))

print(ans)
Problem p03477 (python)

Fixed submission:
a, b, c, d = map(int,input().split())
A = ["Left", "Balanced", "Right"]
print(A[int((c+d) > (a+b)) - int((a+b) > (c+d)) + 1])

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int,input().split())
A = ["Left", "Balanced", "Right"]
print(A[(c+d) // (a+b) - (a+b) // (c+d) + 1])
Problem p03535 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
D = list(map(int,input().split()))
# from random import randint

# n = randint(1, 50)
# D = [randint(0, 12) for i in range(n)]

C = [0] * 13
C[0] = 1
for i in range(n):
    C[D[i]] += 1

if C[0] >= 2 or C[12] >=2:
    print(0)
    sys.exit()

for i in range(13):
    if C[i] >= 3:
        print(0)
        sys.exit()

# D = []
# for i in range(13):
#     for j in range(C[i]):
#         D.append(i)
# n = len(D)
# A = [0] * n

# print(C)
ans0 = 0
for i in range(2**13):
    zero = 0
    ib = format(i, "b").zfill(13)
    A = []
    for j in range(13):
        if C[j] == 1:
            A.append(j * (-1) ** int(ib[j]))
        if C[j] == 2:
            if int(ib[j]) == 0:
                A.append(j)
                A.append(-j)
            else:
                zero = 1
    if zero == 1:
        continue
    # print("not cont")
    ans = 30
    # if len(A)>1:
        # print(A)
    # print(ib, A)
    for j in range(len(A)):
        for k in range(j+1, len(A)):
            di = abs(A[k] - A[j])
            # print(ans)
            ans = min(ans, min(di, 24-di))
            if ans <= ans0:
                break
        if ans <= ans0:
            break
    # print(ib, ans0,ans)
    ans0 = max(ans0, ans)
print(ans0)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
D = list(map(int,input().split()))

C = [0] * 13
C[0] = 1
for i in range(n):
    C[D[i]] += 1

if C[0] >= 2 or C[12] >=2:
    print(0)
    sys.exit()

for i in range(n):
    if C[i] >= 3:
        print(0)
        sys.exit()

D = []
for i in range(13):
    for j in range(C[i]):
        D.append(i)
n = len(D)
A = [0] * n
ans0 = 0
for i in range(2**n):
    ib = format(i, "b").zfill(n)
    for j in range(n):
        A[j] = D[j] * (-1) ** int(ib[j])
    ans = 30
    for j in range(n):
        for k in range(j+1, n):
            di = abs(A[k] - A[j])
            # print(ans)
            ans = min(ans, min(di, 24-di))
    # print(ib, ans0,ans)
    ans0 = max(ans0, ans)
print(ans0)
Problem p03624 (python)

Fixed submission:
import string
s = input()

s = sorted(set(s))
moji = [chr(i) for i in range(ord('a'), ord('z')+1)]
# print(s)
# print(moji)

def b():
    for i in range(len(moji)):
        if i > len(s)-1 or moji[i] != s[i]:
            return moji[i]
    return "None"

print(b())

Buggy submission (verdict: Runtime Error):
import string
s = input()

s = sorted(set(s))
moji = [chr(i) for i in range(ord('a'), ord('z')+1)]
# print(s)
# print(moji)

def b():
    for i in range(len(moji)):
        if moji[i] != s[i]:
            return moji[i]
    return "None"

print(b())
Problem p03633 (python)

Fixed submission:
from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    if ans % T[i] != 0:
        ans = ans * T[i] / gcd(ans, T[i])
    #ans = int(ans + 0.1)
    #print(ans)
print(int(ans))

Buggy submission (verdict: Runtime Error):
from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    ans = ans * T[i] / gcd(ans, T[i])
    #ans = int(ans + 0.1)
print(int(ans))

Buggy submission (verdict: Runtime Error):
from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    ans = ans * T[i] / gcd(ans, T[i])
    #ans = int(ans + 0.1)
print(ans)

Buggy submission (verdict: Runtime Error):
from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    ans = Decimal(ans * T[i] / Decimal(gcd(ans, T[i])))
    #ans = int(ans + 0.1)
print(Decimal(ans))

Buggy submission (verdict: Runtime Error):
from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    ans = Decimal(ans * T[i] / gcd(ans, T[i]))
    #ans = int(ans + 0.1)
print(Decimal(ans))

Buggy submission (verdict: Runtime Error):
from decimal import *

n = int(input())
T = [int(input()) for i in range(n)]

for i in range(n):
    T[i] = Decimal(T[i])

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = Decimal(1)
for i in range(n):
    ans = ans * T[i] / gcd(ans, T[i])
    #ans = int(ans + 0.1)
print(int(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
T = [int(input()) for i in range(n)]

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return max(x, y)

ans = 1
for i in range(n):
    ans = ans * T[i] / gcd(ans, T[i])
    ans = int(ans + 0.1)
print(int(ans))
Problem p03657 (python)

Fixed submission:

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

if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):

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

if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0:
    print("Possible")
else:
    print("Impossible")
Problem p03786 (python)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 1
m = A[0]
for i in range(n-1):
    if A[i+1] <= 2*m:
        ans += 1
    else:
        ans = 1
    m += A[i+1]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
m = max(A)
B = [0] * (m+1)
for i in range(n):
    B[A[i]] += 1
for i in range(1, m+1):
    B[i] = B[i-1] + B[i] * i

# print(B)

ans = 0
for i in range(n):
    ma = -1
    mm = A[i]
    while mm <= m and ma != mm:
        ma = mm
        mm = B[mm]
    if mm > m:
        ans += 1
print(ans)
Problem p03808 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
B = []
for i in range(n):
    B.append(A[i] - A[i-1])

m = max(B)
no = 0

if m < 0:
    no = 1
elif m == 0:
    if A[0] % (n*(n+1)//2) > 0:
        no = 1
else:
    c = 0
    for i in range(n):
        if (m - B[i]) % n > 0:
            no = 1
        else:
            c += (m - B[i]) // n

    if c != m:
        no = 1
    if sum(A) != m * n*(n+1)//2:
        no = 1

if no==1:
    print("NO")
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
3
6 6 6
Problem p03912 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
Y = list(map(int,input().split()))

l = max(Y) + 1
X = [0] * l
for i in range(n):
    X[Y[i]] += 1

# print(X)
U = [[0] * m for i in range(2)]

for i in range(l):
    a = X[i] // 2
    U[0][i % m] += a

A = [0] * m
for i in range(l):
    A[i % m] += X[i]
# print(A)

for i in range(1, m//2 + 1):
    a = min(A[i], A[m-i])
    U[1][i] += a
    U[1][m-i] += a

U[1][0] = A[0]

# print(U)

ans = 0
for i in range(m):
    ans += min((A[i]-U[1][i]) // 2, U[0][i]) * 2 + U[1][i]

print(ans // 2)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
Y = list(map(int,input().split()))

l = max(Y) + 1
X = [0] * l
for i in range(n):
    X[Y[i]] += 1

# print(X)
U = [[0] * m for i in range(2)]

for i in range(l):
    a = X[i] // 2
    U[0][i % m] += a

A = [0] * m
for i in range(l):
    A[i % m] += X[i]
# print(A)

for i in range(1, m//2 + 1):
    a = min(A[i], A[m-i-1])
    U[1][i] += a
    U[1][m-i-1] += a

U[1][i] = A[0]

# print(U)

ans = 0
for i in range(m):
    ans += min((A[i]-U[1][i]) // 2, U[0][i]) * 2 + U[1][i]

print(ans)
Problem p04032 (python)

Fixed submission:
s = input()
n = len(s)
s += "0"
def d():
    for i in range(n-1):
        if s[i] == s[i+1]:
            return str(i+1) + " " + str(i+2)
        elif s[i] == s[i+2]:
            return str(i+1) + " " + str(i+3)
    return "-1 -1"
print(d())

Buggy submission (verdict: Runtime Error):
s = input() + "0"
def d():
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            return str(i+1) + " " + str(i+2)
        elif i <= len(s)-2 and s[i] == s[i+2]:
            return str(i+1) + " " + str(i+3)
    return "-1 -1"
print(d())
Problem p02536 (python)

Fixed submission:
import sys
sys.setrecursionlimit(int(2e6))

def dfs(u, p = 0):
  vis[u] = True
  for v in g[u]:
    if not vis[v]:
      dfs(v, u)

n, m = map(int, input().split())
assert 2 <= n <= int(1e5)
assert 1 <= m <= int(1e5)
g = [list() for i in range(n + 1)]
for i in range(m):
  u, v = map(int, input().split())
  assert 1 <= u <= int(1e5)
  assert 1 <= v <= int(1e5)
  assert u < v
  g[u].append(v)
  g[v].append(u)
c = 0
vis = [False] * (n + 1)
for i in range(1, n + 1):
  if not vis[i]:
    c += 1
    dfs(i)
print(c - 1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(int(2e6))

def dfs(u, p = 0):
  vis[u] = True
  for v in g[u]:
    if v != p:
      dfs(v, u)

n, m = map(int, input().split())
g = [list() for i in range(n + 1)]
for i in range(m):
  u, v = map(int, input().split())
  g[u].append(v)
  g[v].append(u)
c = 0
vis = [False] * (n + 1)
for i in range(1, n + 1):
  if not vis[i]:
    c += 1
    dfs(i)
print(c - 1 if c else 0)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(int(2e6))

def dfs(u, p = 0):
  for v in g[u]:
    if v != p:
      dfs(v, u)
  g[u] = None

n, m = map(int, input().split())
g = [list() for i in range(n + 1)]
for i in range(m):
  u, v = map(int, input().split())
  g[u].append(v)
  g[v].append(u)
c = 0
for i in range(1, n + 1):
  if g[i] is not None:
    c += 1
    dfs(i)
print(c - 1 if c else 0)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(int(1e6))

def dfs(u, p = 0):
  for v in g[u]:
    if v != p:
      dfs(v, u)
  g[u] = None


n, m = map(int, input().split())
g = [list() for i in range(n + 1)]
for i in range(m):
  u, v = map(int, input().split())
  g[u].append(v)
  g[v].append(u)
c = 0
for i in range(1, n + 1):
  if g[i] is not None:
    c += 1
    dfs(i)
print(c - 1 if c else 0)
Problem p02830 (python)

Fixed submission:
n=int(input())
s,t=input().split()
i=0
while i<n:
    print(s[i]+t[i],end="")
    i+=1

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
i=0
while i<n:
    print(s[i]+t[i],end="")
    i+=1
Problem p02969 (python)

Fixed submission:
r=int(input())
ans=r*r*3
print(ans)

Buggy submission (verdict: Runtime Error):
print(r*r*3)