Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def solve():
    N, M = map(int, input().split())
    WAnum = 0
    ACnum = 0
    WA = [0]*max(N, M)
    AC = [False]*max(N, M)

    if N==0:
        print(0, 0)
        exit()

    for _ in range(M):
        p, S = map(str, input().split())
        p = int(p)
        if AC[p]:
            continue
        if S == 'AC':
            AC[p] = True
            ACnum += 1
            WAnum += WA[p]
        elif S == 'WA':
            WA[p] += 1
        #print(AC, WA)
    #print(AC,WA)
    print(ACnum, WAnum)

solve()

Fixed submission:
def solve():
    N, M = map(int, input().split())
    WAnum = 0
    ACnum = 0
    WA = [0]*(N+1)
    AC = [False]*(N+1)

    for _ in range(M):
        p, S = map(str, input().split())
        p = int(p)
        if AC[p] == True:
            continue
        if S == 'AC':
            AC[p] = True
            ACnum += 1
            WAnum += WA[p]
        elif S == 'WA':
            WA[p] += 1
        #print(AC, WA)
    #print(AC,WA)
    print(ACnum, WAnum)

solve()

Buggy python submission (verdict: Runtime Error):
def solve():
    N, M = map(int, input().split())
    WAnum = 0
    ACnum = 0
    WA = [0]*max(N, M)
    AC = [False]*max(N, M)

    for _ in range(M):
        p, S = map(str, input().split())
        p = int(p)
        if AC[p]:
            continue
        if S == 'AC':
            AC[p] = True
            ACnum += 1
            WAnum += WA[p]
        elif S == 'WA':
            WA[p] += 1
        #print(AC, WA)
    #print(AC,WA)
    print(ACnum, WAnum)

solve()

Fixed submission:
def solve():
    N, M = map(int, input().split())
    WAnum = 0
    ACnum = 0
    WA = [0]*(N+1)
    AC = [False]*(N+1)

    for _ in range(M):
        p, S = map(str, input().split())
        p = int(p)
        if AC[p] == True:
            continue
        if S == 'AC':
            AC[p] = True
            ACnum += 1
            WAnum += WA[p]
        elif S == 'WA':
            WA[p] += 1
        #print(AC, WA)
    #print(AC,WA)
    print(ACnum, WAnum)

solve()

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


li = []

for i in range(m):
    p,q = map(str, input().split())
    li.append((int(p),q))

wa = 0

se = {i for i in li if i[1]=='AC'}
ac = len(se)

flag = True
for i in range(m-1):
    if li[i][0]!=li[i+1][0]:
        flag = True
    elif li[i][0]==li[i+1][0] and li[i][1]=='AC':
        flag = False
    elif li[i][0]==li[i+1][0] and li[i][1]=='WA' and flag:
        wa += 1
    elif li[len(li)-1]==li[len(li-2)] and li[i][1]=='WA' and flag:
        wa += 1

print(ac, wa)

Fixed submission:
def solve():
    N, M = map(int, input().split())
    WAnum = 0
    ACnum = 0
    WA = [0]*(N+1)
    AC = [False]*(N+1)

    for _ in range(M):
        p, S = map(str, input().split())
        p = int(p)
        if AC[p] == True:
            continue
        if S == 'AC':
            AC[p] = True
            ACnum += 1
            WAnum += WA[p]
        elif S == 'WA':
            WA[p] += 1
        #print(AC, WA)
    #print(AC,WA)
    print(ACnum, WAnum)

solve()
Buggy python submission (verdict: Runtime Error):
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

r = list(itertools.permutations(range(1,n+1)))
r.sort()

for i in range(len(r)):
    if r[i] == p:
        a = i+1
    elif r[i] == q:
        b = i+1

print(abs(a-b))

Fixed submission:
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

r = list(itertools.permutations(range(1,n+1)))

print(abs(r.index(p)-r.index(q)))
Buggy python submission (verdict: Runtime Error):
import math
def lcm(a,b):
    return (a*b) // math.gcd(a,b)

A, B = map(int, input().split())
C = lcm(A,B)
print(C)

Fixed submission:
from fractions import gcd

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

A, B = map(int, input().split())
C = lcm(A,B)
print(C)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = list(input())

ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    t_index = 0
    for s_index in range(N):
        if s[s_index] == t[t_index]:
            t_index += 1
            if t_index == 3:
                break
    if t_index == 3:
        ans += 1
print(ans)

