Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))
# print(a_list)
a_set = set(a_list)
length_dict = {}
total_num = 0
for elm in a_set:
    cur_list = [ind for ind in range(n) if a_list[ind] == elm]
    length_dict[elm] = len(cur_list)
    total_num += int(length_dict[elm]*(length_dict[elm]-1)/2)
difference = {}
for elm in a_set:
    difference[elm] = int(length_dict[elm]*(length_dict[elm]-1)/2) - int((length_dict[elm]-1)*(length_dict[elm]-2)/2)


# print(num_dict0, num_dict1)
for ind in range(n):
    elm = a_list[ind]
    print(total_num-difference[elm])

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))
# print(a_list)
a_set = set(a_list)
length_dict = {}
for elm in a_set:
    length_dict[elm] = 0    

for ind in range(n):
    elm = a_list[ind]
    length_dict[elm] += 1

total_num = 0
for elm in a_set:
    total_num += int(length_dict[elm]*(length_dict[elm]-1)/2)
difference = {}
for elm in a_set:
    difference[elm] = int(length_dict[elm]*(length_dict[elm]-1)/2) - int((length_dict[elm]-1)*(length_dict[elm]-2)/2)


# print(num_dict0, num_dict1)
for ind in range(n):
    elm = a_list[ind]
    print(total_num-difference[elm])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))
# print(a_list)
a_set = set(a_list)
length_dict = {}
for elm in a_set:
    cur_list = [ind for ind in range(n) if a_list[ind] == elm]
    length_dict[elm] = len(cur_list)
num_dict0 = {}
num_dict1 = {}
for elm in a_set:
    num_dict0[elm] = int(length_dict[elm]*(length_dict[elm]-1)/2)
    num_dict1[elm] = int((length_dict[elm]-1)*(length_dict[elm]-2)/2)

# print(num_dict0, num_dict1)
for ind in range(n):
    cur_elm = a_list[ind]
    output = 0
    for elm in a_set:
        if elm == cur_elm:
            output += num_dict1[elm]
        else:
            output += num_dict0[elm]
    print(output)

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))
# print(a_list)
a_set = set(a_list)
length_dict = {}
for elm in a_set:
    length_dict[elm] = 0    

for ind in range(n):
    elm = a_list[ind]
    length_dict[elm] += 1

total_num = 0
for elm in a_set:
    total_num += int(length_dict[elm]*(length_dict[elm]-1)/2)
difference = {}
for elm in a_set:
    difference[elm] = int(length_dict[elm]*(length_dict[elm]-1)/2) - int((length_dict[elm]-1)*(length_dict[elm]-2)/2)


# print(num_dict0, num_dict1)
for ind in range(n):
    elm = a_list[ind]
    print(total_num-difference[elm])
Buggy python submission (verdict: Runtime Error):
S = list(input().split())
q = int(input())
d = deque(S)
rev_cnt = 0
for ind in range(q):
    cur_list = list(input().split())
    #print(cur_list)
    if int(cur_list[0]) == 1:
        rev_cnt += 1
    else:
        f = int(cur_list[1])
        c = cur_list[2]
        if (rev_cnt + f) % 2 == 0:
            d.append(c)
        else:
            d.appendleft(c)         
S = list(d)
if rev_cnt %2 == 1:
    S.reverse()
print("".join(S))

Fixed submission:
S = input()
q = int(input())
head = ""
tail = ""
rev_cnt = 1
for ind in range(q):
    cur_list = list(input().split())
    #print(cur_list)
    if int(cur_list[0]) == 1:
        rev_cnt *= -1
    else:
        f = int(cur_list[1])
        c = cur_list[2]
        if f == 1:
            if rev_cnt == 1:
                head += c
            else:
                tail += c
        elif f == 2:
            if rev_cnt == 1:
                tail += c
            else:
                head += c
            
S = head[::-1] + S + tail   
if rev_cnt == -1:
    S = S[::-1]
    
