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:
# -*- coding: utf-8 -*-
import sys
import collections
import re
import copy

def main():
	N, Q = map(int, input().split(" "))
	S = input()
	S = list(S)
	pattern = r"AC"
	
	Qs = []
	for _ in range(Q):
		l, r = map(int, input().split(" "))
		Qs.append((l, r))
	
	ans = []
	for i, val in enumerate(Qs):
		l, r = val
		tmp = S[l-1:r]
		#matchedList = re.findall(pattern, "".join(tmp))
		
		ans.append(tmp)
	
	
	for i in ans:
		print(i)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n, q = map(int, input().split())
s = input()
ac_list = np.array([0]*len(s))
i = 0
'''while True:
    ac_index = s[i:].find("AC")
    if ac_index == -1:
        break
    else:
        ac_list[ac_index+i] = 1
        i = ac_index + i + 2'''

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

print(ac_list)
for _ in range(q):
    lr = tuple(map(int, input().split()))
    print(ac_list[lr[1]-1] - ac_list[lr[0]-1])

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

N, Q = map(int, input().split())
S = input()
ac = [0] * N
for i in range(N-1):
    if S[i:i+2] == 'AC':
        ac[i] = 1

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
inputl = []
inputr = []
for i in range(0,Q):
    l,r = map(int, input().split())
    inputl.append(l)
    inputr.append(r)
answerlist = []
for j in range(0,Q):
    l = inputl[j]
    r = inputr[j]
    appear = 0
    k = 0
    while(l+k+1<r):
    #for k in range(0,N):
        k = k+1
        if(S[l+k-1:l+2+k-1] == 'AC'):
            appear = appear +1
    answerlist.append(appear)
for p in range(0,Q):
    print(answerlist[p])

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
#s=list(input())	
s = input()
index = -1
indexes = []
while True:
    index = s.find("AC", index + 1)
    if index == -1:
        break
    indexes.append(index)

