Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a,k=map(int,input().split())
L=list(map(int,input().split()))
ans=0
 
for i in range(min(k,a)+1):
  for j in range(min(k,a)-i+1):
    S=L[:i]+L[a-j:]
    S.sort()
    x=0
    while x < k-(j+i):
      if S[x]>=0:
        break
      x+=1
    ans=max(ans,sum(S)-sum(S[:x]))
    
print(ans)

Fixed submission:
a,k=map(int,input().split())
L=list(map(int,input().split()))
ans=0
 
for i in range(min(k,a)+1):
  for j in range(min(k,a)-i+1):
    S=[0]+L[:i]+L[a-j:]
    S.sort()
    x=0
    while x < k-(j+i):
      if S[x]>=0:
        break
      x+=1
    ans=max(ans,sum(S)-sum(S[:x]))
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
opt = ['pol', 'por', 'pul', 'pur']
res = []
def helper(res, Q, M, K):
  if K==0:
    res.append(sum(M))
  else:
    if len(Q) > 0:
      # pol
      helper(res, Q[1:], M+[Q[0]], K-1)
      # por
      helper(res, Q[:-1], M+[Q[-1]], K-1)
      if len(M)>0:
        if min(M) < 0:
          # pul
          helper(res, [min(M)]+Q, [i for i in M if i != min(M)], K-1)
          # por
          helper(res, Q+[min(M)], [i for i in M if i != min(M)], K-1)
    helper(res, Q, M, K-1)
helper(res, V, [], K)
print (max(res))
      

Fixed submission:
a,k=map(int,input().split())
L=list(map(int,input().split()))
ans=0
 
for i in range(min(k,a)+1):
  for j in range(min(k,a)-i+1):
    S=[0]+L[:i]+L[a-j:]
    S.sort()
    x=0
    while x < k-(j+i):
      if S[x]>=0:
        break
      x+=1
    ans=max(ans,sum(S)-sum(S[:x]))
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(item) for item in input().split()]
A = [int(item) for item in input().split()]
B = []
C = []
A.sort()
for i in range(M):
  b, c = [int(item) for item in input().split()]
  B.append(b)
  C.append(c)
 
B = [x for y, x in sorted(zip(C, B))]
C = sorted(C)

P = []
for idx in range(len(B)):
  P.extend([C[idx]]*B[idx])
 
res = 0
# print (A)
i = 0
while i < N:
  # print (A[i],P)
  if len(P)>0:
    p = P.pop()
  else:
    p=0
  if A[i] < p:
    res += p
  else:
    res += A[i]
  i+=1
  
print (res)

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1],reverse=True)
for b,c in bc:
    a.extend([c]*b)
    if len(a)>2*n:
        break
a.sort(reverse=True)
print(sum(a[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(item) for item in input().split()]
A = [int(item) for item in input().split()]
B = []
C = []
A.sort()
A.append(0)
for i in range(M):
  b, c = [int(item) for item in input().split()]
  B.append(b)
  C.append(c)

B = [x for y, x in sorted(zip(C, B))][::-1]
C = sorted(C)[::-1]

res = 0
# print (A)
for i in range(M):
  b = B[i]
  c = C[i]
  cnt = 0
  while A[cnt] < c and cnt < len(A)-1:
    cnt += 1
  # print (A, b, c, cnt, res)
  if cnt > b:
    res += c*b+sum(A[cnt:])
    A = A[b:cnt] + [0]
  else:
    res += c*cnt+sum(A[cnt:])
    A = []
  if len(A) == 0:
    break
  
print (res + sum(A))

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1],reverse=True)
for b,c in bc:
    a.extend([c]*b)
    if len(a)>2*n:
        break
a.sort(reverse=True)
print(sum(a[:n]))

Buggy python submission (verdict: Runtime Error):
N, M = [int(item) for item in input().split()]
A = [int(item) for item in input().split()]
A.sort()
for i in range(M):
  B, C = [int(item) for item in input().split()]
  cnt = 0
  while A[cnt] < C and cnt < B:
    A[cnt] = C
    cnt += 1
  A.sort()
print (sum(A))

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1],reverse=True)
for b,c in bc:
    a.extend([c]*b)
    if len(a)>2*n:
        break
a.sort(reverse=True)
print(sum(a[:n]))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[0]*n
ct=0
a=0
b=0
c=0
for i in range(n):
    s[i]=input()
