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:
def solve(st):
        global ans
        if len(st) == 0 or  len(st) == 1:
            return
        elif len(st) == 2:
            if st[0] == 'A' and st[1] == 'C':
                ans += 1
                return
        elif len(st) == 3:
            if (st[0] == 'A' and st[1] == 'C') or (st[1] == 'A' and st[2] == 'C'):
                ans += 1
                return
            else:
                return
        else:
            if len(s)//2 - 1 != 'A':
                solve(st[:len(st)//2])
                solve(st[len(st)//2 + 1:])
            else:
                solve(st[:len(st)//2-1])
                solve(st[len(st)//2:])

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n,q = map(int,input().split())
s = input()
lr = [[int(i) for i in input().split()]for _ in range(q)]
f = 0
si = []
for j,k in enumerate(s):
  if k =='A':
    f = 1
  elif k=='C' and f == 1:
    si.append(j-1)
    f =0
  else:
    f = 0
if len(si)==0:
  for i in range(q):
    print(0)
    exit()
else:
  for i in lr:
    si = np.array(si)
    print(len(si[(i[0]-1<=si) & (si<=i[1]-2)]))

Submission status: Wrong Answer

Solution code:
n,m = input().split()
s = input()
ans = 0
table = [0]
for i in range(len(s)):
    if s[i:i+2] == 'AC':
        ans += 1
    table.append(ans)
        
for i in range(int(m)):
    a,b = input().split()
    a = int(a)
    b = int(b)
    print(table[b-a])
    ans = 0

Submission status: Wrong Answer

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

dp =[[0 for i in range(n)] for j in range(n)]

for j in range(n):
    if s[j]=="C" and j!=0 and s[j-1]=="A":
        for k in range(n):
            if k<=j:
                dp[k][j]=dp[k][j-1]+1 
    else:
        for k in range(n):
            if k<=j:
                dp[k][j]=dp[k][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:
# coding: utf-8
# Your code here!
ACGT = ("A", "G", "C", "T")
N, Q = map(int, input().rstrip().split())
S = input()

pos_l = []
A_flag = False
cnt = 0
for c in S:
    if c == "A":
        A_flag = True
        pos_l.append(0)
    elif c == "C" and A_flag:
        A_flag = False
        pos_l.append(1)
    elif c != "C" and A_flag:
        A_flag = False
        pos_l.append(0)
    else:
        pos_l.append(0)

print(pos_l)

for _ in range(Q):
    l, r = map(int, input().rstrip().split())
    cnt = sum(pos_l[l:r])
    
    print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[75]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=list()
import re
i = 0
pAC=re.compile("AC")
while i >= 0:
    m = pAC.search(S, i)
    if m:
        l.append(m.start())
        #l.append(m.end())
        i = m.start() + 1
    else:
        break
#print(l)
for i in range(Q):
    print(sum(x >= lr[i][0] and x<=lr[i][1] for x in l))


# In[ ]:

Submission status: Wrong Answer

Solution code:
char_numbers = [int(e) for e in input().split(" ")]

char = input()

questions = []
for i in range(char_numbers[1]):
    questions.append([int(e) - 1 for e in input().split()])

start = [-2]

while start[-1] != -1:
    start[-1] = start[-1] + 2
    start.append(char.find("AC",start[-1]))
    start[-2] -= 2 
start[-2] -= 2
del start[0]
del start[-1]

for i in questions:
    n = sum(x>=i[0] and x+1 <= i[1] for x in start)
    print(n)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

string = list(input())
num = 0
numlist = []
for i in range(len(string)):
    if str(string[i]) == "A" or str(string[i]) == "T" or str(string[i]) == "G" or str(string[i]) == "C":
            num += 1
    else:
        numlist.append(num)
        num = 0
print(max(numlist))

Submission status: Wrong Answer

Solution code:
import re
# pattern = r'[ACGT]+'
# ans = 0
# # text = 'SHINJUKU'
# text = input()
# match_list = re.findall(pattern, text)
#
# # print(match_list)
# if match_list:
#     match_list_len = [len(x) for x in match_list]
#     ans = max(match_list_len)
#
# print(ans)

n, q = map(int, input().split())
text = input()
l = [0] * q
r = [0] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())
# n = 8
# q = 3
# text = 'ACACTACGDRHFGGUHHOJJIJIACGYUAC'
# l = [3, 2, 1]
# r = [7, 3, 8]

pattern = r'AC'

m = re.finditer(pattern, text)
position_AC_lst = [x.start() for x in m]
print(position_AC_lst)

for x, y in zip(l, r):
    count = 0
    for i in range(len(position_AC_lst)):
        if x - 1 <= position_AC_lst[i] and position_AC_lst[i] + 1 <= y - 1:
            count += 1

    print(count)

Submission status: Wrong Answer

Solution code:
l, n = input().split(' ')
l = int(l)
n = int(n)
s = input()

c = 'AC'

for i in range(n):
    n1, n2 = input().split(' ')
    n1 = int(n1)
    n2 = int(n2)

    many = 0

    if c in s[n1-1 : n2]:
        many = s[n1-1 : n2].count(c)
        print(many)

Submission status: Wrong Answer

Solution code:
# dp[i]:i文字目までの'AC'の個数
# if a_i='C', a_(i-1)='A':
#     dp[i]=dp[i-1]+1
# else:
#     dp[i]=dp[i-1]
# って感じですかね時間足りない

Submission status: Wrong Answer

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

dp =[[0 for i in range(n)] for j in range(n)]

for j in range(n):
    if s[j]=="C" and j!=0 and s[j-1]=="A":
        for k in range(n):
            if k<=j:
                dp[k][j]=dp[k][j-1]+1 
    else:
        for k in range(n):
            dp[k][j]=dp[k][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:
from sys import stdin
import re
N, Q = (int(i) for i in input().split())
s = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
ms = re.finditer("AC", s)
ml = list(ms)
for i in range(Q):
    count = 0
    for j in range(len(ml)):
        a, b = ml[j].span()
        #print(a, b)
        #print("q", lr[i])
        if lr[i][0]-1 <= a and b <= lr[i][1]:
            count = count +1
            #print("counted")
        if b < lr[i][0]:
            break

    print(count)

Submission status: Wrong Answer

Solution code:
a = input()
b = input()
#print()
#print(a[2])
x = int(a[2])
#print(b)

j=0
while j<x:
    c = input()
    slice = b[int(c[0])-1:int(c[2])]
    #print(slice)
    print(slice.count("AC"))
    #print()
    j+=1

Submission status: Wrong Answer

Solution code:
import re
N, Q = map(int, input().split())
S = input()
l = []
r = []
for i in range(Q):
    li, ri = map(int, input().split())
    l += [li]
    r += [ri]

for ind in range(Q):
    substr = S[max(0, l[ind]-1) : min(r[ind], N)]
    #print(substr.count("AC"))
    print(len(re.findall("AC", S)))

Submission status: Wrong Answer

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

from collections import Counter
for _  in range(Q):
  l, r = map(int,input().split())
  xx = S[l-1:r]
  t = ""
  a = 0
  for k, v in dict(Counter(xx)).items():
    if k== "A":
      t += k
    if k=="C" and t == "A":
      t += k
    if t == "AC":
      a += v
      t = ""
  print(a)

Submission status: Wrong Answer

Solution code:
from sys import stdin

a, b = map(int, input().split())

str = stdin.readline().rstrip()

k = 0

for i in range(b):
    k = 0
    c, d = map(int, input().split())
    arr = []
    snt = ""
    
    aaaa = str[c-1:d]
    print(aaaa)
    for j in aaaa:
        snt = snt + j.replace('\n','')
        
        if len(snt)== 2:
            #print(snt)
            
            if snt == "AC":
                k = k + 1
            snt = snt[-1]
        
        else:
            snt = snt[-1]
            pass
        
    print(k)
    print("-------")

Submission status: Wrong Answer

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

import re
lis = [m.start() for m in re.finditer('AC', s)]
print(lis)

for i in range(q):
    l, r = map(int, input().split())
    s = [i for i in lis if (l-1 <= i) & (i < r-1)]
    print(len(s))

Submission status: Wrong Answer

Solution code:
a = input()
b = input()
print()
print(a[2])
x = int(a[2])
print(b)

j=0
while j<x:
    c = input()
    slice = b[int(c[0])-1:int(c[2])]
    #print(slice)
    print(slice.count("AC"))
    #print()
    j+=1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
        lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    c = d = 0
    while a < N:
        if lst[a] != 0:
            c = lst[a]
            break
        a += 1
    while b > 0:
        if lst[b - 1] != 0:
            d = lst[b - 1]
            break
        b -= 1
    print(max(d - c + 1, 0))

Submission status: Wrong Answer

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

from collections import Counter
for _  in range(Q):
  l, r = map(int,input().split())
  xx = S[l-1:r]
  t = ""
  a = 0
  for k, v in dict(Counter(xx)).items():
    if k== "A":
      t += k
      tmp = v
    if k=="C" and t == "A":
      t += k
      if tmp==v:
        a = v
  print(a)

Submission status: Wrong Answer

Solution code:
n,q = map(int, input().split())
s = input()
ss = s
t = []
for i in range(s.count("AC")):
  try:
  	t.append(ss.index("AC"))
  	ss = ss[ss.index("AC")+2]
  except:
    break
for i in range(q):
  l,r = map(int, input().split())
  print(len([1 for i in t if l <= i and i+1 <= r]))

Submission status: Wrong Answer

Solution code:
N, Q = (int(x) for x in input().split())
S = input()

a_loc = set()
for i in range(len(S)):
    if (S[i] is 'A') and (S[i+1] is 'C'):
        a_loc.add(i)
ans = [0]*Q
for i in range(Q):
    l, r = (int(x) for x in input().split())
    num = 0
    for j in range(l-1, r-1):
        if j in a_loc:
            num += 1
    ans[i] = num

for i in range(Q):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
L=[]
for i in range(N+1):
  L.append(S.count('AC',0,i))
for j in range(Q):
  l,r=map(int,input().split())
  print(L[r]-L[l])
print(L)

Submission status: Wrong Answer

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

# def get_num_AC(ccond, s, count):
#     if s == []:
#         return count
#     if ccond:
#         if s.pop() == 'A':
#             return get_num_AC(False, s, count+1)
#         else:
#             if s == []:
#                 return count
#             else:
#                 return get_num_AC(s.pop() == 'C', s, count)
#     return get_num_AC(s.pop() == 'C', s, count)

def get_substr(s, smaller, larger):
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = substr.count('AC')
    print(count)

Submission status: Wrong Answer

Solution code:
l = []
r = []
n,q = input().split()
N = int(n)
Q = int(q)
S = input()
for i in range(Q):
    L,R = input().split()
    l.append(int(L)-1)
    r.append(int(R)-1)
flag = [0 for i in S]
for i in range(len(S)-1):
    if((S[i] == "A")&(S[i+1] == "C")):
        flag[i] = 1
print(S)
print(flag)
for j in range(Q):
    count = 0
    for i in range(l[j],r[j]):
#        print(i)
        if flag[i] == 1:
           count = count + 1
#    if S[r[j]] == "A":
#        count = count -1
    print(count)

Submission status: Wrong Answer

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

is_ac = [0] * n
count = 0
for i in range(n-1):
  if s[i] == "A":
    if s[i+1] == "C":
      count += 1
  is_ac[i+1] = count
is_ac[-1] = count
print(is_ac)
for item in lr:
  ans = is_ac[item[1]-1] - is_ac[item[0]-1]
  print(ans)

Submission status: Wrong Answer

Solution code:
char_numbers = [int(e) for e in input().split(" ")]

char = input()

questions = []
for i in range(char_numbers[1]):
    questions.append([int(e) - 1 for e in input().split()])

start = [0]

while 1:
    start.append(char.find("AC",start[-1]))
    if start[-1] == -1:
        start[-2] -= 2
        del start[0]
        del start[-1]
        break
    else:
        start[-1] = start[-1] + 2
        start[-2] -= 2 
print(start)
for i in questions:
    n = sum(x>=i[0] and x+1 <= i[1] for x in start)
    print(n)

Submission status: Wrong Answer

Solution code:
def have_AC(str):
    count=0
    for i in range(len(str)-1):
        if(str[i:i+1]=="AC"):
            count=count+1
    return count

n,q=input().split() #nは文字の長さ　qは質問数
s=input() #Sは文字列
n=int(n)
q=int(q)
num=[]

for i in range(q):
    a,b=input().split()
    a=int(a) -1
    b=int(b)
    num.append(have_AC(s[a:b]))

for j in range(len(num)):
    print(num[j])

Submission status: Wrong Answer

Solution code:
def main():
    line = input()
    line = line.split(' ')
    n = int(line[0])
    q = int(line[1])
    s = input()
    num = []
    num = find_ac(s)
    print(num)
    for i in range(0,q):
        line = input() 
        line = line.split(' ')
        l1 = int(line[0])
        l2 = int(line[1])
        print(sum(num[l1:l2]))


def find_ac(s):
    num = []
    cnt = 0
    b_s2 = 'B'
    s = s+'B'
    for s1, s2 in zip(s[0::2],s[1::2]):
        if b_s2 == 'A' and s1 == 'C':
            cnt = 1
        else:
            cnt = 0
        b_s2 = s2
        num.append(cnt)

        if s1 == 'A' and s2 == 'C':
            cnt = 1
        else:
            cnt = 0
        num.append(cnt)

    return num

main()

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for _ in range(Q)]
ans = 0
for i in range(Q):
    a = li[i][0]-1
    b = li[i][1]
    S_a = S[a:b]
    ans += S_a.count("AC")
    ans = 0

Submission status: Wrong Answer

Solution code:
import numpy as np
n, q = map(int, input().split())
s = input()

cnt = 0
mask = np.zeros(n, dtype=int)
for i in range(n-1):
  if s[i:i+2] == "AC":
    mask[i] = cnt
    cnt += 1
    mask[i+1] = cnt
    cnt += 1
  else:
    mask[i] = cnt
mask[n-1] = cnt

for _ in range(q):
  a, b = map(int, input().split())
  if s[a-1] == "C" and s[b-1] == "A":
    print(int((mask[b-1] - mask[a] - 2)/ 2 + 1))
  elif s[a-1] == "C" or s[b-1] == "A":
    print(int((mask[b-1] - mask[a] - 1)/ 2 + 1))
  else:
    print(int((mask[b-1] - mask[a])/ 2 + 1))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
for i in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(n1,n2)

Submission status: Wrong Answer

Solution code:
from sys import stdin

a, b = map(int, input().split())

str = stdin.readline().rstrip()

for i in range(b):
    k = 0
    c, d = map(int, input().split())
    arr = []
    snt = ""
    
    
    for j in str[c-1:d]:
        snt = snt + j.replace('\n','')
        
        if len(snt)== 2:
            print(snt)
            snt = ""
        
        else:
            pass
                    
            
        k = k + 1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
S = input()
p = set()
for n,i in enumerate(S[:-1]):
    if i == "A" and S[n+1]=="C":
        p.add(n)
#print(p)
for i in range(Q):
    a,b = map(int,input().split())
    #tmp = {}
    # tmp = {i for i in range(a-1,b-1)}
    # print(tmp)
    # print(len(tmp&p))
    count=0
    for j in p:
        #print("j",j)
        if a <= j+1 and j+1 < b:
            count+=1
        elif j+1 > b:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    b = S()
    b = b[0]
    if b == "A":
        print("T")
    elif b == "T":
        print("A")
    elif b == "C":
        print("G")
    elif b == "G":
        print("C")
    return

#B
def B():
    s = S()
    agct = ["A", "G", "C", "T"]
    ans = 0
    for num, i in enumerate(s):
        ansb = 0
        if i in agct:
            ansb += 1
            for k in range(num+1, len(s)):
                if s[k] in agct:
                    ansb += 1
                else:
                    break
        ans = max(ans, ansb)
    print(ans)
    return

#C
def C():
    n, q = LI()
    s = S()
    ans = [0 for i in range(n+1)]
    ac = 0
    for num, ss in enumerate(s):
        if not ac and ss == "A":
            ac = 1
            ans[num] = ans[num - 1]
        elif ac and ss == "C":
            ac = 0
            ans[num] = ans[num - 1] + 1
        else:
            ac = 0
            ans[num] = ans[num - 1]
    lr = LIR_(q)
    for l,r in lr:
        print(ans[r]-ans[l])

    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
import numpy as np
import re
from sys import stdin

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()

def func(Str):
  idx = Str.find("AC")
  return idx

i = 0
ac_idx = []
while i<N:
  a = func(S[i:])
  if a != -1:
    ac_idx.append(a+i)
    i = a+i+2
  else:
    break

ac_idx = np.array(ac_idx)
print("ac:",ac_idx)
for j in range(Q):
  l,r = [int(x) for x in stdin.readline().rstrip().split()]
  L = ac_idx >= l-1
  R = ac_idx < r-1
  print(np.sum(np.logical_and(L, R)))

Submission status: Wrong Answer

Solution code:
#8 3
#ACACTACG
#=> ACACxACx
#3 7
#2 3
#1 8
#import time
#start = time.time()

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

p_list=[]
cnt=0

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

#print p_list

p_len = len(p_list)

#print "p_list", p_list

for i in range(Q):
    q_a, q_b = map(int,raw_input().split())
#    print S[q_pos[0]-1:q_pos[1]]

    min_p=0
    max_p=p_len-1

    for i in range(p_len):
#        print "i",i,q_a-1, p_list[i]
        if q_a-1 <= p_list[i]:
            min_p = i
            break

    for j in range(p_len):
#        print "j",j, q_b-1, p_list[p_len - j-1]
        if q_b-1 > p_list[p_len - j-1]:
            max_p = p_len - j-1
            break
#    print min_p, max_p
    cnt = max_p - min_p +1
#    cnt = len([p for p in p_list if (p >= (q_a-1)) and (p <(q_b-1))])

 #    cnt = 0
 #    for p in p_list:
 #        if (p >= (q_a-1)) and (p <(q_b-1)):
 # #            print q_pos[0]-1, p, q_pos[1]-1
 #            cnt += 1
    print cnt

#print format(time.time() - start)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    b = S()
    b = b[0]
    if b == "A":
        print("T")
    elif b == "T":
        print("A")
    elif b == "C":
        print("G")
    elif b == "G":
        print("C")
    return

#B
def B():
    s = S()
    agct = ["A", "G", "C", "T"]
    ans = 0
    for num, i in enumerate(s):
        ansb = 0
        if i in agct:
            ansb += 1
            for k in range(num+1, len(s)):
                if s[k] in agct:
                    ansb += 1
                else:
                    break
        ans = max(ans, ansb)
    print(ans)
    return

#C
def C():
    n, q = LI()
    s = S()
    ans = [0 for i in range(n+1)]
    ac = 0
    for num, ss in enumerate(s):
        if not ac and ss == "A":
            ac = 1
            ans[num] = ans[num - 1]
        elif ac and ss == "C":
            ac = 0
            ans[num] += ans[num - 1] + 1
        else:
            ac = 0
            ans[num] = ans[num - 1]
    lr = LIR_(q)
    for l,r in lr:
        print(ans[r]-ans[l])

    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
import sys

str = []

lines = sys.stdin.readlines()
#print(lines)

for i, nyan in enumerate(lines):
    str.append(nyan.strip("\n"))
#print(nyan[0])

cnt = [0] * int(str[0][2])

for i in range(int(str[0][2])):
  for j in range(int(str[2+i][0]), int(str[2+i][2]), 1):
    if str[1][j-1] == 'A':
      if str[1][j] == 'C':
        cnt[i] += 1
  print(cnt[i])
print('\r\n')

Submission status: Wrong Answer

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

leftmost = n
rightmost = -1
tests = [0] * q
for i in range(q):
	l, r = map(int, input().split())
	leftmost = min(l-1, leftmost)
	rightmost = max(r-1, rightmost)
	tests[i] = [l, r]

positions = []
i = leftmost
while i < rightmost-1:
	if s[i]+s[i+1]=="AC":
		positions.append(i+1)
		i += 1
	i += 1

length = len(positions)

for test in tests:
	l = test[0]
	r = test[1]

	left = 0
	right = length-1
	while left < right:
		current = positions[left]
		if current >= l:
			break
		else:
			left += 1
	while right > left:
		current = positions[right]
		if current < r:
			break
		else:
			right -= 1

	if right == left:
		if positions[right]<r:
			print(1)
		else:
			print(0)
	else:
		print(right-left+1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
ACGT = ("A", "G", "C", "T")
N, Q = map(int, input().rstrip().split())
S = input()
for _ in range(Q):
    l, r = map(int, input().rstrip().split())
    part_S = S[l-1:r]
    
    A_flag = False
    cnt = 0
    for c in part_S:
        if c == "A":
            A_flag = True
        if c == "C" and A_flag:
           cnt += 1
           A_flag = False
        if c != "C" and A_flag:
            A_flag = False
    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)]

for i in range(Q):
    s_tmp = S[max(lr[i][0] - 1, 0):lr[i][1]]
    s_tmp_aft = S[lr[i][1]:]
    s_tmp_aft_2 = S[lr[i][1] - 1:]
    print(s_tmp.count('AC') - max(s_tmp_aft.count('AC'), s_tmp_aft_2.count('AC')))

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)]
rui_count = [0]
AC_k = S.find('AC')
for i in range(1,N):
    if AC_k == -1:
        rui_count += [rui_count[i-1] for j in range(i,N)]
        break
    if AC_k+1 > i or (i==N-1 and S[N-2:N].find('AC')==-1):
        rui_count.append(rui_count[i-1])
        continue
    rui_count.append(rui_count[i-1]+1)
    AC_k = S[i:N].find('AC')+i
count = []
for i in lr:
    count.append(rui_count[i[1]-1]-rui_count[i[0]-1])
for i in count:
    print(i)

Submission status: Wrong Answer

Solution code:
N, Q = [int(n) for n in input().split(' ')]
s = input().strip()

l = []
for i in range(N-1):
    if s[i] == 'A' and s[i+1] == 'C':
        l.append(i)
     
for i in range(Q):
    start, end = [int(n) for n in input().split(' ')]
    count = 0
    for i in l:
        if i>=start or i<=end:
            count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n,q = map(int,input().split())
  
s = list(input())
a = list()

last_s = 'l'

for j in s:
  if last_s == 'A' and j=='C':
    a.append(1)
  else:
    a.append(0)
  last_s = j
print(a)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import re

N,Q = map(int, input().split())
S = input()
itr = re.finditer("AC",S)
li = [i.span() for i in itr]

for i in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for match in li:
    	if l <= int(match[0]) + 1 and int(match[1]) <= r :
            cnt+=1
    print(cnt)

print(li)

Submission status: Wrong Answer

Solution code:
import sys
import bisect

def parse(inp):
    N,Q=map(int,next(inp).split())
    S=list(next(inp))
    
    lr=[[] for _ in range(Q)]
    
    for i in range(Q):
        lr[i]=list(map(int,next(inp).split()))
        
    return N,Q,S,lr
  
def whereAC(S):
    ACpoint=[]
    for i in range(len(S)-1):
        if(S[i]=='A' and S[i+1]=='C'):
            ACpoint.append(i)
            
    return ACpoint
  
def main(inp):
    N,Q,S,lr=inp
#     print(S,lr)
    ACpoint=whereAC(S)
#     print(ACpoint)
    for i in range(Q):
        l,r=lr[i]

        le=min(bisect.bisect_left(ACpoint,l-1),len(ACpoint)-1)
        ge=min(bisect.bisect_left(ACpoint,r-1),len(ACpoint)-1)
        
#         print(le,ge)
        if(le==ge and r-l==1):
            if(S[l-1]=='A' and S[l]=='C'):
                print(1)
            else: print(0)
        else: print(ge-le+1)
          
main(parse(sys.stdin))

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
s = input()
lr = [[int(i) for i in input().split()]for _ in range(q)]
f = 0
si = []
for j,k in enumerate(s):
  if k =='A':
    f = 1
  elif k=='C' and f == 1:
    si.append(j-1)
    f =0
  else:
    f = 0
if len(si)==0:
  for i in range(q):
    print(0)
    exit()
else:
  for i in lr:
    ans = 0
    for j in si:
      if i[0]<=j+1 and j+2<=i[1]:
        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 _ in range(Q)]
for q in range(Q):
    q_lis = S[lr[q][0]:lr[q][1]]
    print(q_lis.count('AC'))

Submission status: Wrong Answer

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

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

ans=[]
for j in range(Q):
    l,r = lr[j][0]-1, lr[j][1]-1
    ans.append(bisect.bisect_right(lst,r) - bisect.bisect_left(lst,l))

for a in ans:
    print(a)

Submission status: Wrong Answer

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

Accumulation = [0]*N
flag = False

if (S[0] == "A"):
    flag = True

for i in range(1,N):
    if (flag):
        if (S[i] == "C"):
            Accumulation[i] = Accumulation[i-1] + 1
            flag = False
            continue
        else:
            flag = False
            Accumulation[i] = Accumulation[i-1]
            continue
    elif (S[i] == "A"):
        flag = True
    Accumulation[i] = Accumulation[i-1]

for eachRange in rangeList:
    tmp = 0
    if (S[eachRange[0]-1] == "C"):
        tmp = 1
    print(Accumulation[eachRange[1]-1] - Accumulation[eachRange[0]-1] - tmp)

Submission status: Wrong Answer

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

ans = []
while len(s) > 0:
  x = s.find('AC')
  c = x
  if x < 0:
    break
  ans.append(c + x)
  s = s[x + 1:]

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

Submission status: Wrong Answer

Solution code:
N,Q = [int(x) for x in input().split()]
S = input()
l = [0]*Q
r = [0]*Q
li = [0]*(N+1)
for i in range(Q):
    l[i],r[i] = [int(x) for x in input().split()]
state = 0
for index,j in enumerate(S):
    li[index+1]=li[index]
    if(state == 0):
        if(j == 'A'):
            state = 1
    elif(state == 1):
        if(j == 'C'):
            li[index+1]+=1
        state = 0

for i in range(Q):
    print(li[r[i]]-li[l[i]])

Submission status: Wrong Answer

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