for i in range(q):
    l,r = map(int,input().split())
    ans1 = -1
    ans2 = len(indexes) + 1
    for j in range(len(indexes)):
        if(l -1 <= indexes[j] and ans1 == -1):
            ans1 = j
        if (r < indexes[j]+2):
            ans2 = j
            break
    if (ans1 == -1):
        ans2 = -1
    print(ans2-ans1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import collections
import re
import copy

def main():
	N, Q = map(int, input().split(" "))
	S = input()
	S = list(S)
	pattern = r"AC"
	
	Qs = []
	for _ in range(Q):
		l, r = map(int, input().split(" "))
		Qs.append((l, r))
	
	ans = []
	for i, val in enumerate(Qs):
		l, r = val
		#tmp = S[l-1:r]
		matchedList = re.findall(pattern, "".join(S))
		
		ans.append(len(matchedList))
	
	
	for i in ans:
		print(i)
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
#s=list(input())	
s = input()
index = -1
indexes = []
while True:
    index = s.find("AC", index + 1)
    if index == -1:
        break
    indexes.append(index)

for i in range(q):
    l,r = map(int,input().split())
    ans1 = 0
    ans2 = len(indexes) + 1
    for j in range(len(indexes)):
        if(l -1 <= indexes[j] and ans1 == 0):
            ans1 = j
        if (r < indexes[j]+2):
            ans2 = j
            break
    if (ans1 == 0):
        ans2 = 0
    print(ans2-ans1)

Submission status: Wrong Answer

Solution code:
import bisect
N,Q=list(map(int,input().split()))
S=input()
place=[]
for i in range(0,len(S)-1):
    if S[i:i+2]=='AC':
        place.append(i+2)

for i in range(Q):
    frm,to=list(map(int,input().split()))
    if to-frm<=1:
        print(0)
    else:
        f=bisect.bisect_left(place,frm)
        t=bisect.bisect_right(place,to)
        print(t-f)

#print(place)

Submission status: Wrong Answer

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input()
    inlist = [line.split(' ') for line in open(0).read().split('\n')]

    try:
        for start, stop in inlist:
            start = int(start)-1
            stop = int(stop)
            s = S[start:stop]
            print(s.count('AC'))
    except Exception:
        pass


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
N,Q=list(map(int,input().split()))
S=input()
place=[]
for i in range(0,len(S)-1):
    if S[i:i+2]=='AC':
        place.append(i+2)

for i in range(Q):
    frm,to=list(map(int,input().split()))
    if to-frm<=1:
        print(0)
    else:
        f=bisect.bisect_left(place,frm)
        t=bisect.bisect_left(place,to)
        if(t<len(place) and place[t]==to):
            t+=1
        print(t-f)

#print(place)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import bisect

n, q = map(int, raw_input().split())
s = raw_input()
i_list = []
i = -1
while True:
    i = s.find("AC", i+1)
    if(i == -1): break
    i_list.append(i)
print(i_list)
for i in range(q):
    a, b = map(int, raw_input().split())
    a = bisect.bisect_left(i_list, a-1)
    b = bisect.bisect_left(i_list, b-1)
    print(b-a)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
#s=list(input())	
s = input()
index = -1
indexes = []
while True:
    index = s.find("AC", index + 1)
    if index == -1:
        break
    indexes.append(index)

for i in range(q):
    l,r = map(int,input().split())
    ans1 = 0
    ans2 = len(indexes) + 1
    for j in range(len(indexes)):
        if(l -1 <= indexes[j] and ans1 == 0):
            ans1 = j
        if (r < indexes[j]+2):
            ans2 = j
            break
    print(ans2-ans1)

Submission status: Wrong Answer

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

check_point = []
check = 0
inf = 10

# AC文字列のAの位置をリストに収めた
for i in range(inf):
  out = S.find('AC')
  if out < 0:
    break
  else:
    S = S[out+2:]
    check_point.append(out + len(check_point) * 2)
  

# 指定した文字列範囲を含む要素数を表示
for i in range(Q):
  start, end  = map(int,input().split())
  list_match = [i for i in check_point if i < end]
  out = len(list_match)
  print(out)

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, q = ip.IL()
    s = ip.S()
    # lr = ip.SILS(q)

    li = [i for i in r(n - 2) if s[i] == "A" and s[i + 1] == "C"]

    for _ in r(q):
        x, y = ip.IL()
        x -= 1
        y -= 1
        if (y - x) % 2 != 0:
            y -= 1
        print(sum(1 for z in li if x <= z <= y))


main()

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
#s=list(input())	
s = input()
index = -1
indexes = []
while True:
    index = s.find("AC", index + 1)
    if index == -1:
        break
    indexes.append(index)
print(indexes)

for i in range(q):
    l,r = map(int,input().split())
    ans1 = 0
    ans2 = len(indexes) + 1
    for j in range(len(indexes)):
        if(l -1 <= indexes[j] and ans1 == 0):
            ans1 = j
        if (r < indexes[j]+2):
            ans2 = j
            break
    print(ans2-ans1)

Submission status: Wrong Answer

Solution code:
def count_ac(rawlist,l,r):
    cnt = 0
    sliced_list = rawlist[l-1:r+1]
    for idx,char in enumerate(sliced_list):
        if idx == len(sliced_list)-1:
            break
        if sliced_list[idx] == "A":
            if sliced_list[idx+1] =="C":
                cnt += 1

    print(cnt)

n,q = map(int,input().split())
s = list(input())
for i in range(q):
    li,ri = map(int,input().split())
    count_ac(s,li,ri)

# testlist = ["A","C","D","A","C"]
# l=1
# r=5
# print(testlist[0:6])
# count_ac(testlist,l,r)

Submission status: Wrong Answer

Solution code:
import sys

_ = input()
S = input().strip()
idx = [i+1 for i in range(len(S)-1) if S[i:i+2] == 'AC']
print(idx)

for line in sys.stdin:
  l,r = list(map(int, line.strip().split(' ')))
  print(sum([1 for i in idx if l <= i <= r-1]))

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
ss = 0
ans = 0
left = 0
right = 0
acplace = []
for i in range(q):
    a.append(list(map(int, input().split())))
for j in range(n-1):
    if s[j] == 'A' and s[j+1] == 'C':
        acplace.append(j)
len_acplace = len(acplace)
for k in range(q):
    left = a[k][0]-1
    right = a[k][1]
    for aa in range(len_acplace):
        if acplace[aa] >= left:
            ss = aa
            break
    for aa in range(ss, len_acplace):
        if acplace[aa]+1 < right:
            ans += 1
        else:
          break
    print(ans)
    ans = 0
    ss = 0

Submission status: Wrong Answer

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

q=[]
for i in range(Q):
    a,b=map(int,input().split())
    q.append([a,b])
kekka=[0]*N

#print(S)
for i in range(N-1):
    if S[i]=="A"and S[i+1]=="C":
        kekka[i]=1
print(kekka)
for i in range(Q):
    print(sum(kekka[q[i][0]-1:q[i][1]-1]))

Submission status: Wrong Answer

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

C = [0]

cnt = 0
flg = False
for s in S:
  if flg:
    if s == 'C':
      cnt += 1
    flg = False
  elif s == 'A':
    flg = True
  C.append(cnt)

for i in range(Q):
  l, r = map(int, input().split())
  ans = C[r] - C[l-1]
  if l-2 >= 0 and S[l-1] == 'C' and S[l-2] == 'A':
    ans -= 1
  print(ans)

Submission status: Wrong Answer

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

for i in range(q):
  last_s = ''
  l,r = map(int,input().split())
  
  for j in s[l-1:r]:
    print(j,end='')
    if last_s == 'A' and j=='C':
      ans += 1
    last_s = j
    
  print("\t :",ans)
  ans = 0

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import bisect

n, q = map(int, raw_input().split())
s = raw_input()
i_list = []
i = 0
while True:
    i = s.find("AC", i+1)
    i_list.append(i)
    if(i == -1): break
for i in range(q):
    a, b = map(int, raw_input().split())
    a = bisect.bisect_left(i_list, a-1)
    b = bisect.bisect_left(i_list, b-1)
    print(b-a)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

idx = -1
idxList = []
while True:
    idx = S.find('AC', idx + 1)
    if idx == -1:
        break
    idxList.append(idx)

idxList = np.array(idxList)
ans = []

for q in range(Q):
    l, r = map(int, input().split())
    ans.append(np.sum((l-1 <= idxList) & (idxList < r-1)))

print(idxList)

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
NandQ=input() #文字列の長さ＆質問の個数
S=str(input()) #文字列
ListNandQ=NandQ.split()
N=int(ListNandQ[0])
Q=int(ListNandQ[1])
for i in range(0,Q,1):
  LandR=input() #質問の入力受付
  ListLandR=LandR.split()
  L=int(ListLandR[0])
  R=int(ListLandR[1])
  moji=S[L-1:R-1] #文字列の取り出し
  print(int(moji.count("AC")))

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = str(input())
leng=len(S)
for i in range(Q):
    l, r = map(int, input().split())
    slice = S[l-1:r]
    po=slice.replace("AC","")
    le=len(po)

    print(int((leng-(r-l+1)+le)/2))

Submission status: Wrong Answer

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

answerlist = []
for j in range(0,Q):
    l = inputl[j]
    r = inputr[j]
    appear = 0
    for k in range(0,N):
        if(S[l+k-1:l+2+k-1] == 'AC'):
            appear = appear +1
        if(l+2+k-1 == r):
            answerlist.append(appear)
            break
    

for p in range(0,Q):
    print(answerlist[p])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = list(str(input()))
agct = {'A', 'C', 'G', 'T'}

ans_list = []
fa = 0
ans = 0
for index, s in enumerate(S):
    if s == 'A' and fa == 0:
        fa = 1
        ans_list.append(ans)
    elif s == 'C' and fa == 1:
        fa = 0
        ans += 1
        ans_list.append(ans)
    else:
        fa = 0
        ans_list.append(ans)

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

Submission status: Wrong Answer

Solution code:
S = input()
ACGT = ["A","C","G","T"]
index = []
for i in range(len(S)):
    if S[i] not in ACGT:
        index.append(i)


if index:#一致しない文字列が存在
    diff = [index[0]]
    for j in range(len(index)-1):
        diff.append(index[j+1] - index[j] - 1)
    print(max(diff))
    
else:#一致しない文字列が存在しない
    print(len(S))

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, q = ip.IL()
    s = ip.S()
    lr = ip.SILS(q)

    li = []
    for i in r(n):
        if s[i] == "A" and s[i + 1] == "C":
            li.append(i)

    for i in r(q):
        x, y = lr[i][0], lr[i][1]
        x -= 1
        y -= 1
        if (y - x) % 2 != 0:
            y -= 1
        c = sum(1 for z in li if x <= z <= y)
        print(c)


main()

Submission status: Wrong Answer

Solution code:
N,Q=list(map(int,input().split()))
S=input()
place=[0]*(N+2)
for i in range(0,len(S)-1):
    if S[i:i+2]=='AC':
        place[i+2]+=1
        
for i in range(N+1):
    place[i+1]=place[i]+place[i+1]
for i in range(Q):
    frm,to=list(map(int,input().split()))
    if to-frm<=1:
        print(0)
    else:
        print(place[to]-place[frm-1])

#print(place)

Submission status: Wrong Answer

Solution code:
import re
N, Q = map(int, input().split())
S = input()
indices = [m.start(0) for m in re.finditer("AC", S)]
print(indices)
for _ in range(Q):
    li, ri = map(int, input().split())
    print(len([x for x in indices if li - 1 <= x and x < ri - 1]))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
input = sys.stdin.readline
def 解():
    N,Q=[int(_) for _ in input().split()]
    S = input()
    #aA = []
    aC = [-1]
    iC = 0
    bF = False
    for s in S:
        iC += 1
        if s == 'A':
            if bF:
                bF = False
            bF = True
        elif s == 'C' :
            if bF:
            #   aA.append(iC-1)
                aC.append(iC)
        else:
            bF = False

    aC.append(10**9)
    aAns = []
    for _ in range(Q):
        l,r = [int(_) for _ in input().split()]
        iL = bisect.bisect_left(aC,l)
        if l == aC[iL]:
            iL += 1
        iR = bisect.bisect_left(aC,r)
        if aC[iR] <= r:
            iR += 1
        aAns.append(iR-iL)
    print(*aAns,sep="\n")
解()

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)]
l = [e[0]-1 for e in lr]
r = [e[1]-1 for e in lr]

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