for i in range(n):
    for j in range(len(s[i])):
        t=s[i]
        ts=list(t)
        ts.append(0)
        if ts[j]=='A' and ts[j+1]=='B':
            ct+=1
    if ts[0]=='B' and ts[len(s[i])-1]!='A':
        a+=1
    if ts[len(s[i])-1]=='A' and ts[0]!='B':
        b+=1
    if ts[0]=='B' and ts[len(s[i])-1]=='A':
        c+=1
ct += max(0,c -1)
if c !=0:
  if a > 0 and b >0:
    ct += 2 + min(a-1,b-1)
  elif head>0:
    ct += 1 + min(a-1,b)
  elif last>0:
    ct += 1 + min(a,b-1)
else:
  ct += min(a,b)
print(ct)

Fixed submission:
n=int(input())
s=[0]*n
ct=0
a=0
b=0
c=0
for i in range(n):
    s[i]=input()
for i in range(n):
    for j in range(len(s[i])):
        t=s[i]
        ts=list(t)
        ts.append(0)
        if ts[j]=='A' and ts[j+1]=='B':
            ct+=1
    if ts[0]=='B' and ts[len(s[i])-1]!='A':
        a+=1
    if ts[len(s[i])-1]=='A' and ts[0]!='B':
        b+=1
    if ts[0]=='B' and ts[len(s[i])-1]=='A':
        c+=1
ct += max(0,c -1)
if c !=0:
  if a > 0 and b >0:
    ct += 2 + min(a-1,b-1)
  elif a>0:
    ct += 1 + min(a-1,b)
  elif b>0:
    ct += 1 + min(a,b-1)
else:
  ct += min(a,b)
print(ct)

Buggy python submission (verdict: Runtime Error):
N = int(input())
res = 0
both = 0
h = 0
b = 0
for i in range(N):
  inp = input()
  if 'AB' in inp:
    res += 1
  if 'B'==inp[0] and 'A'==inp[-1]:
    both+=1
  elif 'B'==inp[0]:
    # print (inp)
    h+=1
  elif 'A'==inp[-1]:
    # print (inp)
    b += 1
if max(h,b)>0 or both==0:
    print(res+min(h,b)+both)
elif max(a,b)==0:
    print(res+both-1)

Fixed submission:
n=int(input())
s=[0]*n
ct=0
a=0
b=0
c=0
for i in range(n):
    s[i]=input()
for i in range(n):
    for j in range(len(s[i])):
        t=s[i]
        ts=list(t)
        ts.append(0)
        if ts[j]=='A' and ts[j+1]=='B':
            ct+=1
    if ts[0]=='B' and ts[len(s[i])-1]!='A':
        a+=1
    if ts[len(s[i])-1]=='A' and ts[0]!='B':
        b+=1
    if ts[0]=='B' and ts[len(s[i])-1]=='A':
        c+=1
ct += max(0,c -1)
if c !=0:
  if a > 0 and b >0:
    ct += 2 + min(a-1,b-1)
  elif a>0:
    ct += 1 + min(a-1,b)
  elif b>0:
    ct += 1 + min(a,b-1)
else:
  ct += min(a,b)
print(ct)
Buggy python submission (verdict: Runtime Error):
N, K = [int(i) for i in input().split()]
s = input()
S = [int(s[i]) for i in range(len(s))]

for i in range(K):
    pair = []
    temp = 0
    for i in range(N):
        if i <= N-1:
            if (S[i]==0 and S[i+1]==0):
                temp += 1
            elif(S[i]==0):
                pair.append([i-temp,temp])
                temp = 0
        else:
            if(S[i]==0):
                pair.append([i,temp])
                temp = 0
    max_m = 0
    max_s = []
    for i in range(len(pair)):
        temp = S.copy()
        s, l = pair[i]
        for j in range(l+1):
            temp[s+j]=1
        m = cal_l(temp, N)
        if (m > max_m):
            max_m = m
            max_s = temp.copy()
    S = max_s.copy()
print (max_m)

Fixed submission:
inputs = [int(i) for i in input().split()]
res = 0
res += max(inputs)
max_idx = inputs.index(max(inputs))
inputs[max_idx] -= 1
res += max(inputs)
print (res)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

a = int(stdin.readline().rstrip())

for x in range(1,1000000001):
    if x % 2 == 0  and x % a == 0 :
        print(x)
        break;


Fixed submission:
from sys import stdin

a = int(stdin.readline().rstrip())
if a % 2 == 0:
    print(a)
else:
    x = a * 2
    print(x)