Fixed submission:
from collections import defaultdict
n = int(input())
S = input()

d1 = defaultdict(int)
d2 = defaultdict(int)
d3 = defaultdict(int)

for s in S:
    for x in d2:
        d3[x+s]+=1
    for y in d1:
        d2[y+s]+=1
    d1[s]+=1

print(len(d3))

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input())

tb = [False]*10**2
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            l = int(''.join(S[i]+S[j]+S[k]))
            tb[l] = True
print(tb.count(True))

Fixed submission:
from collections import defaultdict
n = int(input())
S = input()

d1 = defaultdict(int)
d2 = defaultdict(int)
d3 = defaultdict(int)

for s in S:
    for x in d2:
        d3[x+s]+=1
    for y in d1:
        d2[y+s]+=1
    d1[s]+=1

print(len(d3))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

tb = [False]*10**5
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            l = int(''.join(S[i]+S[j]+S[k]))
            tb[l] = True
print(tb.count(True))

Fixed submission:
from collections import defaultdict
n = int(input())
S = input()

d1 = defaultdict(int)
d2 = defaultdict(int)
d3 = defaultdict(int)

for s in S:
    for x in d2:
        d3[x+s]+=1
    for y in d1:
        d2[y+s]+=1
    d1[s]+=1

print(len(d3))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

tb = [False]*10**5
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            l = int(''.join(S[i]+S[j]+S[k]))
            tb[l] = True
print(tb.count(True))

Fixed submission:
from collections import defaultdict
n = int(input())
S = input()

d1 = defaultdict(int)
d2 = defaultdict(int)
d3 = defaultdict(int)

for s in S:
    for x in d2:
        d3[x+s]+=1
    for y in d1:
        d2[y+s]+=1
    d1[s]+=1

print(len(d3))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
S = list(input())
se = set(itertools.combinations(S,3))
print(len(se))


Fixed submission:
from collections import defaultdict
n = int(input())
S = input()

d1 = defaultdict(int)
d2 = defaultdict(int)
d3 = defaultdict(int)

for s in S:
    for x in d2:
        d3[x+s]+=1
    for y in d1:
        d2[y+s]+=1
    d1[s]+=1

print(len(d3))
Buggy python submission (verdict: Runtime Error):
import string
import numpy as np
N = int(input())
S = list(input())
A2Z = string.ascii_uppercase

str_index = np.full(len(S), 0)
mod26 = np.full(len(S), 26)
#print(str_index)

for i in range(len(S)):
    str_index[i] = A2Z.index(S[i])
str_index = (str_index+N) % mod26
#print(str_index)

tmp = ['']*len(S)
for i in range(len(S)):
    tmp[i] = A2Z[str_index[i]]
answer = ''.join(tmp)
print(answer)

Fixed submission:
import string
import numpy as np
N = int(input())
S = list(input())
A2Z = string.ascii_uppercase

str_index = np.full(len(S), 0)
mod_26 = np.full(len(S), 26)
#print(str_index)

for i in range(len(S)):
    str_index[i] = A2Z.index(S[i])
str_index = (str_index+N) % mod_26
#print(str_index)

tmp = ['']*len(S)
for i in range(len(S)):
    index = int(str_index[i])
    tmp[i] = A2Z[index]
answer = ''.join(tmp)
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

L = [0]*N
for i in range(1,N+1):
    L[i-1] = A.index(i)+1
print(*L)

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

L = [0]*N
for i in range(N):
    L[A[i]-1] = i+1
print(*L)
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
A = [int(input())-1 for _ in range(Q)]
Point = [K]*N
for i in range(Q):
    Point[A[i]] += 1
    for j in range(N):
        Point[j] -= 1

for p in Point:
    if p>0:
        print('Yes')
    else:
        print('No')

Fixed submission:
N, K, Q = map(int, input().split())
A = [int(input())-1 for _ in range(Q)]
Point = [K-Q]*N
for i in range(Q):
    Point[A[i]] += 1

for p in Point:
    if p>0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
total=0
l = list(range(2,n+1)) + [1]
for i in range(n):
  total+=(i+1)%l[i]
print(total)