for i in range(q):
	print(account[r[i]] - account[l[i]])

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)]
P=[]
for k, j in enumerate(S[:-1]):
        if j=="A" and S[k+1]=="C":
            P.append(1)
        else:
            P.append(0)
for i in L:
    res=0
    res=sum(P[i[0]-1:i[1]])
    '''
    for j in P:

        if(j>=i[0] and j<i[1]):
            flag=1
            res+=1
        else:
            if(flag==1):
                break
        '''
    print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,Q = map(int, lines.pop(0).split(' '))
    S = lines.pop(0)
    NLIST = []
    for i in range(Q):
        a,b = map(int, lines.pop(0).split(' '))
        NLIST.append((a,b))
    sums = [0]
    res = 0
    for i in range(N-1):
        if S[i:i+2] == 'AC':
            res += 1
        sums.append(res)
    print(sums)
    for k in NLIST:
        i = max( k[0] - 1, 0)
        j = k[1] - 1
        print(sums[j] - sums[i])
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Wrong Answer

Solution code:
def countAC(s):
    index = []
    for i in range(len(s)):
        if i == len(s)-1:
            break
        if s[i] == 'A':
            if s[i+1] == 'C':
                index.append(1)
                continue
        index.append(0)
    return index

N,Q = (int(_) for _ in input().split())
S = input()
SIndex = countAC(S)
out = 0
for i in range(Q):
    l,r = (int(_) for _ in input().split())
    print(SIndex)
    s = SIndex[l-1:r-1]
    print(s)
    for x in s:
        out += x
    print(out)
    out = 0