Buggy python submission (verdict: Runtime Error):
head=[int(n) for n in input.readline().split()]
list_x=[int(n) for n in input.readline().split()]
list_x.append(head[2])
list_y=[int(n) for n in input.readline().split()]
if max(list_x) < min(list_y):
    print("No War")
else:
    print("War")

Fixed submission:
head=[int(n) for n in input().split()]
list_x=[int(n) for n in input().split()]
list_x.append(head[2])
list_y=[int(n) for n in input().split()]
list_y.append(head[3])
if max(list_x) < min(list_y):
    print("No War")
else:
    print("War")
Buggy python submission (verdict: Runtime Error):
s=input().strip()
t=input().strip()
s_list=[]
t_list=[]
for char in s:
    s_list.append(char)
for char in t:
    t_list.append(char)
s_collection=collections.Counter(s_list)
t_collection=collections.Counter(t_list)
s_countlist=[]
t_countlist=[]
for entry in s_collection.values():
    s_countlist.append(entry)
for entry in t_collection.values():
    t_countlist.append(entry)
s_countlist.sort()
t_countlist.sort()
if s_countlist == t_countlist:
    print("Yes")
else:
    print("No")

Fixed submission:
import collections
s=input().strip()
t=input().strip()
s_list=[]
t_list=[]
for char in s:
    s_list.append(char)
for char in t:
    t_list.append(char)
s_collection=collections.Counter(s_list)
t_collection=collections.Counter(t_list)
s_countlist=[]
t_countlist=[]
for entry in s_collection.values():
    s_countlist.append(entry)
for entry in t_collection.values():
    t_countlist.append(entry)
s_countlist.sort()
t_countlist.sort()
if s_countlist == t_countlist:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
headData = input().split()
candyTotal = int(headData[1])
childList = [ int(n) for n in input().split()]
childList.sort()
childTotal = sum(childList)

if candyTotal == childTotal:
    print(len(childList))
elif candyTotal == childTotal:
    print(len(childList)-1)
else:
    answer=0
    childSum=0
    for child in childList:
        childSum = childSum + child
        if childSum > candyTotal:
            print(answer)
            exit()
        else:
            answer = answer + 1
print(answer-1)

Fixed submission:
headData = input().split()
candyTotal = int(headData[1])
childList = [ int(n) for n in input().split()]
childList.sort()
childTotal = sum(childList)

if candyTotal == childTotal:
    print(len(childList))
elif candyTotal > childTotal:
    print(len(childList)-1)
else:
    answer=0
    childSum=0
    for child in childList:
        childSum = childSum + child
        if childSum > candyTotal:
            print(answer)
            exit()
        else:
            answer = answer + 1
    print(answer-1)
Buggy python submission (verdict: Runtime Error):
dataNum=input()
wordList=[]
for word in input:
    wordList.append(word.strip())

if len(wordList) != len(set(wordList)):
    print("No")
    exit()

char = wordList[0][-1:]
for n in range(1, len(wordList)):
    if(char != wordList[n][:1]):
        print("No")
        exit()
    char = wordList[n][-1:]

print("Yes")

Fixed submission:
dataNum=int(input())
wordList=[]
for n in range(dataNum):
    wordList.append(input().strip())

if len(wordList) != len(set(wordList)):
    print("No")
    exit()

char = wordList[0][-1:]
for n in range(1, len(wordList)):
    if(char != wordList[n][:1]):
        print("No")
        exit()
    char = wordList[n][-1:]

print("Yes")
Buggy python submission (verdict: Runtime Error):
headData = [int(n) for n in input().split()]
islandNum = headData[0]
requestNum = headData[1]
requestList = []
count = 0
for n in range(requestNum):
    request = [int(elem) for elem in input().split()]
    requestList.append(request)


while (len(requestList) != 0):
    print(count)
    # 優先度チェック
    bridgePriority = islandNum * [0]
    for request in requestList:
        for j in range(request[0], request[1]):
            bridgePriority[j] += 1
    deleteBridgeList = []

    print(max(bridgePriority))
    # 優先度が最も高い橋を特定
    for index in range(len(bridgePriority)):
        if (bridgePriority[index] == max(bridgePriority)):
            deleteBridgeList.append(index)

    print(deleteBridgeList)
    # 橋を削除した場合、叶っていないリクエストリストを作成
    newRequestList = []
    for request in requestList:
        for bridge in deleteBridgeList:
            isUnsolvedBridge = True
            if (request[0]<=bridge and bridge<request[1]):
                isUnsolvedBridge=False
                break
        if isUnsolvedBridge:
            newRequestList.append(request)
    requestList = newRequestList
    print(requestList)
    count += len(deleteBridgeList)

