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()
L=[0]
c=0
for i in range(n-1):
    if S[i:i+2]=='AC':
        c+=1    
    L.append(c)
print(L)
for j in range(q):
    s,e=map(int,input().split())
    print(L[e-1]-L[s-1])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
hantei=[0]
for i in range(1,len(s)):
  if s[i-1]=="A" and s[i]=="C":
    hantei.append(hantei[i-1]+1)
  else:
    hantei.append(hantei[i-1])
#print(hantei)
#ここまではあってる

for i in range(q):
  l,r=map(int,input().split())
  if l==1:
    l+=1
  if hantei[l-1]!=hantei[l-2]:
    print(hantei[r-1]-hantei[l-1])
  else:
    print(hantei[r-1]-hantei[l-1]+1)

Submission status: Wrong Answer

Solution code:
def find_AC(S):
  ret = []
  for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
      ret.append(i)
  return ret

N, Q = [int(x) for x in input().split()]
S = input()
result = find_AC(S)
print(result)
pos = [res+1 for res in result]

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  ans = 0
  for p in pos:
    if p>=l and p<=r-1:
      ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = s[lr[i][0]-1:lr[i][1]]
  cnt =0
  j = -1
  while True:
    j = temp.find('AC', j+1)
    if j == -1:
      break
    cnt += 1

Submission status: Wrong Answer

Solution code:
import re
x,y  = map(int,input().split())
string = input()

while y>0:
  y-=1
  a,b = map(int,input().split())
  print(len(re.findall('AC',string[a+1:b+1])))

Submission status: Wrong Answer

Solution code:
import re
x,y  = map(int,input().split())
string = input()

while y>0:
  y-=1
  a,b = map(int,input().split())
  print(len(re.findall('AC',string[a:b])))

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_)
    r.append(r_)
    
for i in range(Q):
    print(S[l[i]:r[i]+1].count('AC'))

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())
    print(S[l:r+1].count('AC'))

Submission status: Wrong Answer

Solution code:
import bisect
n,q=map(int,input().split())
s=input()
data=[]
for i in range(n-1):
    if s[i]=='A' and s[i+1]=='C':
        data.append(i)
query = [tuple(map(int,input().split())) for i in range(q)]
print(data)
for qe in query:
    l=bisect.bisect_left(data,qe[0]-1)
    r=bisect.bisect_right(data,qe[1]-2)
    print(r-l)

Submission status: Wrong Answer

Solution code:
import numpy as np
import re
prog = re.compile('AC')
N, Q = [int(x) for x in input().split()]
S = input()
result = prog.finditer(S)
pos = np.array([res.start()+1 for res in result])
print(pos)
for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  print(len(pos[np.logical_and(pos>=l, pos<=r-1)]))

Submission status: Wrong Answer

Solution code:
def moji(s,a,b):
  s = s[a:b+1]
  re= s.count("AC")
  return re

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

s = input()

for i in range(M):
  a,b = map(int,input().split())
  ans = moji(s,a,b)
  print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

s = input()

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


def count(total, i):
    return total + 1 if s[i-1] + s[i] == 'AC' else total


cumsum = [0] + list(accumulate(range(1, n), count))