Fixed submission:
n=int(input())
#total=0
#l = list(range(2,n+1)) + [1]
#for i in range(n):
#    total+=(i+1)%l[i]
#print(total)
# 1+2+3+...+n-1
print(n*(n-1)//2)

Buggy python submission (verdict: Runtime Error):
n=int(input())
total=0
l = list(range(2,n+1)) + [1]
for i in range(n):
  total+=(i+1)%l[i]
print(total)

Fixed submission:
n=int(input())
#total=0
#l = list(range(2,n+1)) + [1]
#for i in range(n):
#    total+=(i+1)%l[i]
#print(total)
# 1+2+3+...+n-1
print(n*(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
t = set(s)

def tousa(n):
    return n*(n-1)//2

ans = 0
for t_i in t:
    ans += tousa(s.count(t_i))
print(ans)

Fixed submission:
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for _ in range(N):
    d[''.join(sorted(input()))] += 1

def tousa(n):
    return n*(n-1)//2

ans = 0
for i in d.values():
    ans += tousa(i)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [sorted(input()) for _ in range(N)]
for i in range(N):
    s[i] = ''.join(s[i])
s.sort()
t = set(s)

def tousa(n):
    return n*(n-1)//2

ans = 0
for t_i in t:
    ans += tousa(s.count(t_i))
print(ans)

Fixed submission:
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for _ in range(N):
    d[''.join(sorted(input()))] += 1

def tousa(n):
    return n*(n-1)//2

ans = 0
for i in d.values():
    ans += tousa(i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
H = list(map(int, input().split()))

fl = True
for i in range(1,N):
    if H[i]-H[i-1]<0:
        H[i-1] -= 1
        tmp = np.array(H[i:])
        if all(x-1<H[i-1] for x in tmp):
            fl = False
            break
print('Yes') if fl else print('No')

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

fl = True
for i in range(1,N):
    if H[i]-H[i-1]>0:
        H[i] -= 1

for i in range(1,N):
    if H[i]-H[i-1]<0:
        fl = False
        break

print('Yes') if fl else print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))

fl = True
check = []
cnt = 0
while True:
    tmp = len(check)
    for i in range(1,N):
        if H[i]-H[i-1]<0 and not i-1 in check:
            H[i-1] -= 1
            check.append(i-1)
    if cnt==3:
        break
    cnt += 1

for i in range(1,N):
    if H[i]-H[i-1]<0:
        fl = False
        break

print('Yes') if fl else print('No')

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

fl = True
for i in range(1,N):
    if H[i]-H[i-1]>0:
        H[i] -= 1

for i in range(1,N):
    if H[i]-H[i-1]<0:
        fl = False
        break

print('Yes') if fl else print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))

fl = True
check = []
while True:
    tmp = len(check)
    for i in range(1,N):
        if H[i]-H[i-1]<0 and not i-1 in check:
            H[i-1] -= 1
            check.append(i-1)
    if len(check)==tmp:
        break

for i in range(1,N):
    if H[i]-H[i-1]<0:
        fl = False
        break

print('Yes') if fl else print('No')


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

fl = True
for i in range(1,N):
    if H[i]-H[i-1]>0:
        H[i] -= 1

for i in range(1,N):
    if H[i]-H[i-1]<0:
        fl = False
        break

print('Yes') if fl else print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)

for a in A:
    if a==max(A):
        print(B[-2])
    else:
        print(B[-1])

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A)
M0 = B[-1]
M1 = B[-2]

for a in A:
    if a==M0:
        print(M1)
    else:
        print(M0)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 2019
L, R = map(int, input().split())

ans = float('inf')
for i in range(L,R):
    if i%MOD==0:
        print(0)
        exit()
    for j in range(i+1,R+1):
        if i%MOD==0:
            print(0)
            exit()
        ans = min(ans,(i*j)%MOD)
print(ans)


Fixed submission:
MOD = 2019
L, R = map(int, input().split())

if R - L > 2019:
    print(0)
    exit()

ans = float('inf')
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%MOD)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 2019
L, R = map(int, input().split())

ans = float('inf')
for i in range(L,R):
    if i%MOD==0:
        print(0)
        exit()
    for j in range(i+1,R+1):
        if i%MOD==0:
            print(0)
            exit()
        ans = min(ans,(i*j)%MOD)
print(ans)

Fixed submission:
MOD = 2019
L, R = map(int, input().split())

if R - L > 2019:
    print(0)
    exit()

ans = float('inf')
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%MOD)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 2019
L, R = map(int, input().split())

ans = float('inf')
for i in range(L,R):
    for j in range(i+1,R+1):
        if i%MOD==0 or j%MOD==0:
            ans = min(ans,(i*j)%MOD)
            break
        ans = min(ans,(i*j)%MOD)