print(count)

Fixed submission:
data = [int(n) for n in input().split()]
print(max(data)-min(data))
Buggy python submission (verdict: Runtime Error):
headerData = input.split()
d = int(headerData[0])
n = headerData[1]
if n == "100":
    n = "101"
answer = n + "00" * d
print(answer)

Fixed submission:
headerData = input().split()
d = int(headerData[0])
n = headerData[1]
if n == "100":
    n = "101"
answer = n + "00" * d
print(answer)
Buggy python submission (verdict: Runtime Error):
    num=int(input())
    a_array=[]
    b_array=[]
    for n in range(2*num):
        elem=[int(n) for n in input().split()]
        if n < num:
            a_array.append(elem)
        else:
            b_array.append(elem)
    a_array.sort(key=lambda x:x[1])
    a_array.reverse()
    b_array.sort(key=lambda x: x[0])
    answer=0
    for b_x, b_y in b_array:
        for a_x, a_y in a_array:
            if b_x > a_x and b_y > a_y:
                answer=answer+1
                a_array.remove([a_x,a_y])
    print(answer)

Fixed submission:
num=int(input())
a_array=[]
b_array=[]
for n in range(2*num):
    elem=[int(n) for n in input().split()]
    if n < num:
        a_array.append(elem)
    else:
        b_array.append(elem)
a_array.sort(key=lambda x:x[1])
a_array.reverse()
b_array.sort(key=lambda x: x[0])
answer=0
for b_x, b_y in b_array:
    for a_x, a_y in a_array:
        if b_x > a_x and b_y > a_y:
            answer=answer+1
            a_array.remove([a_x,a_y])
            break;
print(answer)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()

from heapq import nsmallest

m = int(-(a/2))
s = int(a/2)

n = int(a)
p = list(map(int, b.split()))

m2 = sorted(p)[m]
s2 = nsmallest(s, p)[-1]

print(m2-s2)

Fixed submission:
from heapq import nsmallest

n = int(input())
p = list(map(int, input().split()))

m = int(-(n/2))
s = int(n/2)

m2 = sorted(p)[m]
s2 = nsmallest(s, p)[-1]

print(m2-s2)

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

l = int(n/2)

for i in range(l-1):
    t1 = max(p)
    t2 = min(p)
    #print(t1, t2)
    p.remove(t1)
    p.remove(t2)

print(max(p) - min(p))

Fixed submission:
from heapq import nsmallest

n = int(input())
p = list(map(int, input().split()))

m = int(-(n/2))
s = int(n/2)

m2 = sorted(p)[m]
s2 = nsmallest(s, p)[-1]

print(m2-s2)

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

l = int(a/2)

for i in range(l-1):
    t1 = max(p)
    t2 = min(p)
    #print(t1, t2)
    p.remove(t1)
    p.remove(t2)

print(max(p) - min(p))

Fixed submission:
from heapq import nsmallest

n = int(input())
p = list(map(int, input().split()))

m = int(-(n/2))
s = int(n/2)

m2 = sorted(p)[m]
s2 = nsmallest(s, p)[-1]

print(m2-s2)

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

l = int(a/2)

for i in range(l-1):
    t1 = max(p)
    t2 = min(p)
    #print(t1, t2)
    p.remove(t1)
    p.remove(t2)

print(max(p) - min(p))

Fixed submission:
from heapq import nsmallest

n = int(input())
p = list(map(int, input().split()))

m = int(-(n/2))
s = int(n/2)

m2 = sorted(p)[m]
s2 = nsmallest(s, p)[-1]

print(m2-s2)
Buggy python submission (verdict: Runtime Error):
a=str(nput())
b=''
r='Good'
for c in a:
    if b == c:
        r='Bad'
        break
    else:
        b = c
print(r)

Fixed submission:
a=str(input())
b=''
r='Good'
for c in a:
    if b == c:
        r='Bad'
        break
    else:
        b = c
print(r)
Buggy python submission (verdict: Runtime Error):
a,b=map(int, inout().split())
list = input().split(' ')

s = 0
c = !

for item in list:
    c += 1
    if (s + int(item)) <= b:
        s += int(item)
    else:
        break

print(c)

Fixed submission:
a,b=map(int, input().split())
list = input().split(' ')

s = 0
c = 1

for item in list:
    if (s + int(item)) <= b:
        c += 1
        s += int(item)
    else:
        break

