Problem:


Score : 300 points

Problem Statement

You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:

Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?

Notes

A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and  (the empty string), but not AC.

Constraints

2 \leq N \leq 10^5

1 \leq Q \leq 10^5

S is a string of length N.

Each character in S is A, C, G or T.

1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:

N Q
S
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query.

Sample Input 1

8 3
ACACTACG
3 7
2 3
1 8

Sample Output 1

2
0
3

Query 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.

Query 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.

Query 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.



Sample input:
8 3
ACACTACG
3 7
2 3
1 8


Sample output:
2
0
3

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
len_s = len(s)
for i in range(q):
    l, r = map(int, input().split())
    tmp_len = len(s[l-1:r].replace("AC", ""))
    res = ((r-l+1) - tmp_len) / 2
    print(res)

Submission status: Wrong Answer

Solution code:
import bisect
N,Q = map(int,input().split())
S = input()
lista = []
for j in range(N-1):
    if S[j:j+2] == 'AC':
        lista.append(j)
print(lista)
for i in range(Q):
    l,r = map(int,input().split())
    l,r = l-1,r-1
    lind = bisect.bisect_left(lista,l)
    rind = bisect.bisect_right(lista,r-1)
    print(rind-lind)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
s = input()

L = [0]*a
li = [0]*(a+1)
for i in range(a-1):
    if s[i] == "A" and s[i+1] == "C":
        L[i] = 1
        L[i+1] = 0
        
li[0] = L[0]
for i in range(1,a):
    li[i] = li[i-1] + L[i]

for i in range(b):
    c,d = map(int,input().split())
    if d-c == 1:
        if s[c:d] == "AC":
            print(1)
        else:
            print(0)
    else:
        print(li[d-1]-li[c-2])

Submission status: Wrong Answer

Solution code:
# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = [0]*N
count = 0
for j in range(1,len(S)):
    if S[j] == 'C' and S[j - 1] == 'A':
        count += 1
    else:
        pass
    S1[j] = count
print(S1)

for k in range(Q):
    print(S1[A[k][1]-1]-S1[A[k][0]-1])

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
questions = [[i-1 for i in map(int,input().split())] for j in range(Q)]
indexes = []
for i in range(len(S)-1):
  if S[i]=='A' and S[i+1]=='C':
    indexes.append(i)
    
print(indexes)
import bisect
for question in questions:
  left = bisect.bisect_left(indexes, question[0])
  right = bisect.bisect_left(indexes, question[1])
  print(len(indexes[left:right]))

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
L = [list(map(int,input().split())) for i in range(Q)]

for c in range(Q):
  l = L[c][0] - 1
  r = L[c][1] - 1
  part = S[l:r]
  print(part.count("AC"))

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())

word = input()

counter = [0] * n

for i in range(1, len(word)):
    counter[i] = counter[i-1]
    if word[i-1] + word[i] == 'AC':
        counter[i] += 1

print(counter)
for i in range(q):
    start, end = map(int, input().split())
    print(counter[end-1] - counter[start-1])

Submission status: Wrong Answer

Solution code:
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = []
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        oc.append(i)

for i in range(Q):
    (l, r) = [int(n) for n in input().split()]
    print('')

Submission status: Wrong Answer

Solution code:
n, q = list(map(int, input().split()))
s = input()

acs = [0] * (n - 1)

for i in range(n - 1):
  if i == 0:
    if s[0 : 2] == "AC":
      acs[0] += 1
  else:
    if s[i : i + 2] == "AC":
      acs[i] = acs[i - 1] + 1
    else:
      acs[i] = acs[i - 1]
      
print(acs)

for i in range(q):
  x = 0
  l, r = list(map(int, input().split()))
  if s[l - 1:l + 1] == "AC":
    x = 1
  print(acs[r - 2] - acs[l - 1] + x)

Submission status: Wrong Answer

Solution code:
n, q = list(map(int, input().split()))
s = input()

acs = [0] * (n)

for i in range(1,n):
  if i == 1:
    if s[i - 1:i + 1] == "AC":
      acs[1] = 1
  else:
    if s[i - 1:i + 1] == "AC":
      acs[i] = acs[i - 1] + 1
    else:
      acs[i] = acs[i - 1]