print(ans)

Fixed submission:
MOD = 2019
L, R = map(int, input().split())

if R - L > 2019:
    print(0)
    exit()

ans = float('inf')
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%MOD)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 2019
L, R = map(int, input().split())

ans = float('inf')
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%MOD)
        if ans == 0:
            break
print(ans)

Fixed submission:
MOD = 2019
L, R = map(int, input().split())

if R - L > 2019:
    print(0)
    exit()

ans = float('inf')
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%MOD)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
d = list(map(int, input().split()))
d.sort()

s, t = N//2-1, N//2

cnt = 0
for i in range(d[s],d[t]+1):
    tmp = [x>=i for x in d]
    if tmp.count(True)==tmp.count(False):
        cnt += 1
print(cnt)

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

s, t = N//2-1, N//2

ans = d[t] - d[s]
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
d = np.array(list(map(int, input().split())))
d.sort()

s, t = N//2-1, N//2

cnt = 0
for i in range(d[s],d[t+1]):
    if np.count_nonzero(d>=i)==t:
        cnt += 1
print(cnt)

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

s, t = N//2-1, N//2

ans = d[t] - d[s]
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
l = list(map(int, input().split()))
d = 0
answer = 0
for i in range(N+1):
    if d <= X:
        answer += 1
        d += l[i]
    else:
        break
print(answer)

Fixed submission:
import itertools
N, X = map(int, input().split())
l = list(map(int, input().split()))
l.insert(0,0)
l_acc = list(itertools.accumulate(l))
answer = [x for x in l_acc if x<=X]
print(len(answer))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S, P = ['0']*N, [0]*N
SP = []
for i in range(N):
    tmp_s, tmp_p = map(str, input().split())
    S[i], P[i] = tmp_s, tmp_p
    SP.append((tmp_s,int(tmp_p)))

# 点数で逆順ソート
SSP = sorted(SP, key=itemgetter(1), reverse=True)
# 名前で昇順ソート
SSP = sorted(SSP, key=itemgetter(0))

answer = [0]*N
for i in range(N):
    for j in range(N):
        if SSP[i] == SP[j]:
            answer[i] = j+1

for i in answer:
    print(i)

Fixed submission:
from operator import itemgetter

# input
N = int(input())
S, P = ['0']*N, [0]*N
SP = []
for i in range(N):
    tmp_s, tmp_p = map(str, input().split())
    S[i], P[i] = tmp_s, tmp_p
    SP.append((tmp_s,int(tmp_p)))

# 点数で逆順ソート
SSP = sorted(SP, key=itemgetter(1), reverse=True)
# 名前で昇順ソート
SSP = sorted(SSP, key=itemgetter(0))

answer = [0]*N
for i in range(N):
    for j in range(N):
        if SSP[i] == SP[j]:
            answer[i] = j+1

for i in answer:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
L, R = [0]*M, [0]*M
for i in range(M):
    L[i],R[i] = map(int, input().split())

cnt = 0
LR = zip(L,R)
res = set(range(1,N+1))
for l,r in LR:
    res &= set(range(l,r+1))
print(len(res))

Fixed submission:
N, M = map(int, input().split())
L, R = [0]*M, [0]*M
for i in range(M):
    L[i],R[i] = map(int, input().split())

