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

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

boxes = [[] for i in range(N)]
impossible = False
for idx,num in enumerate(ls):
    if num>=N:
        impossible=True
        break
    boxes[num].append(idx)

check_start=-1
ans = 1

if impossible:
    ans = 0
elif len(boxes[0])==0:
    ans = 0
elif boxes[0][0]!=0:
    ans = 0
elif len(boxes[0])>=2:
    ans = 0
else:
    for i in range(N-1):
        a = len(boxes[i])
        b = len(boxes[i+1])
        if a == 0:
            check_start = i
            rest_ls = boxes[i:]
            if rest_ls.count([])!=len(rest_ls):
                ans = 0
            break
        ans*=a**b
baisu = ans//998244353
print(ans-(998244353*baisu))

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

boxes = [[] for i in range(N)]
impossible = False
for idx,num in enumerate(ls):
    if num>=N:
        impossible=True
        break
    boxes[num].append(idx)

check_start=-1
ans = 1

if impossible:
    ans = 0
elif boxes[0][0]!=0:
    ans = 0
elif len(boxes[0])>=2:
    ans = 0
else:
    for i in range(N-1):
        a = len(boxes[i])
        b = len(boxes[i+1])
        if a == 0:
            check_start = i
            rest_ls = boxes[i:]
            if rest_ls.count([])!=len(rest_ls):
                ans = 0
            break
        ans*=a**b
baisu = ans//998244353
print(ans-(998244353*baisu))
Problem p02921 (python)

Fixed submission:
a=list(input())
b=list(input())

ans=0
for i in range(3):
    if a[i]==b[i]:ans+=1

print(ans)

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

Fixed submission:
import copy

n,m=map(int,input().split())
D=list(map(int,input().split(" ")))
answer=-99999999999
for i in range(m+1):
    take=i
    trash=m-i
    #print("take",take,"trash",trash)
    for j in range(take+1):
        if take>=n:
            #print("A")
            goukei=copy.copy(D)
        else:
            left=j
            right=j-take
            leftjewel=D[:left]
            rightjewel=D[right:]
            if right==0:
                rightjewel=[]
            
            #print("left",left,"right",right,"j",j,"take",take,"trash",trash)
            #print(leftjewel,rightjewel)
            goukei=leftjewel+rightjewel
        goukei.sort()
        for i in range(trash):
            if goukei!=[]:
                if goukei[0]<0:
                    del goukei[0]
        #print("最終",sum(goukei))
        if sum(goukei)>answer:
            #print("更新")
            answer=sum(goukei)
print(answer)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
D=list(map(int,input().split(" ")))
answer=-99999999999
 
for i in range(m+1):
    take=i
    trash=m-i
    for j in range(take+1):
        if j>=n:
            goukei=D
        else:
            left=j
            right=j-take
            leftjewel=D[:left]
            rightjewel=D[right:]
            if right==0:
                rightjewel=[]
            goukei=leftjewel+rightjewel
        goukei.sort()
        for i in range(trash):
            if goukei!=[]:
                if goukei[0]<0:
                    del goukei[0]
        if sum(goukei)>answer:
            answer=sum(goukei)
print(answer)
n,m=map(int,input().split())
D=list(map(int,input().split(" ")))
answer=-99999999999

for i in range(m+1):
    take=i
    trash=m-i
    for j in range(take+1):
        if j>=n:
            goukei=D
        else:
            left=j
            right=j-take
            leftjewel=D[:left]
            rightjewel=D[right:]
            if right==0:
                rightjewel=[]
            if left-right>n:
              	rightjewel=D[n-right+1:]
            goukei=leftjewel+rightjewel
        goukei.sort()
        for i in range(trash):
            if goukei!=[]:
                if goukei[0]<0:
                    del goukei[0]
        if sum(goukei)>answer:
            answer=sum(goukei)
print(answer)
提出情報
提出日時
Problem p02616 (python)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
mod = 10**9 + 7
A1 = []  
A2 = []
for i in range(N):
    if A[i] > 0:
        A1.append(A[i])
    if A[i] < 0:
        A2.append(-A[i])