print(c)
Buggy python submission (verdict: Runtime Error):
a,b= input().split("")
if a=="H"and b=="H":
    print("H")
elif a=="H" and b=="D":
    print("D")
elif a=="D" and b=="D":
    print("H")
else:
    print("D")

Fixed submission:
a, b = input().split()
if a == "H"and b == "H":
    print("H")
elif a == "H" and b == "D":
    print("D")
elif a == "D" and b == "D":
    print("H")
else:
    print("D")
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
ab = a+b
bc = b+c
ca = c+a
flg = False
if ab == c:
    flg = True
if bc == a:
    flg = True
if ca == b:
    flg = True

if flg = True:
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c = map(int, input().split())
ab = a+b
bc = b+c
ca = c+a
flg = False
if ab == c:
    flg = True
if bc == a:
    flg = True
if ca == b:
    flg = True

if flg == True:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s = input()
# s = "01B0"
# print(s[0])

ans = []
for key in range(len(s)):

    if s[key] == "0" or s[key] == "1":
        ans.append(s[key])
    if s[key] == "B":
        ans.pop(-1)
print("".join(ans))

Fixed submission:
s = input()
# s = "01B0"
# print(s[0])

ans = []
for key in range(len(s)):

    if s[key] == "0" or s[key] == "1":
        ans.append(s[key])
    if s[key] == "B" and len(ans) > 0:
        ans.pop(-1)
print("".join(ans))
Buggy python submission (verdict: Runtime Error):
N, L = map(int, input().split())
s = []
for i in range(L):
    line = input()
    print(line)
    s.append(line)
s.sort()
print("".join(s))

Fixed submission:
N, L = map(int, input().split())
S = []
for i in range(N):
    line = input()
    S.append(line)
S.sort()
print("".join(S))
Buggy python submission (verdict: Runtime Error):
import pandas as pd

N = int(input())
rest = [list(input().split()) for n in range(N)]

df_rest = pd.DataFrame(rest)
df_rest[1] = df_rest[1].apply(int)
df_rest = df_rest.sort_values([0,1], ascending = [True, False])

for x in df_rest.index:
    print(x + 1)

Fixed submission:
N = int(input())
rest = [list(input().split()) for n in range(N)]

for n in range(N):
    rest[n][1] = int(rest[n][1])
    rest[n].append(n + 1)
    
rest.sort(key = lambda x: x[1], reverse = True)
rest.sort(key=lambda x: x[0], reverse=False)


for n in range(N):
    print(rest[n][2])
Buggy python submission (verdict: Runtime Error):
a = []
for i in range(5):
    a.append(int(input()))
 
b = []
c = []
for j in range(5):
    if a[j] % 10 == 0:
        c.append(10)
        b.append(a[j]-10)
    else:
      　num = a[j]%10
        c.append(num)
        b.append(a[j] - c[j])
        
 
b_sum = sum(b)
c_min = min(c)
c_sum = c_min + 4*10
 
print(b_sum + c_sum)

Fixed submission:
a = []
for i in range(5):
    a.append(int(input()))

b = []
c = []
for j in range(5):
    if a[j] % 10 == 0:
        c.append(10)
        b.append(a[j]-10)
    else:
        c.append(a[j] % 10)
        b.append(a[j] - c[j])
        

b_sum = sum(b)
c_min = min(c)
c_sum = c_min + 4*10

print(b_sum + c_sum)
Buggy python submission (verdict: Runtime Error):
inr = lambda: list(map(int, input().split()))
inn = lambda: input()
 
N,Q = inr()
S = inn()


cou  = 0
cou_list = []
for s in S:
    if s == "C":
        if flag == 1:
            cou += 1
            flag = 0
    elif s == "A":
        flag = 1
    else:
        flag = 0
    cou_list.append(cou)

for q in range(Q):
    l,r = inr()
    bubun = cou_list[r-1] - cou_list[l-1]
    print(bubun)

Fixed submission:
n,q = map(int,input().split())
s = input()
pref = [0]
for i in range(1,n):
  if s[i-1:i+1] == "AC": 
      pref.append(pref[-1]+1)
  else: 
      pref.append(pref[-1])