print("".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
p = list(map(int,input().split()))

subs = [p[ind:ind+k] for ind in range(n-k+1)]
sums = [sum(elm) for elm in subs]
max_val = float(max(sums))
k = float(k)
print(max_val/2+k/2)

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

exps = [(elm+1)/2 for elm in p]
#print(exps)
cum_sums = [0]*(n+1)
for ind in range(n):
  cum_sums[ind+1] = cum_sums[ind]+exps[ind]
#print(cum_sums)
k_exps = [cum_sums[ind+k]-cum_sums[ind] for ind in range(n-k+1)]
#print(k_exps)
print(max(k_exps))

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

max_val = 0
for ind in range(n-k+1):
  if sum(p[ind:ind+k]) >= max_val:
    max_val = sum(p[ind:ind+k])
max_val = float(max_val)
k = float(k)
print(max_val/2+k/2)

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

exps = [(elm+1)/2 for elm in p]
#print(exps)
cum_sums = [0]*(n+1)
for ind in range(n):
  cum_sums[ind+1] = cum_sums[ind]+exps[ind]
#print(cum_sums)
k_exps = [cum_sums[ind+k]-cum_sums[ind] for ind in range(n-k+1)]
#print(k_exps)
print(max(k_exps))

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

sums = []
for ind in range(n-k+1):
  sums.append(sum(p[ind:ind+k]))
max_val = float(max(sums))
k = float(k)
print(max_val/2+k/2)

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

exps = [(elm+1)/2 for elm in p]
#print(exps)
cum_sums = [0]*(n+1)
for ind in range(n):
  cum_sums[ind+1] = cum_sums[ind]+exps[ind]
#print(cum_sums)
k_exps = [cum_sums[ind+k]-cum_sums[ind] for ind in range(n-k+1)]
#print(k_exps)
print(max(k_exps))

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

max_val = 0
for ind in range(n-k+1):
  cur_val = sum(p[ind:ind+k])
  max_val = max(max_val,cur_val)
max_val = float(max_val)
k = float(k)
print(max_val/2+k/2)

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

exps = [(elm+1)/2 for elm in p]
#print(exps)
cum_sums = [0]*(n+1)
for ind in range(n):
  cum_sums[ind+1] = cum_sums[ind]+exps[ind]
#print(cum_sums)
k_exps = [cum_sums[ind+k]-cum_sums[ind] for ind in range(n-k+1)]
#print(k_exps)
print(max(k_exps))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
p_min = []
for ind in range(1,n+1):
    p_min.append(min(p[:ind]))
# print(p_min)
cnt = 0
for ind in range(n):
    if p[ind] <= p_min[ind]:
        cnt += 1  
print(cnt)


Fixed submission:
n = int(input())
p = list(map(int, input().split()))
p_min = p[0]
cnt = 0
for ind in range(n):
    if p[ind] <= p_min:
        cnt += 1
    p_min = min(p[ind],p_min)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import math

A, B, N = map(int, input().split(' '))

_max = 0
for x in range(N, int(N/2), -1):
    if x < 1:
        break
    num =math.floor(A * x / B) - A * math.floor(x/B) 
    # print(num)
    if  num > _max:
        _max = num

print(_max)


Fixed submission:
import math

def floor(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x/B) 

A, B, N = map(int, input().split(' '))
x = min(N, B-1)
print(floor(A,B,x))

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

A, B, N = map(int, input().split(' '))

_max = 0
for x in range(N, int(N/2), -1):
    
    num =math.floor(A * x / B) - A * math.floor(x/B) 
    # print(num)
    if  num > _max:
        _max = num

print(_max)

Fixed submission:
import math

def floor(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x/B) 

A, B, N = map(int, input().split(' '))
x = min(N, B-1)
print(floor(A,B,x))

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

A, B, N = map(int, input().split(' '))

_max = 0
for x in range(1, N+1):
    num =math.floor(A * x / B) - A * math.floor(x/B) 
    if  num > _max:
        _max = num

print(_max)


Fixed submission:
import math

def floor(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x/B) 

A, B, N = map(int, input().split(' '))
x = min(N, B-1)
print(floor(A,B,x))
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce
import itertools 

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

_sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            _sum +=gcd(a, b, c)

print(_sum)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

_sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            _sum +=gcd(a, b, c)

print(_sum)
Buggy python submission (verdict: Runtime Error):
X = map(int, input())

num_500 = X // 500
num_5 = (X - (X // 500)*500 ) % 5

print(1000*num_500 + 5 * num_5)

Fixed submission:
X = int(input())
 
num_500 = X // 500
num_5 = (X - (X // 500) * 500 ) // 5
 
print(1000*num_500 + 5 * num_5)

Buggy python submission (verdict: Runtime Error):
X = map(int, input())

happy = ((X // 500) * 1000 ) + ((X % 5) * 5)
print(happy)

Fixed submission:
X = int(input())
 
num_500 = X // 500
num_5 = (X - (X // 500) * 500 ) // 5
 
print(1000*num_500 + 5 * num_5)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y= map(int, input().split(' '))
 
node = []
for k in range(1, N+1):
    for v in range(k, N+1):
       node.append(min([abs(k-v), abs(X-k)+abs(v-Y)+1, abs(Y-k)+abs(X-v)+1]))

for i in range(1, N):
    print(node.count(i))

Fixed submission:
N, X, Y= map(int, input().split(' '))
 
array=[None]*N
for i in range(N):
    array[i]=0
    
for k in range(1, N+1):
    for v in range(k, N+1):
       array[min([abs(k-v), abs(X-k)+abs(v-Y)+1, abs(Y-k)+abs(X-v)+1])] += 1 

for i in range(1, N):
    print(array[i])

Buggy python submission (verdict: Time Limit Exceeded):
import queue
import itertools

def bfs(top_dict, first, end):
    q = queue.Queue()
    visited = []
    
    dist = {}
    for i in range(1, end+1):
        dist[i] = 0 
    q.put(first)
    
    while not q.empty():
        label = q.get(0)
        if label not in visited:
            visited.append(label)
            for i in top_dict[label]:
                if dist[i] != 0 or i== first:
                    continue
                dist[i] =  dist[label] +1
                q.put(i)
    return dist  

N, X, Y= map(int, input().split(' '))

top_dict = {}
for i in range(1, N+1):
    if i == N:
        top_dict[i] = [i-1]
    elif i==1:
        top_dict[i] = [i+1]
    else:
        top_dict[i] = [i-1, i+1]


top_dict[X].append(Y)
top_dict[Y].append(X)
res = list(itertools.chain(*[bfs(top_dict, i, N).values() for i in range(1, N+1)]))

for i in range(1, N):
    print(res.count(i)//2)

Fixed submission:
N, X, Y= map(int, input().split(' '))
 
array=[None]*N
for i in range(N):
    array[i]=0
    
for k in range(1, N+1):
    for v in range(k, N+1):
       array[min([abs(k-v), abs(X-k)+abs(v-Y)+1, abs(Y-k)+abs(X-v)+1])] += 1 

for i in range(1, N):
    print(array[i])
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, A, B, C = map(int ,input().split(' '))
p = list(map(int ,input().split(' ')))
q = list(map(int ,input().split(' ')))
R = set(map(int ,input().split(' ')))

eat = sorted(p, reverse=True)[:X]
eat[len(eat):] = sorted(q, reverse=True)[:Y]

eat.sort()

for r in R:
  if r>eat[0]:
    eat.remove(min(eat))
    eat.append(r)
  
print(sum(eat))

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(' ')))
 
eat = sorted(p, reverse=True)[:X]
eat[len(eat):] = sorted(q, reverse=True)[:Y]
eat[len(eat):] = R
eat.sort(reverse=True)


print(sum(eat[:X+Y]))

Buggy python submission (verdict: Time Limit Exceeded):
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(' ')))

eat = sorted(p, reverse=True)[:X]
eat[len(eat):] = sorted(q, reverse=True)[:Y]

for r in R:
  if r>min(eat):
    eat.remove(min(eat))
    eat.append(r)
  
print(sum(eat))


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(' ')))
 
eat = sorted(p, reverse=True)[:X]
eat[len(eat):] = sorted(q, reverse=True)[:Y]
eat[len(eat):] = R
eat.sort(reverse=True)


print(sum(eat[:X+Y]))
Buggy python submission (verdict: Runtime Error):
L = map(int, input())

l = L/3

l*l*l

print('{:.0f}'.format(l*l*l))

Fixed submission:
import math

N, M = map(int, input().split(' '))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
cnt = 0

if N > 1:
    cnt += combinations_count(N, 2)
if M > 1:
    cnt += combinations_count(M, 2)

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools 

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

for k in range(N):
    A_replace = A[:]
   
    del A_replace[k]
    cnt = 0 
    for i in set(A_replace):
        cnt += ((A_replace.count(i) * (A_replace.count(i)-1)) / 2)
    A_replace = A
    print(int(cnt))

Fixed submission:
import collections

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

A_counter= collections.Counter(A)

_sum = 0
for count in A_counter:
    _sum += (A_counter[count]* (A_counter[count]-1)) // 2

for k in range(N):
    l = (A_counter[A[k]]) *  (A_counter[A[k]]-1)//2
    m = (A_counter[A[k]]-1) *  (A_counter[A[k]]-2)//2
    # print(_sum)
    # print(c_a)
    print(_sum -l + m)
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split(' '))
 
blue = 0
if N!=0 and A!=0:
    for i in range(int(N/(A+B))+1):
        if i==int(N/(A+B)):
            if N%(A+B) <= A:
                blue += N%(A+B)
            else:
                blue += A 
        else:
            blue += A

print(blue)

Fixed submission:
N, A, B = map(int, input().split(' '))
 
blue = 0
if N!=0 and A!=0:    
    blue = A *int(N/(A+B))
    if N%(A+B) <= A:
        blue += N%(A+B)
    else:
        blue += A 
print(blue)

Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split(' '))
 
row = ''
for i in range(int(N/(A+B)) +1):
    row+='b' * A
    row+= 'r' * B
print(list(row[:N]).count('b'))

Fixed submission:
N, A, B = map(int, input().split(' '))
 
blue = 0
if N!=0 and A!=0:    
    blue = A *int(N/(A+B))
    if N%(A+B) <= A:
        blue += N%(A+B)
    else:
        blue += A 
print(blue)

Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split(' '))

row = ''
for i in range(1000):
    row +='b' * A
    row+= 'r' * B

print(list(row[:N]).count('b'))

Fixed submission:
N, A, B = map(int, input().split(' '))
 
blue = 0
if N!=0 and A!=0:    
    blue = A *int(N/(A+B))
    if N%(A+B) <= A:
        blue += N%(A+B)
    else:
        blue += A 
print(blue)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

Query = [input() for i in range(Q)]

for q in Query:
    query = q.split(' ')
    if q == '1':
        S = S[::-1]
    elif query[0]=='2':
        if query[1]=='1':
            S = query[2] + S
        elif query[1]=='2':
            S = S + query[2]
        
print(S)

Fixed submission:
import collections

S = input()
Q = int(input())

Query = [input() for i in range(Q)]

deq = collections.deque(S)

flg = False
for q in Query:
    query = q.split(' ')
    if query[0]=='1':
        flg = not flg

    elif query[0] == '2':
        if query[1] == '1':
            if flg == True:
                deq.append(query[2])
            else:
                deq.appendleft(query[2])
        else:
            if flg==True:
               deq.appendleft(query[2])
            else:
               deq.append(query[2]) 
if flg == True:
    deq.reverse()        
print(''.join(deq))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = [input() for n in range(N)]

S = Counter(S)

k_list = [ k for k, v in S.items() if v == max(S.values())]

for k in sorted(k_list):
    print(k)


Fixed submission:
from collections import Counter

N = int(input())
S = [input() for n in range(N)]

S = Counter(S)
max_val = max(S.values()) 
k_list = [ k for k, v in S.items() if v == max_val]

for k in sorted(k_list):
    print(k)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

positive = []
negative = []
zero = 0

for combi in itertools.combinations(A, 2):
    c = combi[0]
    n = combi[1]
    if c*n > 0:
        positive.append(c*n)
    elif c*n < 0 :
        negative.append(c*n)
    else:
        zero += 1

if K <= len(negative):
    negative.sort()
    print(negative[K-1])
elif K <= len(negative)+zero:
    print(0)
else:
    positive.sort()
    k = K - len(negative) - zero
    print(positive[k-1])

Fixed submission:
import itertools
import numpy as np

N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A = np.sort(A)

positive = A[A>0]
negative = A[A<0]
zero = A[A==0]

l = -10**18
r = 10**18

while l + 1 < r:
    x = (l+r) // 2 # 中央位置
    cnt = 0
    if x >= 0:
        cnt += N * len(zero)
    
    # x//pos : 中央値/posのそれぞれの値
    cnt += A.searchsorted(x//positive, side="right").sum()
    cnt += (N - A.searchsorted(-(-x//negative), side="left")).sum()
    cnt -= np.count_nonzero(A * A <= x)
    cnt //= 2
 
    if cnt >= K:
        r = x
    else:
        l = x
print(r)
Buggy python submission (verdict: Runtime Error):
def expect(p):
    return (int(p)+1)/2

N, K = map(int ,input().split(' '))
P = list(map(expect ,input().split(' ')))

sum_list = [sum(P[0:K])]
S = [sum(P[0:i]) for i in range(len(P))]
E = []

for i in range(N-K):
    E.append(S[i+K]-S[i])

print('{:.12f}'.format(max(E)))

Fixed submission:
S, T = map(str ,input().split(' '))
A, B = map(int ,input().split(' '))
U = input()

dct = {S:A, T:B}
dct[U] = dct[U] - 1
print(dct[S], dct[T])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

A.sort()
B.sort()
C.sort()

ans = 0
for i in B:
  a=bisect.bisect_left(A, i)
  c=bisect.bisect_right(C, i)
  ans += len(A[:a])*len(C[c:])
print(ans)

Fixed submission:
import bisect

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

A.sort()
B.sort()
C.sort()

ans = 0
for i in B:
  a=bisect.bisect_left(A, i)
  c=bisect.bisect_right(C, i)
  ans += a*(N-c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
A,B,N=map(int,input().split())
x_max=0
for x in range(N+1):
    x_max=max(math.floor(A*x/B)-A*math.floor(x/B),x_max)
print(x_max)

Fixed submission:
import math
A,B,N=map(int,input().split())
def D_func(x):
    return math.floor(A*x/B)-A*math.floor(x/B)
print(D_func(min(B-1,N)))
Buggy python submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input().split()))
if N==1:
    print(1)
else:
    maxh=H[0]
    c=1
    for i in range(1,N):
        if maxh<=H[i]:
            c+=1
            maxh=H[i]
    print(c)

Fixed submission:
A,B=map(int,input().split())
A1=2*A-1
B1=2*B-1
if A==B:
    print(2*A)
else:
    print(max(A,B)*2-1)
Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
l=[A,B,C,D,E]
l0=[i%10 for i in l]
x=[]
for i in range(5):
    if l0[i]!=0:
        l[i]=(1+l[i]//10)*10 
        x.append(l0[i])
ans=sum(l)-10+min(x)
print(ans)

Fixed submission:
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
l=[A,B,C,D,E]
l0=[i%10 for i in l]
x=[]
for i in range(5):
    if l0[i]!=0:
        l[i]=(1+l[i]//10)*10 
        x.append(l0[i])
if x==[]:
    ans=sum(l)
else:
    ans=sum(l)-10+min(x)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()
t=[0]*N
for i in range(N-1):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Fixed submission:
b=input()
if b=='A':
    print('T')
elif b=='T':
    print('A')
elif b=='C':
    print('G')
else:
    print('C')

Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
c={}
for i in range(Q):
    for i in range(l[i]-1,r[i]-1):
        if (S[i]=='A') and (S[i+1]=='C'):
            c[i]=1
    print(int(c.count(1)))

Fixed submission:
b=input()
if b=='A':
    print('T')
elif b=='T':
    print('A')
elif b=='C':
    print('G')
else:
    print('C')
Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
c={}
for i in range(Q):
    for i in range(l[i]-1,r[i]-1):
        if (S[i]=='A') and (S[i+1]=='C'):
            c[i]=1
    d=int(c.count(1))
    print(d)

Fixed submission:
N,Q=map(int,input().split())
S=input()
t=[0]*N
for i in range(N-1):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
c=[]
for i in range(N):
    c.append(0)
for i in range(N-1):
    if (S[i]=='A') and (S[i+1]=='C'):
        c[i]+=1
for i in range(Q):
    d=c[l[i]-1:r[i]-1]
    print(d.count(1))

Fixed submission:
N,Q=map(int,input().split())
S=input()
t=[0]*N
for i in range(N-1):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
for i in range(Q):
    c=0
    for j in range(l[i]-1,r[i]-1):
        if (S[j]=='A') and (S[j+1]=='C'):
            c+=1
    print(c)

Fixed submission:
N,Q=map(int,input().split())
S=input()
t=[0]*N
for i in range(N-1):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
c=[]
for i in range(N):
    c.append(0)
for i in range(N-1):
    if (S[i]=='A') and (S[i+1]=='C'):
        c[i]+=1
for i in range(Q):
    print(sum(c[l[i]-1:r[i]-1]))

Fixed submission:
N,Q=map(int,input().split())
S=input()
t=[0]*N
for i in range(N-1):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
for i in range(Q):
    S0=S[l[i]-1:r[i]]
    print(S0.count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
t=[0]*N
for i in range(N-1):
    t[i+1]=t[i]+(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])