for l, r in problems:
    print(cumsum[r-1] - cumsum[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
AC = [0] * N

for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        AC[i] = AC[i-1] + 1
    else:
        AC[i] = AC[i-1]

print(AC)

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

Submission status: Wrong Answer

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

lr = []
for i in range(Q):
    _ = list(map(int,input().split()))
    lr.append(_)

AC = [0]
counter = 0

for j in range(1,N):
    if S[j-1] == 'A' and S[j] == 'C':
        counter += 1
    AC.append(counter)

print(AC)

for j in range(Q):
    right = lr[j][1]-1
    left = lr[j][0]-1
    print(AC[right]-AC[left])

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(N,Q,S)
#print(lr)

#print(S[0:5])

for _ in range(Q):
    l = lr[_][0]
    r = lr[_][1]
    #print(_,S[0:r],S[0:(l-1)])
    #print(S[0:r].count('AC')-S[0:l].count('AC'))
    #print(_,S[l:r])
    print(S[l-1:r-1].count('AC'))

Submission status: Wrong Answer

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

for i in range(q):
  cnt = 0
  l,r = map(int,input().split())
  for j in idx:
    if j in range(l-1,r)and j+1 in range(l-1,r):
      cnt += 1
  print((cnt))

Submission status: Wrong Answer

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

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

for i in range(n - 1):
    ac[i + 1] += ac[i]
print(ac)
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ret = ac[r] - ac[l]
    print(ret)

Submission status: Wrong Answer

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

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

for i in range(n - 1):
    ac[i + 1] += ac[i]
print(ac)
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ret = ac[r] - ac[l]
    if s[l] == 'A' and s[l + 1] == 'C':
        ret -= 1
    print(ret)

Submission status: Wrong Answer

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

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

for i in range(n - 1):
    ac[i + 1] += ac[i]
ac = [0] + ac
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    print(ac[r + 1] - ac[l])

Submission status: Wrong Answer

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

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

for i in range(n - 1):
    ac[i + 1] += ac[i]

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = "Z" + input()
cumsum = [0] * (N + 1)
for i in range(1, N + 1):
  temp = S[i - 1] == "A" and S[i] == "C"
  cumsum[i] = cumsum[i - 1] + temp
print(cumsum)
for _ in range(Q):
  l, r = map(int, input().split())
  temp = S[l - 1] == "A" and S[l] == "C"
  print(cumsum[r] - cumsum[l - 1] - temp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools

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

b = [0]+[S[i]=='A' and S[i+1]=='C' for i in range(N-1)]
b = list(itertools.accumulate(b))

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

Submission status: Wrong Answer

Solution code:
s = list(input())
cnt = 0
for i in range(len(s)-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input()
    S_sum = [0] * (N+1)
    for i in range(N):
        S_sum[i+1] = S_sum[i] + (1 if S[i:i+2] == 'AC' else 0)

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


main()

Submission status: Wrong Answer

Solution code:
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())

if N >= 3:
    cum = [0] * N
    c = 0
    for i in range(2, N):
        if S[i - 2:i] == "AC":
            c += 1

        cum[i - 1] = c
    cum[-1] = c
elif S == "AC":
    cum = [0, 1]
else:
    cum = [0, 0]

for l, r in zip(L, R):
    print(cum[r - 1] - cum[l - 1])

Submission status: Wrong Answer

Solution code:
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())

cum = [0] * N
c = 0
for i in range(2, N):
    if S[i - 2:i] == "AC":
        c += 1

    cum[i - 1] = c
cum[-1] = c

for l, r in zip(L, R):
    print(cum[r - 1] - cum[l - 1])

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n, q = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    ss = [0] * n
    t = 0
    for i in range(n):
        if s[i] == "C" and s[i-1] == "A":
            t += 1
        ss[i] = t
    print(ss)
    for l, r in [list(map(int, input().split())) for _ in range(q)]:
        print(ss[r-1] - ss[l-1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n1, n2 = [int(i) for i in input().split()]
s1 = input()

na1 = [[0] * 2] * n2
 
for i1 in range(n2):
    na1[i1] = [int(j) for j in input().split()]

f1 = False
a1 = [0] * n2

c1 = 0

while True:
    t1 = s1.find("AC", c1)
 
    if t1 == -1:
        break
    else:
        for i2 in range(n2):
            if na1[i2][0] <= (t1 + 1) and na1[i2][1] >= (t1 + 2):
                a1[i2] += 1
        c1 += t1 + 1

for i5 in range(n2):
    print(a1[i5])

Submission status: Wrong Answer

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

ACcount = [0 for _ in range(N)]
count = 0
Afound = False
for i in range(N):
    c = S[i]
    if Afound:
        if c == "C":
            count += 1
        Afound = False
    else:
        if c == "A":
            Afound = True
    ACcount[i] = count

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

Submission status: Wrong Answer

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

ACcount = [0 for _ in range(N)]
count = 0
Afound = False
for i, c in enumerate(S):
    if Afound:
        if c == "C":
            count += 1
        Afound = False
    else:
        if c == "A":
            Afound = True
    ACcount[i] = count

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

Submission status: Wrong Answer

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

ACcount = [0 for _ in range(N)]
count = 0
Afound = False
for i, c in enumerate(S):
    if Afound:
        if c == "C":
            count += 1
            Afound = False
    else:
        if c == "A":
            Afound = True
    ACcount[i] = count

for q in QList:
    print(ACcount[q[1]-1] - ACcount[q[0]-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
count_AC = [0]*N

have_A = False
count = 0
for i in range(N):
    if S[i] == 'A':
        have_A = True

    if have_A and S[i] == 'C':
        count += 1
        have_A = False
    count_AC[i] = count

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S = input()

add = [0] * (len(S)+1)

for i in range(N):
    if i==0:
        continue
    s = S[i]
    add[i+1] += add[i]
    if s == 'C':
        if S[i-1] == 'A':
            add[i+1] += 1

ret = []

for i in range(Q):
    l,r = map(int,input().split())
    l -= 1
    r -= 1
    
    ans = add[r+1] - add[l]
    if S[l] == 'C':
        ans -= 1

    ret.append(ans)

for r in ret:
    print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math

n,q = map(int, input().split())
s = input()
l = [0] * q
r = [0] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())

left = [0] * n
right = [0] * n
sum = s.count('AC')
for i in range(n):
    left[i] = s[:i].count('AC')
    right[i] = s[i:].count('AC')

print(left)
print(right)

for j in range(q):
    print(sum - left[l[j]] - right[r[j] - 1])

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
  readline = stdin.readline
  n, q = map(int, readline().split())
  s = input()
  c = [0] * (n + 1)
  pch = s[0]
  pc = 0
  for i in range(2, n + 1):
    cch = s[i - 1]
    if cch == 'C' and pch == 'A':
      t = pc + 1
    else:
      t = pc
    c[i] = t
    pc = t
    pch = cch
  for _ in range(q):
    l, r = map(int, readline().split())
    t = c[r] - c[l - 1]
    if l >= 2 and s[l - 2: l] == 'AC':
      t -= 1
    print(t)
  print(c)
main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
  readline = stdin.readline
  n, q = map(int, readline().split())
  s = input()
  c = [0] * (n + 1)
  pch = ''
  pc = 0
  for i in range(2, n + 1):
    cch = s[i - 1]
    if cch == 'C' and pch == 'A':
      t = pc + 1
    else:
      t = pc
    c[i] = t
    pc = t
    pch = cch
  for _ in range(q):
    l, r = map(int, readline().split())
    t = c[r] - c[l - 1]
    if l >= 2 and s[l - 2: l] == 'AC':
      t -= 1
    print(t)
main()

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
flag = True
R = [0]*N
a = 0
for i in range(N):
    s = S[i]
    if s == "A":
        flag = True
    elif s == "C" and flag:
        a += 1
        flag = False
    else:
        flag = False
    R[i] = a
print(R)
for i in range(Q):
    l, r = map(int, input().split())
    print(R[r-1] - R[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
flag = True
R = [0]*N
a = 0
for i in range(N):
    s = S[i]
    if s == "A":
        flag = True
    elif s == "C" and flag:
        a += 1
        flag = False
    R[i] = a
for i in range(Q):
    l, r = map(int, input().split())
    print(R[r-1] - R[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
flag = True
R = [0]*N
a = 0
for i in range(N):
    s = S[i]
    if s == "A":
        flag = True
    elif s == "C" and flag:
        a += 1
    R[i] = a
for i in range(Q):
    l, r = map(int, input().split())
    print(R[r-1] - R[l-1])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
lst=[0]*n
cnt=0
for i in range(n-1):
  if s[i]=='A':
    lst[i]=cnt
    cnt+=(1 if s[i+1]=='C' else 0)
    lst[i+1]=cnt
  else:
    lst[i]=cnt
for j in range(q):
  l,r=map(int,input().split())
  print(lst[r-1]-lst[l-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)]


indexes = [0] * n

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

print(indexes)

for l, r in lr:
    print(indexes[r-1]-indexes[l-1])

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())
  print(s[l:r+1].count("AC"))

Submission status: Wrong Answer

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

    # i-th element count the number of AC in S[:i]
    prefix = [0, 0]
    prev = S[0]
    for i in range(1, N):
        if prev + S[i] == "AC":
            prefix.append(prefix[-2] + 1)
        else:
            prefix.append(prefix[-1])
        prev = S[i]

    for _ in range(Q):
        l, r = map(int, input().split())
        count = prefix[r] - prefix[l]
        if S[l-1] + S[l] == "AT":
            count -= 1
        print(count)

if __name__ == '__main__':
    # print(main())
    main()

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
t = [0] * (N + 1)

for i in range(N):
    if S[i : i + 2] == 'AC':
        t[i + 1] = t[i] + 1
    else:
        t[i + 1] = t[i]

for i in range(Q):
    l, r = map(int, input().split())

print(t[r-1] - t[l-1])

Submission status: Wrong Answer

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

Sl = [0 for i in range(n)]
for i in range(1,n-1):
  if (S[i-1] == "A")&(S[i]=="C"):
    Sl[i] = Sl[i-1]+1
  else:
    Sl[i] = Sl[i-1]
Sl[n-1] = Sl[n-2]

ans = []
for i,j in lr:
  ans.append(Sl[j-1]-Sl[i-1])
  
for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
# データ構造：ヒープ
import heapq
class heapque:
    def __init__(self, *args):
        self.que = []
        for arg in args:
            self.push(arg)
    def push(self, v):
        heapq.heappush(self.que, v)
    def pop(self):
        return heapq.heappop(self.que)

# 定数
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1

# エントリーポイント
def main():
    N, Q = map(int, input().split())
    S = input()
    LR = tuple(map(int1, input().split()) for _ in range(Q))

    add_sum = [0]
    for n in range(1, N):
        add_sum += [add_sum[-1] + (S[n - 1:n + 1] == "AC")]
    print(add_sum)

    for l, r in LR:
        print(add_sum[r] - add_sum[l])

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

lr = []
for i in range(q):
	l,r = map(int,input().split())
	chkword = s[l-1:r]
	co = Counter([c for c in chkword])
	print(co)

Submission status: Wrong Answer

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

ans = 0
for i in range(len(s)-1):
	if s[i] == "A" and s[i+1] == "C":
		ans += 1
		x.append(ans)
	else:
		x.append(ans)
x.append(ans)

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

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline--------------------------------------------
    N,Q = map(int,input().split())
    S = input()
    LR = [list(map(int,input().split())) for i in range(Q)]
    accum = [0]
    keep = "start"
    S += "D"

    for i in S:
        if i == "C":
            if keep == "A":
                accum.append(accum[-1]+1)
                keep = ""
            else:
                keep = ""
                accum.append(accum[-1])
        elif i == "A":
            keep = "A"
            accum.append(accum[-1])
        else:
            accum.append(accum[-1])
    accum = accum[1:]
    for i in range(Q):
        print(accum[LR[i][1]-1]-accum[LR[i][0]-1])

if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline--------------------------------------------
    N,Q = map(int,input().split())
    S = input()
    LR = [list(map(int,input().split())) for i in range(Q)]
    accum = [0]
    keep = "start"

    for i in S:
        if i == "C":
            if keep == "A":
                accum.append(accum[-1]+1)
                keep = ""
            else:
                keep = ""
                accum.append(accum[-1])
        elif i == "A":
            keep = "A"
            accum.append(accum[-1])
        else:
            accum.append(accum[-1])
    accum = accum[1:]
    for i in range(Q):
        print(accum[LR[i][1]-1]-accum[LR[i][0]-1])

if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

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:r+1]
  print(ss.count("AC"))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
AClst = [0]
c = 0

for i in range(N-1):
  if S[i:i+2]=="AC":
    c += 1
  AClst.append(c)
print(AClst)

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
AClst = []
c = 0

for i in range(N-1):
  if S[i:i+2]=="AC":
    c += 1
  AClst.append(c)
AClst.append(c)

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
AClst = [] #ACのAを抜き出すリスト

for i in range(N-1):
  if S[i:i+2]=="AC":
    AClst.append(1)
  else:
    AClst.append(0)
AClst.append(0)

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

Submission status: Wrong Answer

Solution code:
import re

n,q = [int(x) for x in input().split()]
s = input()
questions = [list(map(lambda x: int(x),input().split())) for x in range(q)]

print([s[q[0]-1:q[1]].count('AC') for q in questions])

Submission status: Wrong Answer

Solution code:
import re

n,q = [int(x) for x in input().split()]
s = input()
questions = [list(map(lambda x: int(x),input().split())) for x in range(q)]

print([len(re.findall('AC',s[q[0]-1:q[1]])) for q in questions])

Submission status: Wrong Answer

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

def get(n):
    ans = 0
    for i in range(n):
        if S[i] =="A" and S[i+1] =="C":
            ans += 1
    return ans

for i in range(len(S)):
    l.append(get(i))
print(l)
for i in range(Q):
    print(l[X[i][1]-1]-l[X[i][0]-1])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
r=[list(map(int,input().split())) for _ in range(q)]
print(r)
x=[]
for i in range(q):
  y=''
  cnt=0
  y=s[r[i][0]-1:r[i][1]]
  for j in range(len(y)-1):
    if y[j]+y[j+1]=='AC':
      cnt+=1
  print(cnt)

Submission status: Wrong Answer

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

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

for i in range(Q):
    ans = dp[r[i]-1] - dp[l[i]-1]
    print(ans)

Submission status: Wrong Answer

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

cnt = [0]*(n)

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

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

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,q = map(int,input().split())
	s = input()
	lr = []
	for i in range(q):
		lr.append(list(map(int,input().split())))
	ac = [0]
	ac.append(1 if s[0]+s[1]=='AC' else 0)
	for i in range(2,n-1):
		if(s[i-1]+s[i]=='AC'):
			ac.append(ac[i-1]+1)
		else:
			ac.append(ac[i-1])
	ac.append(ac[-1])
	for i in lr:
		print(ac[i[1]-1]-ac[i[0]-1])

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()