A1.sort(reverse=True)
A2.sort(reverse=True)
ans = 1
if max(A)< 0:
    if K%2 == 0:
        for i in range(K):
            ans = (ans * A2[i])%mod
    else:
        A2.sort()
        for i in range(K):
            ans = (ans * A2[i])%mod
            ans = (mod - ans)%mod
elif max(A) == 0:
    if K%2 == 1:
        ans = 0
    else:
        if len(A2) >= K:
            for i in range(K):
                ans = (ans * A2[i])%mod
        else:
            ans = 0
else:
    A3 = []
    for i in range(len(A2)//2):
        A3.append(A2[2 * i] * A2[2 * i + 1])
    A4 = []
    A5 = []
    for i in range(len(A1)//2):
        A4.append(A1[2 * i] * A1[2 * i + 1])
    for i in range((len(A1) - 1)//2):
        A5.append(A1[2 * i + 1] * A1[2 * i + 2])
    if len(A1) + 2 * len(A3) < K:
        if N == K:
            for i in range(N):
                ans = (ans * A[i])%mod
        else:
            ans = 0
    else:
        if K%2 == 0:
            A6 = A3 + A4
            A6.sort(reverse=True)
            for i in range(K//2):
                ans = (ans * A6[i])%mod
        else:
            A6 = A3 + A5
            A6.sort(reverse=True)
            ans = A1[0]
            for i in range((K - 1)//2):
                ans = (ans * A6[i])% mod
print(ans)

Buggy submission (verdict: Runtime Error):
A = list(map(int,input().split()))
mod = 10**9 + 7
A1 = []  
A2 = []
for i in range(N):
    if A[i] > 0:
        A1.append(A[i])
    if A[i] < 0:
        A2.append(-A[i])
A1.sort(reverse=True)
A2.sort(reverse=True)
ans = 1
if max(A)< 0:
    if K%2 == 0:
        for i in range(K):
            ans = (ans * A2[i])%mod
    else:
        A2.sort()
        for i in range(K):
            ans = (ans * A2[i])%mod
            ans = (mod - ans)%mod
elif max(A) == 0:
    if K%2 == 1:
        ans = 0
    else:
        if len(A2) >= K:
            for i in range(K):
                ans = (ans * A2[i])%mod
        else:
            ans = 0
else:
    A3 = []
    for i in range(len(A2)//2):
        A3.append(A2[2 * i] * A2[2 * i + 1])
    A4 = []
    A5 = []
    for i in range(len(A1)//2):
        A4.append(A1[2 * i] * A1[2 * i + 1])
    for i in range((len(A1) - 1)//2):
        A5.append(A1[2 * i + 1] * A1[2 * i + 2])
    if len(A1) + 2 * len(A3) < K:
        if N == K:
            for i in range(N):
                ans = (ans * A[i])%mod
        else:
            ans = 0
    else:
        if K%2 == 0:
            A6 = A3 + A4
            A6.sort(reverse=True)
            for i in range(K//2):
                ans = (ans * A6[i])%mod
        else:
            A6 = A3 + A5
            A6.sort(reverse=True)
            ans = A1[0]
            for i in range((K - 1)//2):
                ans = (ans * A6[i])% mod
print(ans)
Problem p02665 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
k = sum(A)
###syuutenの個数
c = 1  
###考えている列の〇の個数(次の列につながる個数)
aa = 1
ans = 1
if A[0] != 0:
    aa = 2
    if N != 0:
        print(-1)
    else:
        if A[0] == 1:
            print(1)
        else:
            print(-1)
else:
    for i in range(1,N + 1):
        c *= 2
        ##次の列につながる個数の最大値
        if A[i] > c:
            ###A[i]はここが終点になるということ。終点の方が多いことは認められない
            aa = 0
            break
        elif A[i] == c:
            ###終点と同数だとこれより下には繋がらない。もし最下段でなければアウト
            if i != N:
                aa = 0
                break
            else:
                ans += c
        else:
            c -= A[i]
            k -= A[i]
            ans += A[i]
            ###終点の個数を引く。ここで終点の個数だけansを足す
            if c >= k:
                ###次の列につながる個数はこれよりしたにある終点の個数を超えれない
                c = k
            ans += c
            ###この段で下につながる個数を足す

if aa == 0:
    print(-1)
elif aa == 1:
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
k = sum(A)　###syuutenの個数
c = 1  ###考えている列の〇の個数(次の列につながる個数)
aa = 1
ans = 1
if A[0] != 0:
    print(-1)
else:
    for i in range(1,N + 1):
        c *= 2 ##次の列につながる個数の最大値
        if A[i] > c:
            ###A[i]はここが終点になるということ。終点の方が多いことは認められない
            aa = 0
            break
        elif A[i] == c:
            ###終点と同数だとこれより下には繋がらない。もし最下段でなければアウト
            if i != N:
                aa = 0
                break
            else:
                ans += c
        else:
            c -= A[i]
            k -= A[i]
            ans += A[i]
            ###終点の個数を引く。ここで終点の個数だけansを足す
            if c >= k:
                ###次の列につながる個数はこれよりしたにある終点の個数を超えれない
                c = k
            ans += c
            ###この段で下につながる個数を足す

if aa == 0:
    print(-1)
else:
    print(ans)
Problem p02691 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
C = [0]*N
for i in range(N):
    B[i] = i + 1 - A[i]
    C[i] = i + 1 + A[i]
for i in range(N):
    if B[i] < 0:
        B[i] = 200001
    if C[i] > N:
        C[i] = 200001
K = [0]*200002
L = [0]*200002
for i in B:
    K[i] += 1
for i in C:
    L[i] += 1
M = [0]*200001
for i in range(200001):
    M[i] = K[i]*L[i]
print(sum(M))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
C = [0]*N
for i in range(N):
    B[i] = i + 1 - A[i]
    C[i] = i + 1 + A[i]
K = [0]*200001
L = [0]*200001
for i in B:
    K[i] += 1
for i in C:
    L[i] += 1
M = [0]*200001
for i in range(200001):
    M[i] = K[i]*L[i]
print(sum(M))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
C = [0]*N
for i in range(N):
    B[i] = i + 1 - A[i]
    C[i] = i + 1 + A[i]
B.sort()
C.sort()
K = [1]*300000
for i in B:
    K[i] *= 2
for i in C:
    K[i] *= 5
ans = 0
for i in K:
    p = 0
    q = 0
    if i%10 == 0:
        while i%2 == 0:
            i = i//2
            p += 1
        while i != 1:
            i = i//5
            q += 1
        ans += p*q
print(ans)
Problem p02760 (python)

Fixed submission:
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
b = [0] * N 
for i in range(N):
    b[i] = int(input())
A = [A1,A2,A3]
B = [[0]*3,[0]*3,[0]*3]
for i in range(3):
    for j in range(3):
        for k in range(N):
            if A[i][j] == b[k]:
                B[i][j] = 1
if B[0] == [1,1,1]:
    print("Yes")
elif B[1] == [1,1,1]:
    print("Yes")
elif B[2] == [1,1,1]:
    print("Yes")
elif B[0][0] == 1 and B[1][0] == 1 and B[2][0] == 1:
    print("Yes")
elif B[0][1] == 1 and B[1][1] == 1 and B[2][1] == 1:
    print("Yes")
elif B[0][2] == 1 and B[1][2] == 1 and B[2][2] == 1:
    print("Yes")
elif B[0][0] == 1 and B[1][1] == 1 and B[2][2] == 1:
    print("Yes")
elif B[0][2] == 1 and B[1][1] == 1 and B[2][0] == 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
b = [0] * N 
for i in range(N):
    b[i] = int(input())
A = [A1,A2,A3]
B = [[0]*3,[0]*3,[0]*3]
for i in range(3):
    for j in range(3):
        for k in range(N):
            if A[i][j] == b[k]:
                B[i][j] = 1
if B[0] == [1,1,1]:
    print("Yes")
elif B[1] == [1,1,1]:
    print("Yes")
elif B[2] == [1,1,1]:
    print("Yes")
elif B[0][0] == 1 and B[1][0] == 1 and B[2][0] == 1:
    print("Yes")
elif B[0][1] == 1 and B[1][1] == 1 and B[2][1] == 1:
    print("Yes")
elif B[0][2] == 1 and B[1][2] == 1 and B[2][2] == 1:
    print("Yes")
elif B[0][0] == 1 and B[1][1] == 1 and B[2][2] == 1:
    print("Yes")
elif B[0][2] == 1 and B[1][1] == 1 and B[2][0] == 1:
    print("Yes")
else:
    print("No"
Problem p02791 (python)

Fixed submission:
s = [(input().split()) for i in range(2)]
N = int(s[0][0])
t = s[1]
a = 1000000
b = 1
for i in range(N - 1):
    a = min(a,int(t[i]))
    c = int(t[i + 1])
    if a >= c:
        b = b + 1
print(b)

Buggy submission (verdict: Runtime Error):
s = [(input()) for i in range(2)]
N = int(s[0])
t = s[1]
a = 1000000
b = 1
for i in range(N - 1):
    a = min(a,int(t[i]))
    k = i + 1
    c = int(t[k])
    if a >= c:
        b = b + 1
print(b)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = [int(input()) for i in range(N)]
a = 10000000000
b = 1
for i in range(N - 1):
    a = min(a,s[i])
    if a >= s[i + 1]:
        b = b + 1
print(b)
Problem p03160 (python)

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(N - 2):
    dp[i + 2] = min(dp[i] + abs(h[i] - h[i + 2]),dp[i + 1] + abs(h[i + 1] - h[i + 2]))
print(dp[N - 1])

Buggy submission (verdict: Runtime Error):
def flog1(n):
    if A[n] != 0:
        return A[n]
    if n == 0:
        a = 0
    elif n == 1:
        a = abs(h[0] - h[1])
    else:
        a = min(flog1(n - 1) + abs(h[n - 1] - h[n]),flog1(n -2) + abs(h[n - 2] - h[n]))
    A[n] = a
    return a

N = int(input())
h = list(map(int,input().split()))
A = [0] * N
print(flog1(N - 1))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
def flog1(n):
    if A[n] != 0:
        return A[n]
    if n == 0:
        a = 0
    elif n == 1:
        a = abs(h[0] - h[1])
    else:
        a = min(flog1(n - 1) + abs(h[n - 1] - h[n]),flog1(n -2) + abs(h[n - 2] - h[n]))
    A[n] = a
    return a

N = int(input())
h = list(map(int,input().split()))
A = [0] * N
print(flog1(N - 1))
Problem p03192 (python)

Fixed submission:
n = input()
print(n.count('2'))

Buggy submission (verdict: Runtime Error):
n,h,w = map(int,input().split())
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    if a>=h and w<=b:
        ans+=1
print(ans)
Problem p03408 (python)

Fixed submission:
red = []
blue = []
ans = 0
n = int(input())
for _ in range(n):
    red.append(input())
m = int(input())
for _ in range(m):
    blue.append(input())
for word in set(red):
    if word in blue:
        tmp = red.count(word) - blue.count(word)
    else:
        tmp = red.count(word)
    if tmp > ans:
        ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
red = []
blue = []
ans = 0
n = int(input())
for _ in range(n):
    red.append(input())
m = int(input())
for _ in range(n):
    blue.append(input())
for word in set(red):
    if word in blue:
        tmp = red.count(word) - blue.count(word)
    else:
        tmp = red.count(word)
    if tmp > ans:
        ans = tmp
print(ans)
Problem p03418 (python)

Fixed submission:
n,k=map(int,input().split())
if k==0:
    print(n**2)
    exit()
c=0
for b in range(1,n+1):
    c+=max(b-k,0)*(n//b)
    c+=max(n%b-k+1,0)
print(c)

Buggy submission (verdict: Runtime Error):
    data = input()
    data = data.split(" ")
    n = int(data[0])
    k = int(data[1])
    sum = 0
    for b in range(1, n+1):
        sum += (n//b*max(0,b-k)+max(0,n%b-k+1))
    if k == 0: sum-=n
    print(sum)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
if k==0:
    print(n**2)
    exit()
c=0
for b in range(1:n+1):
    c+=max(b-k,0)*(n//b)
    c+=max(n%b-k+1,0)
print(c)
Problem p03548 (python)

Fixed submission:
x,y,z = list(map(int,input().split()))
x-=z
ans = x//(y+z)
print(ans)

Buggy submission (verdict: Runtime Error):
x,y,z = list(map(int,input().split()))
ans = x//(y+z)
num = x%(y+z)
if num => y:
    ans+=1
print(ans)
Problem p03564 (python)

Fixed submission:
n = int(input())
k = int(input())
num=1
for i in range(n):
    if  num>k:
        num+=k
    else:
        num*=2
print(num)

Buggy submission (verdict: Runtime Error):
n,k = list(map(int,input().split()))
num=1
for i in range(n):
    if  num>k:
        num+=k
    else:
        num*=2
print(num)
Problem p02690 (python)

Fixed submission:
x = int(input())

ans = 0
for a in range(-200, 200):
    for b in range(-200, 200):
        if a**5 - b**5 == x:
            ans = [a, b]
            break
    if ans != 0:
        break
print(ans[0], ans[1])

Buggy submission (verdict: Runtime Error):
def calc(a, b):
    return a**4+a**3*b+a**2*b**2+a*b**3+b**4

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

x = int(input())
div = make_divisors(x)
ans = 0
for yakusu in div:
    num = x // yakusu
    left = 0
    right = int(num**0.25) + 1
    while left+1 < right:
        mid = (left+right) // 2
        a, b = mid, mid-yakusu
        result = calc(a, b)
        if abs(result) > num:
            right = mid
        else:
            left = mid
    if abs(calc(right, right-yakusu)) == num:
        ans = (right, right-yakusu)
        break
    if abs(calc(left, left-yakusu)) == num:
        ans = (left, left-yakusu)
        break

if ans[0]**5 - ans[1]**5 > 0:
    print(ans[0], ans[1])
else:
    print(ans[1], ans[0])
Problem p02720 (python)

Fixed submission:
k = int(input())

def hantei(n):
    string = str(n)
    length = len(string)
    ret = True
    for i in range(length-1):
        if abs(int(string[i]) - int(string[i+1])) > 1:
            ret = False
            break
    return ret

lst = [i for i in range(10)]
dic = {}
dic[1] = lst.copy()
keta = 2
while len(lst) < k+1:
    new = []
    for i in range(1, 10):
        tasu = i*(10**(keta-1))
        for j in sorted(dic.keys()):
            temp_lst = dic[j]
            bit = 0
            for youso in temp_lst:
                num = tasu + youso
                if hantei(num):
                    new.append(num)
                    bit = 1
                elif bit == 1:
                    break
    dic[keta] = new.copy()
    lst.extend(new)
    keta += 1

print(lst[k])

Buggy submission (verdict: Runtime Error):
k = int(input())

def hantei(n):
    string = str(n)
    length = len(string)
    ret = True
    for i in range(length-1):
        if abs(int(string[i]) - int(string[i+1])) > 1:
            ret = False
            break
    return ret

lst = [i for i in range(10)]
dic = {}
dic[1] = lst.copy()
keta = 2
while len(lst) < k+1:
    new = []
    for i in range(1, 10):
        tasu = i*(10**(keta-1))
        for j in sorted(dic.keys()):
            temp_lst = dic[j]
            bit = 0
            for youso in temp_lst:
                num = tasu + youso
                if hantei(num):
                    new.append(num)
                    bit = 1
                elif bit == 1:
                    break
    dic[keta] = new.copy()
    lst.extend(new)
    keta += 1

print(lst[k])
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()

ans = 0
while x != 0 or y != 0:
    if r != []:
        if x > 0 and y > 0:
            maxi = max(p[-1], q[-1], r[-1])
            if maxi == p[-1]:
                ans += p.pop()
                x -= 1
            elif maxi == q[-1]:
                ans += q.pop()
                y -= 1
            else:
                ans += r.pop()
                if p[-x] > q[-y]:
                    y -= 1
                else:
                    x -= 1
        elif x == 0:
            maxi = max(q[-1], r[-1])
            if maxi == q[-1]:
                ans += q.pop()
                y -= 1
            else:
                ans += r.pop()
                y -= 1
        else:
            maxi = max(p[-1], r[-1])
            if maxi == p[-1]:
                ans += p.pop()
                x -= 1
            else:
                ans += r.pop()
                x -= 1
    else:
        if x > 0 and y > 0:
            maxi = max(p[-1], q[-1])
            if maxi == p[-1]:
                ans += p.pop()
                x -= 1
            elif maxi == q[-1]:
                ans += q.pop()
                y -= 1
        elif x == 0:
            ans += q.pop()
            y -= 1
        else:
            ans += p.pop()
            x -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()

ans = 0
for i in range(x):
    if p[-1] >= r[-1]:
        ans += p.pop()
    else:
        ans += r.pop()

for i in range(y):
    if q[-1] >= r[-1]:
        ans += q.pop()
    else:
        ans += r.pop()

print(ans)
Problem p02788 (python)

Fixed submission:
n, d, a = map(int, input().split())
lst = []
for i in range(n):
    xi, hi = map(int, input().split())
    if hi % a == 0:
        hi = hi // a
    else:
        hi = hi // a + 1
    lst.append([xi, hi])
lst.sort(key=lambda x: x[0])
x, h = [], []
for i in range(n):
    x.append(lst[i][0])
    h.append(lst[i][1])

x.append(10**11)
h.append(0)

# 攻撃に巻き込めるインデックスを求める
left = 0 # 可能
right = n # 不可能
while left+1 < right:
    mid = (left + right) // 2
    if x[mid] - x[0] <= 2*d:
        left = mid
    else:
        right = mid
makikomi = [left]
right = left
for i in range(1, n):
    while x[right] - x[i] <= 2*d:
        right += 1
    right -= 1
    makikomi.append(right)

cnt = [0 for i in range(n)]
left = 0
already = 0
for i in range(n):
    while x[makikomi[left]] < x[i]:
        already -= cnt[left]
        left += 1
    cnt[i] = max(h[i] - already, 0)
    already += cnt[i]

print(sum(cnt))

Buggy submission (verdict: Runtime Error):
n, d, a = map(int, input().split())
lst = []
for i in range(n):
    xi, hi = map(int, input().split())
    if hi % a == 0:
        hi = hi // a
    else:
        hi = hi // a + 1
    lst.append([xi, hi])
lst.sort(key=lambda x: x[0])
x, h = [], []
for i in range(n):
    x.append(lst[i][0])
    h.append(lst[i][1])

x.append(10**11)
h.append(0)

kougeki_start = 0
kougeki_end = 0
cnt = 0
i = 0
while i <= n:
    if h[i] > 0:
        left = i # 可能
        right = n # 不可能
        while left+1 < right:
            mid = (left + right) // 2
            if x[mid] - x[i] <= 2*d:
                left = mid
            else:
                right = mid
        cnt += h[i]
        hiku = h[i]
        bit = 0
        for j in range(i, left+1):
            h[j] -= hiku
            if bit == 0 and h[j] > 0:
                next_i = j
                bit = 1
        i = next_i

print(cnt)
Problem p02802 (python)

Fixed submission:
n, m = map(int, input().split())
p, s = [], []
for i in range(m):
    pi, si = input().split()
    p.append(int(pi))
    s.append(si)

lst_ac = [0 for i in range(n+1)]
for i in range(m):
    if s[i] == 'AC':
        lst_ac[p[i]] = 1
ans_ac = sum(lst_ac)

out = 0
for i in range(m):
    if s[i] == 'WA' and lst_ac[p[i]] == 1:
        out += 1
    if s[i] == 'AC' and lst_ac[p[i]] == 1:
        lst_ac[p[i]] = 2

print(ans_ac, out)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
p, s = [], []
for i in range(n):
    pi, si = input().split()
    p.append(int(pi))
    s.append(si)

lst_ac = [0 for i in range(n+1)]
for i in range(n):
    if s[i] == 'AC':
        lst_ac[p[i]] = 1
ans_ac = sum(lst_ac)

out = 0
for i in range(n):
    if s[i] == 'WA' and lst_ac[p[i]] == 1:
        out += 1

print(ans_ac, out)