Submission status: Wrong Answer

Solution code:
import itertools

N,Q = map(int,input().split())
S = input()
info = [[int(e)-1 for e in input().split()] for _ in range(Q)]
note = [0]*(N)
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        note[i] = 1
note = list(itertools.accumulate(note))
for l,r in info:
    if l == 0:
        ans = note[r]
    else:
        ans = note[r] - note[l-1]
        if S[l-1] == "A":
            ans -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = [str(i) for i in input()]

d = [[int(i) for i in input().split()] for i in range(b)]

ans = 0
#print(d[1][0])

for i in range(b):
    for j in range(d[i][0]-1,d[i][1]-1):
        if c[j] == "A" and c[j+1] == "C":
            ans+=1
    print(ans)
    ans=0
    exit()

Submission status: Wrong Answer

Solution code:
n,q=map(int, input().split())
S = input()
e = [[int(i) for i in input().split()] for i in range(q)] 
for i in range(q):
    ans=0
    for a in range(e[i][0],e[i][1]-1):
        if S[a] == "A" and S[a+1] == "C":
            ans += 1
    print(ans)

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())
count = 0
c_sum = [0]*n
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    count += 1
  c_sum[i] = count
print(c_sum)
for i in range(q):
  print(c_sum[r[i]-2] - c_sum[l[i]-2])

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