a, b = max(L), min(R)
if a<=b:
    print(b-a+1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import fractions

# 最大公約数
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def gcd_list(nums):
    return functools.reduce(gcd, nums)

N = int(input())
A = list(map(int, input().split()))

left = [0]
right = []
for i in range(N):
    tmp_left = A[:i+1]
    tmp_right = A[i:]
    left.append(gcd_list(tmp_left))
    right.append(gcd_list(tmp_right))
right += [0]
#print(left)
#print(right)

ans = 0
for i in range(N):
    ans = max(ans,fractions.gcd(left[i],right[i+1]))
print(ans)

Fixed submission:
import fractions

N = int(input())
A = list(map(int, input().split()))

left = [0]*(N+1)
right = [0]*(N+1)
for i in range(N):
    left[i+1] = (fractions.gcd(left[i],A[i]))
    right[N-i-1] = fractions.gcd(right[N-i],A[N-1-i])

ans = 0
for i in range(N):
    ans = max(ans,fractions.gcd(left[i],right[i+1]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import functools

# 最大公約数
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def gcd_list(nums):
    return functools.reduce(gcd, nums)

N = int(input())
A = list(map(int, input().split()))

# i番目を取り去る
ans = 0
for i in range(N):
    tmp_left = A[:i]
    tmp_right = A[i+1:]
    tmp_lr = tmp_left + tmp_right
    tmp = gcd_list(tmp_lr)
    ans = max(ans,tmp)
print(ans)

Fixed submission:
import fractions

N = int(input())
A = list(map(int, input().split()))

left = [0]*(N+1)
right = [0]*(N+1)
for i in range(N):
    left[i+1] = (fractions.gcd(left[i],A[i]))
    right[N-i-1] = fractions.gcd(right[N-i],A[N-1-i])

ans = 0
for i in range(N):
    ans = max(ans,fractions.gcd(left[i],right[i+1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

R = [0]*(N+1)
for i in range(1,N+1):
    if S[i-1]=='A' and S[i]=='C':
        R[i] = R[i-1]+1
    else:
        R[i] = R[i-1]

for i,j in lr:
    print(R[j] - R[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

R = [0]*(N+1)
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        R[i] = R[i-1]+1
    else:
        R[i] = R[i-1]

for i,j in lr:
    print(R[j] - R[i])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

for i,j in lr:
    tmp_S = S[i:j+1]
    cnt = tmp_S.count('AC')
    print(cnt)

Fixed submission:
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

R = [0]*(N+1)
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        R[i] = R[i-1]+1
    else:
        R[i] = R[i-1]

for i,j in lr:
    print(R[j] - R[i])

Buggy python submission (verdict: Time Limit Exceeded):
import re
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

for i,j in lr:
    tmp_S = S[i:j+1]
    cnt = len(re.findall('AC',tmp_S))
    print(cnt)

Fixed submission:
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

R = [0]*(N+1)
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        R[i] = R[i-1]+1
    else:
        R[i] = R[i-1]

for i,j in lr:
    print(R[j] - R[i])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
be = len(S)

while True:
    tmp_S = S
    S = S.replace('01','').replace('10','').replace('01','').replace('10','')
    if tmp_S==S:
        break
af = len(S)
print(be-af)

Fixed submission:
s = input()

one = s.count('1')
zero = s.count('0')

print(2*min(one,zero))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
be = len(S)

while True:
    tmp_S = S
    for i in range(1,len(S)):
        if (S[i-1]=='0' and S[i]=='1') or (S[i-1]=='1' and S[i]=='0'):
            S[i-1], S[i] = '', ''
    S = ''.join(S)
    S = list(S)
    if tmp_S==S:
        break
af = len(S)
print(be-af)

Fixed submission:
s = input()

one = s.count('1')
zero = s.count('0')

print(2*min(one,zero))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
be = len(S)

while True:
    tmp_S = S
    for i in range(1,len(S)):
        if (S[i-1]=='0' and S[i]=='1') or (S[i-1]=='1' and S[i]=='0'):
            S[i-1], S[i] = '', ''
    S = ''.join(S)
    S = list(S)
    if tmp_S==S:
        break
af = len(S)
print(be-af)

Fixed submission:
s = input()

one = s.count('1')
zero = s.count('0')

print(2*min(one,zero))
Buggy python submission (verdict: Runtime Error):
import numpy as np
INF = float('inf')
MAX_N = 10**5

N = int(input())
a,b,c = [0]*N, [0]*N, [0]*N
for i in range(N):
    a[i],b[i],c[i] = map(int, input().split())

# dp table
# dp[i][j] := 状態jにおけるi日目に得る幸福度の総和の最大値
dp = np.array([[0]*3 for _ in range(N)])

dp[0][0],dp[0][1],dp[0][2] = a[0],b[0],c[0]

for i in range(1,N):
    for j in range(3):
        if j==0:
            dp[i][j] = max(dp[i-1][j+1]+a[i],dp[i-1][j+2]+a[i])
        if j==1:
            dp[i][j] = max(dp[i-1][j-1]+b[i],dp[i-1][j+1]+b[i])
        if j==2:
            dp[i][j] = max(dp[i-1][j-2]+c[i],dp[i-1][j-1]+c[i])
print(max(dp[N-1]))

Fixed submission:
N = int(input())
a = [[0 for _ in range(3)] for _ in range(N)]
for i in range(N):
    t = list(map(int, input().split()))
    for j in range(3):
        a[i][j] = t[j]

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

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])
#print(dp)


answer = 0
for j in range(3):
    answer = max(answer, dp[N][j])

print(answer)