print(acs)

for i in range(q):
  l, r = list(map(int, input().split()))
  print(acs[r - 1] - acs[l - 1])

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for i in range(q)]

aclist = [0]
acsum = 0

for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        acsum += 1
    aclist.append(acsum)

for i in range(q):
    ans = aclist [lr[i][1]-1] - aclist [lr[i][0]-2]
    if aclist [lr[i][0]-1] - aclist [lr[i][0]-2] != 0:
        ans -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for i in range(q)]

aclist = [0]
acsum = 0

for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        acsum += 1
    aclist.append(acsum)

for i in range(q):
    ans = aclist [lr[i][0]-1] - aclist [lr[i][0]-2]
    if aclist [lr[i][0]-1] - aclist [lr[i][0]-2] != 0:
        ans -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
s = input()
ls = [0]
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ls.append(ls[i]+1)
    else:
        ls.append(ls[i])
print(ls)
for i in range(q):
    l,r = map(int,input().split())
    print(ls[r-1]-ls[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#print(LR)

T = [0] * N
for i in range(N - 1):
  if S[i] == "A" and S[i+1] == "C":
    T[i] = 1
for i in range(1, N):
  T[i] += T[i-1]
#print(T)

for L, R in LR:
  L -= 1
  R -= 1
  answer = T[R] - T[L] 
  if T[R] != T[R-1]: answer -= 1
  if T[L] != T[L-1]: answer += 1
  print(answer)

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
t = [0]
count = 0
for i in range(1, n):
    if s[i-1] + s[i] == 'AC':
        count += 1
    t.append(count)
ans = []
for le, ri in lr:
    ans.append(t[ri-1] - t[le-1])
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from bisect import bisect_left

def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    A_index = []
    ## ACの場所を全部記録しときたい→Aの場所を全部記録
    for i in range(N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            A_index.append(i)
    
    for j in range(Q):
        if r[j] <= 1:
            print(0)
            continue

        left_index = bisect_left(A_index,l[j]-1)
        right_index = bisect_left(A_index,r[j]-2)
        if right_index == left_index:
            answer = 0
        elif right_index >= len(A_index):
            answer = right_index-left_index
        else:
            answer = right_index-left_index+1
        
        print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]"
    r = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, q = ril()
s = rs()
acc = [0] * n
for i in range(n - 1):
    if s[i] != 'A':
        acc[i + 1] = acc[i]
        continue
    if s[i + 1] == 'C':
        acc[i + 1] = acc[i] + 1
for _ in range(q):
    l, r = ril()
    print(acc[r - 1] - acc[l - 1])

Submission status: Wrong Answer

Solution code:
import sys
if sys.platform =='ios':
	sys.stdin=open('input.txt')

n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for _ in range(q)]

AC=[]
for i in range(n-1):
    if s[i]=="A":
        if s[i+1]=="C":
            AC.append(i)
print(AC)

from bisect import bisect_right as br
from bisect import bisect_left as bl
for i in range(q):
    a=bl(AC,lr[i][0]-1)
    print(i,AC,lr[i][0],a)
    b=br(AC,lr[i][1]-2)
    print(a,b)
    print(b-a)

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = list(input())
num = list(range(N))
dic1 = dict(zip(num,S))
q = [list(map(lambda x: int(x)-1,input().split())) for _ in range(Q)]
dic2 = {}
for i in range(N-1):
    if dic1[i]+dic1[i+1] == "AC":
        dic2[i] = i
print(dic1)
print(dic2)
print(q)
for i in range(Q):
    ans = 0
    for j in range(len(dic2)):
        if q[i][0] <= list(dic2.values())[j] < q[i][1]:
            ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*n

for i in range(n):
  a[i]=s[:i+1].count('AC')

print(a)
for i in range(q):
  print(a[l[i][1]-1]-a[l[i][0]-1])

Submission status: Wrong Answer

Solution code:
import sys, os
import collections

def solve(input_stream):
  n, q = [int(char) for char in input_stream.readline().strip().split()]
  target = input_stream.readline().strip()
  ans = []

  dp = [0 for i in range(len(target) + 1)]
  is_a = False
  for index, char in enumerate(target):
    dp[index + 1] = dp[index]
    if is_a:
      if char == "C":
        dp[index + 1] += 1
      is_a = False
    if char == "A":
      is_a = True
  print(dp)
  for index in range(q):
    l, r = [int(char) for char in input_stream.readline().strip().split()]
    ans.append(str( dp[r] - dp[l] ))
  return ans  

if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
AC = [None] * N
flag_A = False
cnt = 0
for i, s in enumerate(input()):
    AC[i] = cnt
    if flag_A:
        if s == 'C':
            cnt += 1
            AC[i] = cnt
        flag_A = False

    elif s == 'A':
        flag_A = True

for q in range(Q):
    l, r = map(int, input().split())
    print(AC[r-1] - AC[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
lr_list = [map(int, input().split()) for _ in range(Q)]

sum_list = [0]

for i in range(N):
    if S[i] == 'C' and S[i-1] == 'A' and i:
        sum_list.append(sum_list[-1]+1)
    else:
        sum_list.append(sum_list[-1])

print(sum_list)

for l, r in lr_list:
    print(sum_list[r] - sum_list[l-1])

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
num = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
  ans = 0
  sen = s[num[i][0]-1:num[i][1]]
  for j in range(num[i][1]-num[i][0]+1):
    if sen[j]=='A':
      if j+1<num[i][1]-num[i][0]:
        if sen[j+1]=='C':
          ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
n, q = [int(x) for x in input().split()]

s = input()

arr = [0 for _ in range(len(s)+1)]

for i in range(len(s)-1):
	if s[i] == 'A' and s[i+1] == 'C':
		arr[i+2] += 1

for i in range(1, len(arr)):
	arr[i] = arr[i-1] + arr[i]

for i in range(1, len(arr)):
	print(arr[i], end=" ")
for _ in range(q):
	a, b = [int(x) for x in input().split()]
	print(str(arr[b]-arr[a]))

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
b=[]
x=0
for i in range(10):
    ind=s.find("AC",x)
    if ind==-1:
        break
    b.append(ind+1)
    x=ind+1
for i in range(q):
    cnt=0
    a=list(map(int,input().split()))
    for j in b:
        if a[0]<=j<a[1]:
            cnt+=1
    print(cnt)

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
W = [0 for i in range(N + 1)]
AC = [False for b in range(N + 1)]
for i in range(1, N):
    if S[i] == 'C' and S[i - 1] == 'A':
        W[i + 1] = W[i] + 1
        AC[i] = True
    else:
        W[i + 1] = W[i]

for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = W[r + 1] - W[l]
    if AC[l]:
        ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
W = [0 for i in range(N + 1)]
AC = [False for b in range(N + 1)]
for i in range(1, N):
    if S[i] == 'C' and S[i - 1] == 'A':
        W[i + 1] = W[i] + 1
        AC[i] = True
    else:
        W[i + 1] = W[i]

for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = W[r + 1] - W[l]
    if AC[i]:
        ans -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split(' '))
S = input()

count_sum_list = [0]*(N+1)
start_A_pointa = [0]*(N+1)

for i in range(1,N+1):
    if i != N and S[i-1] == 'A' and S[i] == 'C':
        count_sum_list[i] = count_sum_list[i-1] + 1
        start_A_pointa[i] = 1
    else:
        count_sum_list[i] = count_sum_list[i-1]
print(count_sum_list)

output_list = []

for _ in range(Q):
    l,r = map(int,input().split(' '))
    if start_A_pointa[r] == 1:
        output_list.append(count_sum_list[r]-count_sum_list[l-1] -1)
    else:
        output_list.append(count_sum_list[r]-count_sum_list[l-1])

for out in output_list:
    print(out)

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()

dp = [[0 for i in range(N + 1)] for j in range(N + 1)]

for i in range(N - 1):
    for j in range(i + 1, N):
        print(i, j)
        if S[j] == 'C' and S[j - 1] == 'A':
            dp[i][j] = dp[i][j - 1] + 1
        else:
            dp[i][j] = dp[i][j - 1]

for i in range(Q):
    l, r = map(int, input().split())
    print(dp[l - 1][r - 1])

Submission status: Wrong Answer

Solution code:
import bisect
n,q=map(int,input().split())
s=list(input())
l=[0]*q
r=[0]*q
for i in range(q):
    l[i],r[i]=map(int,input().split())
cnt=[]
ans=0
a=[]
a1=[]
for j in range(1,n):
    if s[j-1]+s[j]=='AC':
        ans+=1
        a.append(j-1)
        a1.append(j)
        cnt.append([j-1,j,ans])
for k in range(q):
    print(bisect.bisect_left(a1,r[k])-bisect.bisect_right(a,l[k])+1)
    #print(bisect.bisect_right(a1,r[k]),bisect.bisect_left(a,l[k]))
#print(cnt)

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
'''
c=[]
for i in range(n-1):
  if s[i:i+2]=='AC':
    c.append(1)
  else:
    c.append(0)
for i in range(q):
  l,r=map(int,input().split())
  print(sum(c[l-1:r-1]))
'''
for i in range(q):
  l,r=map(int,input().split())
  print(s[l-1:r-1].count('AC'))

Submission status: Wrong Answer

Solution code:
#18:20
n,q = map(int,input().split())
s = input()
ac = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    ac.append(ac[-1] + 1)
  else:
    ac.append(ac[-1])
ac.append(0)
print(ac)
for _ in range(q):
  l,r = map(int,input().split())
  print(ac[r-1]-ac[l-1])

Submission status: Wrong Answer

Solution code:
max_num = 0
num = 0
for c in input():
    if c in {"A", "C", "G", "T"}:
        num += 1
    else:
        max_num = max(max_num, num)
        num = 0
max_num = max(max_num, num)
print(max_num)

Submission status: Wrong Answer

Solution code:
N,Q = input().split()
N,Q = int(N),int(Q)
S = input()
l,r = [],[]
for i in range(Q):
    l_,r_ = input().split()
    l_,r_ = int(l_)-1,int(r_)-1
    l.append(l_)
    r.append(r_)
    
A = [0]
sum_ = 0
for i in range(1,N):
    if(S[i-1]=="A" and S[i]=="C"):
        sum_ += 1
    A.append(sum_)

for i in range(Q):
    if(l[i]==0):
        num = r[i]
        print(A[r[i]])
    else:
        sa = A[r[i]]-A[l[i]-1]
        print(sa)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(input())
count=0
clist=[0]
for i in range(1,n):
  if l[i-1]=="A" and l[i]=="C":
    count+=1
  clist.append(count)
for i in range(m):
  i1,i2=map(int,input().split())
  if i1==1:
    ans=clist[i2-1]
  elif l[i1-1]=="C" and l[i1-2]=="A":
    ans=clist[i2-1]-clist[i1-1]-1
  else:
    ans=clist[i2-1]-clist[i1-1]
  print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(input())
count=0
clist=[0]
for i in range(1,n):
  if l[i-1]=="A" and l[i]=="C":
    count+=1
  clist.append(count)
for i in range(m):
  i1,i2=map(int,input().split())
  if l[i1-1]=="C" and l[i1-2]=="A":
    ans=clist[i2-1]-clist[i1-1]-1
  else:
    ans=clist[i2-1]-clist[i1-1]
  print(ans)

Submission status: Wrong Answer

Solution code:
# ABC122-C
import numpy as np
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
print(ind)
ind = np.array(ind)
print(ind)
for i in range(Q):
    print(np.count_nonzero((lr[i][0] <= ind) & (ind <= lr[i][1] - 1)))

Submission status: Wrong Answer

Solution code:
import bisect
n, q = map(int, input().split())
s = input()
acIdx = []
i = -1
while True:
    i = s.find('AC', i+1)
    if i == -1:
        break
    acIdx.append(i+1)

for i in range(q):
    l, r = map(int, input().split())
    li = bisect.bisect(acIdx, l)
    ri = bisect.bisect(acIdx, r-1)
    print(ri-li+1 if ri-li > 0 else 0)

Submission status: Wrong Answer

Solution code:
N, q = map(int, input().split())
S = input()
Q = [list(map(int ,input().split())) for _ in range(q)]

cnt = [0] * (N+1)
tmp = S[0]
for i in range(2,N+1):
	if tmp == "A" and S[i-1] == "C":
		cnt[i] = cnt[i-1] + 1
	else:
		cnt[i] = cnt[i-1]

	tmp = S[i-1]

for l,r in Q:
	ans = cnt[r] - cnt[l-1]

	if S[l-2] == "A" and S[l-1] == "C":
		ans -= 1

	print(ans)

print(cnt)

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
LR = [list(map(int,input().split())) for _ in range(Q)]
#print(LR)

C = [0 for _ in range(N+1)]
for i in range(1,N):
  if S[i-1] == 'A' and S[i] == 'C':
    C[i+1] = C[i] + 1
  else:
    C[i+1] = C[i]
print(C)
for l,r in LR:
  print(C[r]-C[l])

Submission status: Wrong Answer

Solution code:
def main():
    n,q = map(int, input().split())
    S = input()
    N = [0]*(n+1)

    for i in range(n):
        if S[i:i+2] == 'AC':
            N[i+1] = N[i] + 1
    for i in range(q):
        l,r = map(int,input().split())
        print(N[r-1]-N[l-1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
c=0
for q in range(Q):
    l,r=map(int,input().split())
    for i in range(l-1,r-1):
        #print(S[i:i+2])
        if S[i:i+2]=="AC":
            c+=1
print(c)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc122/tasks/abc122_c

n,q=map(int,input().split())
s=input()

a = [0] * n
num = 0

for i in range(1, n):
    if s[i]=='C' and s[i-1]=='A':
        num += 1

    a[i] = num
print(a)
for _ in range(q):
  l,r=map(int,input().split())
  print(a[r-1] - a[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = str(input())
W = [0] * (N+1)
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for n in range(N-1):
    W[n+1] = W[n] + (1 if S[n:n+2] == 'AC' else 0)    

for q in range(Q):
    print(W[L[q]-1]-W[R[q]-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = str(input())
W = [0] * (N+1)
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for n in range(N-1):
    W[n+1] = W[n] + (1 if W[n:n+2] == 'AC' else 0)    

for q in range(Q):
    print(W[L[q]-1]-W[R[q]-1])

Submission status: Wrong Answer

Solution code:
N, Q = [int(x) for x in input().split()]
S = input()
lr = [[int(x) for x in input().split()] for _ in range(Q)]
for l, r in lr:
  cnt = 0
  for i in range(r-l):
    cnt += (S[l-1+i] == 'A' and S[l+i] == 'C')
    print(cnt)

Submission status: Wrong Answer

Solution code:
N , Q = map(int,input().split())
S = input()
L = [list(map(int,input().split())) for i in range(Q)]

cut = ""

con = 0

for i in range(Q):
	cut = S[L[i][0]-1:L[i][1]]
	num = cut.count("AC")
	if num > con:
		con = num

print(con)

Submission status: Wrong Answer

Solution code:
N , Q = map(int,input().split())
S = input()
L = [list(map(int,input().split())) for i in range(Q)]

cut = ""

conlist = []

for i in range(Q):
	cut = S[L[i][0]-1:L[i][1]+1]
	conlist.append(cut.count("AC"))
	
print(max(conlist))

Submission status: Wrong Answer

Solution code:
N, Q = map(int,input().split())
S = input()
arr = [0]*(N-1)
num = 0
for i in range(N-1):
  arr[i] = num
  if (S[i]=='A')&(S[i+1]=='C'):
    num += 1
arr.append(arr[-1])


for _ in range(Q):
  start,end = map(int,input().split())
  print(arr[end-1]-arr[start-1])

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    lines = stdin.readlines()
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in lr:
        print(AC[r] - AC[l])
    return


main()

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    ss=s[l-1:r]
    n=len(ss)
    ans=0
    for i in range(n-1):
        if s[i]=="A" and s[i+1]=='C':
            ans+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
s = list(input())
lr_list = [0]*q
pre_s = "hoge"
a_list = []
temp_l = 0
temp_r = 0
for i in range(n):
	if pre_s == "A" and s[i] == "C":
		a_list.append(i)		
	pre_s = s[i]

for i in range(q):
	l,r = map(int,input().split())
	temp_l = 999999
	temp_r = 0	
	for j in range(len(a_list)):	
		if l <= a_list[j]:		
			temp_l = min(j,temp_l)
		if r > a_list[j]:
			temp_r = j
	lr_list[i] = [temp_l,temp_r]
#print(lr_list)
for i in range(q):
	print(lr_list[i][1]-lr_list[i][0]+1) if lr_list[i][1]-lr_list[i][0]+1 > 0 else print("0")
#print(lr_list)

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
a=[0]
for i in range(1,N):
    if S[i-1]+S[i]=='AC':
        a.append(1)
    else:
        a.append(0)
print(a)
b=[]
sum=0
b.append(sum)
for x in a:
    sum+=x
    b.append(sum)
print(b)
for i in range(Q):
    l,r=map(int,input().split())
    print(b[r]-b[l])

Submission status: Wrong Answer

Solution code:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
while i < n:
    if s[i] == "A":
        ac[i] = c
        i += 1
        if s[i] == "C":
            c += 1
            ac[i] = c
            i += 1
        else:
            ac[i] = c
            i += 1
    else:
        ac[i] = c
        i += 1
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Submission status: Wrong Answer

Solution code:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
while i < n:
    if s[i] == "A":
        ac[i] = c
        i += 1
        if s[i] == "C":
            c += 1
            ac[i] = c
            i += 1
        else:
            ac[i] = c
            i += 1
    else:
        ac[i] = c
        i += 1
print(ac)
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
cnt_list = [0]*(n)
tmpi = 0
for i in range(1, n):
    if s[i-1] == "A":
        if s[i] == "C":
            cnt_list[i] = cnt_list[i-1] + 1
        else:
            cnt_list[i] = cnt_list[i-1]
    else:
        cnt_list[i] = cnt_list[i-1]
            
print(cnt_list)
for i in range(q):
    l, r = map(int, input().split())
    print(cnt_list[r-1] - cnt_list[l-1])

Submission status: Wrong Answer

Solution code:
#122 C
n,q=map(int,input().split())
s=input()
t=[0]*n
lr=[list(map(int,input().split())) for i in range(q)]
i=0
cnt=0
while i<n-1:
    if s[i]=="A":
        t[i]+=cnt
        i+=1
        if s[i]=="C":
            cnt+=1
            t[i]+=cnt
            i+=1
        else:
            t[i]+=cnt
            i+=1
    else:
        t[i]+=cnt
        i+=1
if i==n-1:
    t[i]+=cnt
for j in range(q):
    print(t[lr[j][1]-1]-t[lr[j][0]-1])

Submission status: Wrong Answer

Solution code:
#122 C
n,q=map(int,input().split())
s=input()
t=[0]*n
lr=[list(map(int,input().split())) for i in range(q)]
i=0
cnt=0
while i<n-1:
    if s[i]=="A":
        t[i]+=cnt
        i+=1
        if s[i]=="C":
            cnt+=1
            t[i]+=cnt
            i+=1
        else:
            t[i]+=cnt
            i+=1
    else:
        t[i]+=cnt
        i+=1
if i==n-1:
    t[i]+=cnt
for i in range(q):
    print(t[lr[i][1]-1]-t[lr[i][0]-1])

Submission status: Wrong Answer

Solution code:
import itertools
n,q = map(int, input().split())
s = input()
calc = [0]*n
prev = None
for i,c in enumerate(s):
    if prev == 'A' and c == 'C':
        calc[i] = 1
    prev = c
calc = list(itertools.accumulate(calc))
print(calc)
for _ in range(q):
    l,r = map(int,input().split())
    print(calc[r-1]-calc[l-1])

Submission status: Wrong Answer

Solution code:
n,q = map(int, input().split())
s = input()
c = []
for i in range(n+1):
  c.append(s[:i].count("AC"))
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r]-c[l-1])

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
sACList = [0] * (n-1)
for i in range(n-1):
    if s[i:i+2] == "AC":
        sACList[i] = 1
print(sACList)
for j in range(q):
    l, r = map(int, input().split())
    print(sum(sACList[l-1:r-1]))

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()

L = []
R = []

for i in range(Q):
    l, r = map(int, input().split())
    L.append(l-1)
    R.append(r-1)

a = [0]*N
pre = ''

for i, s in enumerate(S):
    if pre=='A' and s=='C':
        a[i] = 1
    pre = s

cnt = 0
for i in range(Q):
    cnt += sum(a[:R[i]]) - sum(a[:L[i]])

print(cnt)

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()

L = []
R = []

for i in range(Q):
    l, r = map(int, input().split())
    L.append(l-1)
    R.append(r-1)

a = [0]*N
pre = ''

for i, s in enumerate(S):
    if pre=='A' and s=='C':
        a[i] = 1
    pre = s

cnt = 0
for i in range(Q):
    cnt += sum(a[L[i]:R[i]])

print(cnt)

Submission status: Wrong Answer

Solution code:
N, Q =map(int,input().split())
S =input()
LR = [list(map(int,input().split())) for i in range(Q)]
ACnum =[0]*(N+1)
Sofar = 0
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        Sofar+=1
    ACnum[i+1] = Sofar
ACnum[N]=Sofar
print(ACnum)
for i in range(Q):
    print(ACnum[LR[i][1]-1]-ACnum[LR[i][0]-1])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
some=input()
lists=[]
    
for _ in range(q):
    add=list(map(int,input().split()))
    lists.append(add)
print(lists)
for j in range(q):
    nums=0
    nums+=some[lists[j][0]-1:lists[j][1]].count("AC")
    print(nums)

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
some=input()
lists=[]

for _ in range(q):
    add=list(map(int,input().split()))
    lists.append(add)
print(lists)
for j in range(q):
    nums=some[lists[j][0]-1:lists[j][1]].count("AC")
    print(nums)

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
QList = []
Data  = [0]*N
for _ in range(Q):
    l,r = map(int,input().split())
    QList.append([l,r])

CFound = False
AFound = False

for i in range(N):
    if AFound == False:
        if S[i] == 'A':
            AFound = True
    else:
        if S[i] == 'C':
            CFound = True
        else:
            AFound = False

    if CFound:
        Data[i] = Data[i-1]+1
        CFound = False
        AFound = False
    else:
        if i > 0:
            Data[i] = Data[i-1]
        else:
            Data[i] = 0

for q in QList:
    [l,r] = q
    print( Data[r-1]-Data[l-1])

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
QList = []
Data  = [0]*N
for _ in range(Q):
    l,r = map(int,input().split())
    QList.append([l,r])

CFound = False
AFound = False

for i in range(N):
    if AFound == False:
        if S[i] == 'A':
            AFound = True
    else:
        if S[i] == 'C':
            CFound = True
        else:
            AFound = False

    if CFound:
        Data[i] = Data[i-1]+1
        CFound = False
        AFound = False
    else:
        Data[i] = Data[i-1]

for q in QList:
    [l,r] = q
    print( Data[r-1]-Data[l-1])

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
QList = []
Data  = [0]*N
for _ in range(Q):
    l,r = map(int,input().split())
    QList.append([l,r])

CFound = False
AFound = False

for i in range(N):
    if AFound == False:
        if S[i] == 'A':
            AFound = True
    else:
        if S[i] == 'C':
            CFound = True
    if CFound:
        # i>1
        Data[i] = Data[i-1]+1
        CFound = False
        AFound = False
    else:
        Data[i] = Data[i-1]

for q in QList:
    [l,r] = q
    print( Data[r-1]-Data[l-1])

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
QList = []
Data  = [0]*N
for _ in range(Q):
    l,r = map(int,input().split())
    QList.append([l,r])

CFound = False
AFound = False

for i in range(N):
    if AFound == False:
        if S[i] == 'A':
            AFound = True
    else:
        if S[i] == 'C':
            CFound = True
    if CFound:
        # i>1
        Data[i] = Data[i-1]+1
        CFound = False
        AFound = False
    else:
        Data[i] = Data[i-1]

print(Data)

for q in QList:
    [l,r] = q
    print( Data[r-1]-Data[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
S_list = list(S)
count_list = [0]*N
print(S_list)

for i in range(1, N):
    count_list[i] += count_list[i-1] 
    if S_list[i-1] == "A" and S_list[i] == "C":
        count_list[i] += 1
        
print(count_list)

for i in range(Q):
    start, end = map(int, input().split())
    count = count_list[end-1] - count_list[start-1]
    print(count)