ss = ""
array = defaultdict(int)
for i in range(n):
    if s[i] == "A":
        ss += s[i]
    elif s[i] == "C":
        ss += s[i]
    else:
        ss = ""
    if ss == "AC":
        array[i] += 1
        ss = ""
for i in range(q):
    a, b = map(int, input().split())
    count = 0
    for ar in array:
        if ar > b:
            break
        if ar >= a and ar < b:
            count += 1
    print(count)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N,Q=list(map(int,input().split()))
S=input()
place=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i:i+2]=='AC':
        place[i+2]+=1
for i in range(N):
    place[i+1]=place[i]+place[i+1]
for i in range(Q):
    frm,to=list(map(int,input().split()))
    if to-frm<=1:
        print(0)
    else:
        print(place[to]-place[frm-1])

Submission status: Wrong Answer

Solution code:
import sys

l = raw_input().split()
N = int(l[0])
Q = int(l[1])
l = raw_input().split()
S = l[0]

L = [0]*Q
R = [0]*Q

ac = 'AC'

for i in range(Q):
    l = raw_input().split()
    L[i] = int(l[0])
    R[i] = int(l[1])

#print(N,Q,S,L,R)

def count(S, table):
    length = len(S)
    c = 0
    for i in range(length - 1):
        # print(S[i:i+2])
        if ac == S[length - i - 2:length - i]:
            c += 1
        table[i+1] = c

length_S = len(S)
table = [0]*length_S

count(S, table)
print(table)

for i in range(Q):
    print(table[length_S - L[i]] - table[length_S - R[i]])

Submission status: Wrong Answer

Solution code:
import bisect

Submission status: Wrong Answer

Solution code:
a = input().split()
a = list(map(int, a))
b = input()
c = [0] * a[1]
d = [0] * a[1]
for n in range(a[1]):
	c[n] = input().split()
	c[n] = list(map(int, c[n]))
	flag = False
	count = 0
	for i in range(c[n][1]-c[n][0]):
		if flag == True:
			if b[c[n][0]+i-1] == "C":
				count += 1
		if b[c[n][0]+i-1] == "A":
			flag = True
		else:
			flag = False
	d[n] = count
for z in range(len(d)):
	print(d[z])

Submission status: Wrong Answer

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

S = list(input())

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

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

Submission status: Wrong Answer

Solution code:
import bisect
N,Q=list(map(int,input().split()))
S=input()
place=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i:i+2]=='AC':
        place[i+1]+=1
        
for i in range(N):
    place[i+1]=place[i]+place[i+1]
for i in range(Q):
    frm,to=list(map(int,input().split()))
    if to-frm<=1:
        print(0)
    else:
        print(place[to]-place[frm-1])

Submission status: Wrong Answer

Solution code:
def counter(n, m):
	c = 0
	for o in range(n-1, m-1):
		if S[o] == "A":
			if S[o+1] == "C": 
				c = c+1
	print(c)
	return c
N, Q = map(int, input().split())
A = input()
S = [str(c) for c in A]
x = []
y = []
for i in range(Q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
for i in range(Q):
	print(counter(x[i], y[i]))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import re
N, Q = map(int, input().split())
S = input()
indices = [(m.start(0), m.end(0)) for m in re.finditer("AC", S)]

for _ in range(Q):
    li, ri = map(int, input().split())
    print(len([x for x in indices if x[0] >= li - 1 and x[0] <= ri - 1]))