for i in range(q):
    l,r = map(int,input().split())
    print(pref[r-1]-pref[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
inr = lambda: list(map(int, input().split()))
inn = lambda: input()
 
N,Q = inr()
S = inn()
for q in range(Q):
    l,r = inr()
    bubun = S[l-1:r]
    
    bbb = ""
    for b in bubun:
      if b in ["A","C"]:
        bbb += b
    
    print(bbb.count("AC"))

Fixed submission:
n,q = map(int,input().split())
s = input()
pref = [0]
for i in range(1,n):
  if s[i-1:i+1] == "AC": 
      pref.append(pref[-1]+1)
  else: 
      pref.append(pref[-1])
for i in range(q):
    l,r = map(int,input().split())
    print(pref[r-1]-pref[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
inr = lambda: list(map(int, input().split()))
inn = lambda: input()

N,Q = inr()
S = inn()
for q in range(Q):
    l,r = inr()
    bubun = S[l-1:r]

    cou = 0
    ccc = 0
    for b in bubun:
        if b == "C":
            if ccc ==1:
                cou += 1
            ccc = 0
        elif b == "A":
            ccc = 1
        else:
            ccc = 0

    print(cou)

Fixed submission:
n,q = map(int,input().split())
s = input()
pref = [0]
for i in range(1,n):
  if s[i-1:i+1] == "AC": 
      pref.append(pref[-1]+1)
  else: 
      pref.append(pref[-1])
for i in range(q):
    l,r = map(int,input().split())
    print(pref[r-1]-pref[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
inr = lambda: list(map(int, input().split()))
inn = lambda: input()

N,Q = inr()
S = inn()
for q in range(Q):
    l,r = inr()
    bubun = S[l-1:r]

    bbb = ""
    for b in bubun:
        if b in ["A","C"]:
            bbb += b
        
    print(bbb.count("AC"))

Fixed submission:
n,q = map(int,input().split())
s = input()
pref = [0]
for i in range(1,n):
  if s[i-1:i+1] == "AC": 
      pref.append(pref[-1]+1)
  else: 
      pref.append(pref[-1])
for i in range(q):
    l,r = map(int,input().split())
    print(pref[r-1]-pref[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
inr = lambda: list(map(int, input().split()))
inn = lambda: input()

N,Q = inr()
S = inn()
for q in range(Q):
    l,r = inr()
    bubun = S[l-1:r]
    print(bubun.count("AC"))

Fixed submission:
n,q = map(int,input().split())
s = input()
pref = [0]
for i in range(1,n):
  if s[i-1:i+1] == "AC": 
      pref.append(pref[-1]+1)
  else: 
      pref.append(pref[-1])
for i in range(q):
    l,r = map(int,input().split())
    print(pref[r-1]-pref[l-1])
Buggy python submission (verdict: Runtime Error):
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input().rstrip()  # ignore trailing spaces
 
n, m = na()
ab = []
for i in range(n):
    ab.append(na())
ab.sort(key=lambda x: x[0])
 
rem = m
ans = 0
for v in ab:
    buy = min(rem, v[1])
    ans += buy * v[0]
    rem -= buy
print(ans)

Fixed submission:
H,W = map(int, input().split())
h,w = map(int, input().split())
print((H-h)*(W-w))
Buggy python submission (verdict: Runtime Error):
S = str(input())

zero_num = 0
one_num = 

for i in range(len(S)):
    if S[i] == "0":
        zero_num += 1

print(2*min(zero_num, len(S) - zero_num))

Fixed submission:
S = str(input())

zero_num = 0
one_num = 0

for i in range(len(S)):
    if S[i] == "0":
        zero_num += 1
    else:
        one_num += 1

print(2*min(zero_num, one_num))

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())

count = 0
T = ""
while((len(S) >= 1) and ("0" in S) and ("1" in S)):
    if (S[0:2] == "01") or (S[0:2] == "10"):
        count += 2
        S = S[2:]
        T += S
        S = T
        T = ""
    else:
        T += S[0]
        S = S[1:]
print(count)

Fixed submission:
S = str(input())

zero_num = 0
one_num = 0

for i in range(len(S)):
    if S[i] == "0":
        zero_num += 1
    else:
        one_num += 1

print(2*min(zero_num, one_num))
Buggy python submission (verdict: Runtime Error):
D = int(input())

num = 25 - D
s = "Christmas"
s += " Eve" * num

print(s)

Fixed submission:
ab, bc, ca = map(int, input().split())

S = int(ab * bc / 2)
print(S)
Buggy python submission (verdict: Runtime Error):
D = int(input())

num = 25 - D
s = "Christmas"

for i in num:
    s += " Eve"

print(s)

Fixed submission:
D = int(input())

dic = {25: "Christmas", 24: "Christmas Eve", 23: "Christmas Eve Eve",
22: "Christmas Eve Eve Eve"}

print(dic[D])