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()
cnt = [0] * (N)

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

print(cnt)

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

Submission status: Wrong Answer

Solution code:
n, q = map(int,input().split())
s = list(input())
s.append(0)
ans = [0]*(n+1)
flag = 0
for check in range(1,n):
  if s[check-1]=='A' and s[check]=='C':
    ans[check]+=1
  ans[check+1]=ans[check]
print(ans)  
for i in range(q):
  s,e = map(int,input().split())
  print(ans[e-1]-ans[s-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter
import collections
import numpy as np 
from scipy import sqrt, power, exp, log10
from scipy.fftpack import fft, ifft, fftfreq
import tarfile
import re
import os
import glob
from datetime import datetime
import time
import numpy.linalg as LA

round = lambda x:(x*2+1)//2
a,b = list(map(int,input().split()))
S = input()
sub= "AC"
l = np.array([])
for i in range(len(S)):
  S1 = S[:i+1]
  l = np.append(l,S1.count(sub))
print(l)
for i in range(b):
    r,t = list(map(int,input().split()))
    n = l[t-1]-l[r-1]
    print(int(n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - GeT AC
https://atcoder.jp/contests/abc122/tasks/abc122_c
WA
"""
import sys


def main(args):
    N, Q = map(int, input().split())
    S = input()
    ans = [0] * (N + 1)
    for i, a, c in zip(range(2, N), S, S[1:]):
        ans[i] = ans[i-1] + (a == 'A' and c == 'C')
    ans[-1] = ans[-2]

    ans_d = {i:n for i, n in enumerate(ans)}
    for _ in range(Q):
        l, r = map(int, input().split())
        print(ans_d[r] - ans_d[l])


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - GeT AC
https://atcoder.jp/contests/abc122/tasks/abc122_c

"""
import sys


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

    ans = [0] * (N + 1)
    hit = 0
    for i, a, c in zip(range(2, N), S, S[1:]):
        if a == 'A' and c == 'C':
           hit += 1
           ans[i] = hit
        else:
            ans[i] = ans[i-1]
    ans[-1] = ans[-2]
    
    ans_d = {i:n for i, n in enumerate(ans)}
    for _ in range(Q):
        l, r = map(int, input().split())
        print(ans_d[r] - ans_d[l])


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
word_number, questions_number = map(int, input().split())
words = list(input())
questions = []
for question in range(questions_number):
    a,b = map(int, input().split())
    questions.append([a-1, b-1])

for i in range(len(questions)):
    counter = 0
    for j in range(questions[i][0], questions[i][1]):
        # if words[j] == "A" and words[j+1] == "C":
        if words[j: j+2] == "AC":
            counter += 1
    print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re
AC = 'AC'
Q, N = map(int, input().split())
S = str(input())
ans = []
for n in range(N):
  l,r = map(int, input().split())
  l = l - 1
  QS = S[l:r]
  c = re.findall(AC, QS)
  ans.append(len(c))
  for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, Q = map(int, input().split())
s = input()[:-1]
acc = [0]*(N+1)
prev = ""
for i, c in enumerate(s):
    if c == "C" and prev == "A":
        acc[i+1] = 1
    else:
        prev = c
for i in range(len(acc)-1):
    acc[i+1] += acc[i]
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(acc[r]-acc[l])
for a in ans:
    print(a)

Submission status: Wrong Answer

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

counter = 0
lis = [0]*len(s)
for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        counter+=1
    lis[i+1]=counter
print(lis)
for b,e in zip(l,r):
    print(lis[e-1]-lis[b-1])

Submission status: Wrong Answer

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

isa = False
lis = []
for i,t in enumerate(s):
    if t == 'A' and not isa:
        isa = True
    elif isa:
        isa = False
        if t == 'C':
            lis.append(i-1)

for b,e in zip(l,r):
    su = 0
    for i in range(len(lis)):
        if lis[i] >= b-1:
            su = len(lis) - i
            break
    for i in range(1,su+1):
        if lis[-i]+1 <= e-1:
            print(su-(i-1))
            break
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
Q=input()
S=input()
N,Q_num = int(Q.split(" ")[0]),int(Q.split(" ")[1])
AC=[]
for i in range(N):
  if N == i+1:
    AC.append(0)
  elif S[i]=="A" and S[i+1]=="C":
    AC.append(1)
  else:
    AC.append(0)
print(AC)
    
for q in range(int(Q_num)):
  qu = input().split(" ")
  print(sum(AC[int(qu[0])-1:int(qu[1])-1]))

Submission status: Wrong Answer

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

isa = False
lis = []
for i,t in enumerate(s):
    if t == 'A' and not isa:
        isa = True
    elif isa:
        isa = False
        if t == 'C':
            lis.append(i-1)
for b,e in zip(l,r):
    su = 0
    for ll in lis:
        if b-1 <= ll and ll+1 <= e-1:
            su+=1
    print(su)

Submission status: Wrong Answer

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

for i in range(Q):  
  k = 0
  while S.find('AC', lr[i][0], lr[i][1]+1) != -1:
    k += 1
    lr[i][0] += 2
  print(k)

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
lr = [0] * Q
for i in range(Q):
  lr[i] = list(map(int, input().split()))
  k = 0
  while S.find('AC', lr[i][0], lr[i][1]+1) != -1:
    k += 1
    lr[i][0] += 2
  print(k)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
S = input()
d = [0] * n
for i in range(n - 1):
        if S[i]+S[i + 1] == 'AC':
                d[i+1] += 1
print(d)
for i in range(q):
        r,l = map(int,input().split())
        su = 0
        for j in range(r-1,l):
                su += d[j]
        print(su-d[r-1])

Submission status: Wrong Answer

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

t = [0] * (N + 1) 

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

print(t)
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 = input() 

t = [0] * (N + 1) 

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

AC = S.count('AC')

for  q in range(Q):
  si = lr[q][0]+1
  ei = lr[q][1]+1
  start = S[:si]
  end = S[:ei]
  ans = end.count('AC') - start.count('AC')
  print(ans)

Submission status: Wrong Answer

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

AC_list = []
for i in range(len(S)):
    if S[i:i+1] == "AC":
        AC_list.append(i)
    else:
        pass
        
for i in range(Q):
    l, r = map(int,input().split())
    ans = 0
    for j in AC_list:
        if l-1 <= j <= r-2:
            ans += 1
        elif j > r-2:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ans = []
counter = 0
for i in s:
    if i in 'ATGC':
        counter += 1
    else:
        counter = 0
    ans.append(counter)
print(max(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
t = np.zeros(N+1)
for i in range(N):
    t[i+1] = t[i]+(1 if S[i-1:i+1]=='AC' else 0)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-
from sys import stdin

###########################################


############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
data = stdin.readline().split()
N = int(data[0])
Q = int(data[1])

data = str(stdin.readline().split()[0])

question = []
for _ in range(Q):
    a = stdin.readline().split()
    question.append([int(a[0]), int(a[1])])
    
#for x in [2, 4, 8, 16, 32, 64, 128]:
cache = []
for i,q in enumerate(question):
    mydata = data
    b = q[0]
    e = q[1]
    count=0    
    if not i==0:
        for c in cache:
            if c[0]>b and c[1]==e:
                e = c[1]
                count += c[2]
            elif c[0]==b and c[1]<e:
                b = c[0]
                count += c[2]                
    prev=0
    for d in data[q[0]:q[1]]:
        if d=="C" and prev=="A":
            count+=1
        prev=d
    print(count)
    if count > 0:
        cache.append([q[0],q[1],count])

Submission status: Wrong Answer

Solution code:
import re
r = re.compile("AC")

A = input()
A = A.replace("\n", "").split()
A.insert(3, "")
A = [(bb, bc) for bb, bc in zip(A[::2], A[1::2])]
for s, e in A[2:]:
  a = A[1][0][int(s)-1:int(e)]
  print(len(r.findall(a)))

Submission status: Wrong Answer

Solution code:
import re
r = re.compile("AC")

A = input()
A = A.split()
A.insert(3, "")
A = [(bb, bc) for bb, bc in zip(A[::2], A[1::2])]
for s, e in A[2:]:
  a = A[1][0][int(s)-1:int(e)]
  print(len(r.findall(a)))

Submission status: Wrong Answer

Solution code:
import re
r = re.compile("AC")

A = input()
A = A.split()
A.insert(3, "")
A = [(bb, bc) for bb, bc in zip(A[::2], A[1::2])]
c=0
for s, e in A[2:]:
  a = A[1][0][int(s)-1:int(e)]
  c += len(r.findall(a))
  
print(c)

Submission status: Wrong Answer

Solution code:
import re
r = re.compile("AC")

A = input()
A = A.split()
A.insert(3, "")
A = [(bb, bc) for bb, bc in zip(A[::2], A[1::2])]
c=0
for s, e in A[2:]:
  a = A[1][0][int(s)-1:int(e)]
  c = len(r.findall(a))
  
print(c)

Submission status: Wrong Answer

Solution code:
import re
r = re.compile("AC")

A = input()
A = A.split("\n")

c=0
for i in A[2:]:
  s, e = [int(i) for i in i.split(" ")]
  a = A[1][s-1:e]
  c = len(r.findall(a))
  
print(c)

Submission status: Wrong Answer

Solution code:
N, Q = map(int,input().split())
S = list(input())
S.append(0)
par = [0]*(N+1)#par[0]は無視
Ans = []
for i in range(N):
        par [i+1]=par[i]+(1 if (S[i]=='A') & (S[i+1]=='C') else 0)
        print(par)
for i in range(Q):
        x,y = map(int,input().split())
        print(par[y]-par[x-1])

Submission status: Wrong Answer

Solution code:
def get_answer(a, start, end):
    return a[end] - a[start]

def create_answer_array(s):
    result = []
    result.append(0)

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

    return result

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())
    questions.append((a - 1, b - 1))

a = create_answer_array(s)

for question in questions:
    print(get_answer(a, question[0], question[1]))

Submission status: Wrong Answer

Solution code:
def get_answer(s):
    count = 0
    for i, c in enumerate(s):
        if i == len(s) - 1:
            return count
        if c == "A" and s[i + 1] == "C":
            count += 1

    return count

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())
    questions.append((a - 1, b - 1))

for question in questions:
    print(get_answer(s[question[0]: question[1]]))

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
places = []
for i in range(1, n):
  if (s[i - 1:i + 1] == 'AC'):
    places.append(i)
print(places)
for j in range(q):
  l, r = map(int, input().split())
  print(len([p for p in places if ((l <= p) and (p <= r - 1))]))

Submission status: Wrong Answer

Solution code:
Raw = input()
N, Q = int(Raw[0]), int(Raw[-1])
s = input()
for _ in range(Q):
  Raw = input()
  L, R = int(Raw[0]) - 1, int(Raw[-1])
  print(s[L:R].count('AC'))

Submission status: Wrong Answer

Solution code:
N, Q = map(int, raw_input().split())
S = raw_input()
countlist = []
flag = False
cnt = 0
for i in range(0, len(S)):
	if flag:
		if S[i] == 'C':
			cnt += 1
		flag = False
	else:
		if S[i] == 'A':
			flag = True
	countlist.append(cnt)

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

Submission status: Wrong Answer

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

for i in range(Q):
    a.append(list(map(int, input().split())))

for i in range(len(S)):
    an[i+1]=an[i]
    if S[i:i + 2] == "AC":
        an[i+1] += 1
print(an)

for i in range(Q):
    print(an[a[i][1]-1] - an[a[i][0] - 1])

Submission status: Wrong Answer

Solution code:
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_b -d test-b
oj test -d test-c -c "python abc116c.py"
oj test -d test-b -c "python abc116b.py" test-b/sample-3.in
"""

from collections import defaultdict
import sys
import math
import time
import itertools

#累積和
def deco(func):
    def wrapper(*args, **kwargs):
        s = time.time()
        #print('--start--')
        ret = func(*args, **kwargs)
        logging.debug('--end in %f --' % (time.time() - s) )
        return ret
    return wrapper


@deco
def sol(N, Q, S, LR):
    M = [0] * N
    logging.debug("%s, %s, %s, %s, %s" % (N, Q, S, LR, M))
    for i in range(1, N):
        logging.debug("i:%s" % i)
        if S[i-1] + S[i] == "AC":
            M[i] = M[i-1] + 1
        else:
            M[i] = M[i-1]

    A = [0]*Q
    for j in range(Q):
        l, r = int(LR[j][0])-1, int(LR[j][1])-1
        A[j] = M[r] - M[l]

    return A





import logging

#do_submit = False
do_submit = True
if do_submit:
    logging.basicConfig(level=logging.ERROR, format="%(message)s")
else:
    logging.basicConfig(level=logging.DEBUG, format="%(message)s")
def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    (N, Q) = parsed_lines[0]
    N = int(N)
    Q = int(Q)
    S = parsed_lines[1][0]
    # return (n, S)
    LR = []
    for i in range(2, 2+Q):
        l , r = int(parsed_lines[i][0]), int(parsed_lines[i][1])
        LR.append((l, r))
    return (N, Q, S, LR)

do_submit = False

if not do_submit:
    # n, S= input_parse("""
    # 4
    # 1 2 2 1
    # """)
    (N, Q, S, LR) = input_parse("""
    8 3
    ACACTACG
    3 7
    2 3
    1 8
    """)
    for a in sol(N, Q, S, LR):
        print (a)


else:
    str = ""
    NQ = input().strip()
    N, Q= list(map(int, NQ.split()))
    str += NQ + "\n"
    str += input().strip() + "\n"# S
    for i in range(Q):
        str += input().strip() + "\n" # l, r
    (N, Q, S, LR) = input_parse(str)
    #print(sol(N, Q, S, LR))
    for a in sol(N, Q, S, LR):
        print (a)

Submission status: Wrong Answer

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

t = [0] * N
a = [0] * N

for i in range(0, N - 2):
    if S[i] == 'A' and S[i + 1] == 'C':
        t[i] = 1

a[0] = 0
for i in range(N - 1):
    a[i + 1] = a[i] + t[i]

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

Submission status: Wrong Answer

Solution code:
def get_answer(s):
    count = 0
    for i, c in enumerate(s):
        if i == len(s) - 1:
            return count
        if c == "A" and s[i + 1] == "C":
            count += 1

    return count

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())

    questions.append((a - 1, b - 1))

for question in questions:
    print(get_answer(s[question[0]: question[1]]))

Submission status: Wrong Answer

Solution code:
a, loop = input().split()
string = input()

for i in range(int(loop)):
  j, k = input().split()
  print(string[int(j)-1:int(k)-1].count('AC'))

Submission status: Wrong Answer

Solution code:
a, loop = input().split()
string = input()

for i in range(int(loop)):
  j, k = input().split()
  print(string[int(j):int(k)].count('AC'))

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
arr=[]
arr.append(0)
# arr.append(0)
for i in range(len(s)):
	if i+2<len(s):
		xx=s[i:i+2]
		if xx=='AC':
			arr.append(1)
		else:
			arr.append(0)
arr.append(0)
# print(arr)
prefix=[0]*(len(arr))
prefix[0]=arr[0]
for i in range(1,len(arr)):
	prefix[i]=prefix[i-1]+arr[i]
for ii in range(q):
	l,r=map(int,input().split())
	l-=1
	r-=1
	# print(l,r)
	print(prefix[r]-prefix[l])

Submission status: Wrong Answer

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

ACList = list()
prevA = False
accum = 0
for i in range(N):
    if prevA and S[i] =='C':
        accum += 1
    if S[i] == 'A':
        prevA = True
    ACList.append(accum)

for i in range(Q):
    print( ACList[li[i][1]-1] - ACList[li[i][0]-1] )

Submission status: Wrong Answer

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

ACList = list()
prevA = False
accum = 0
for i in range(N):
    if prevA:
        if S[i] == 'C':
            accum += 1
            prevA = False
        elif S[i] == 'A':
            prevA = True
    else:
        if S[i] == 'A':
            prevA = True
    ACList.append(accum)

for i in range(Q):
    print( ACList[li[i][1]-1] - ACList[li[i][0]-1] )

Submission status: Wrong Answer

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

ACList = list()
prevA = False
accum = 0
for i in range(N):
    if prevA:
        if S[i] == 'C':
            accum += 1
            prevA = False
        elif S[i] == 'A':
            prevA = True
    else:
        if S[i] == 'A':
            prevA = True
    ACList.append(accum)
print(ACList)

for i in range(Q):
    print( ACList[li[i][1]-1] - ACList[li[i][0]-1] )

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
st = input()
questions = [tuple(map(int, input().split())) for i in range(q)]
lis = []
cnt = 0
for i in range(len(st)-1):
    if st[i-1:i+1] == 'AC':
        cnt += 1
    lis.append(cnt)
lis.append(cnt)
for l, r in questions:
    print(lis[r-1] - lis[l-1])

Submission status: Wrong Answer

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

cum=[0]*n
for i in range(1, n):
    cum[i] = cum[i - 1]
    if s[i-1:i+1] == 'AC':
        cum[i]+=1
    print(cum)

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

Submission status: Wrong Answer

Solution code:
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input().strip())
        n = 0
        for i in range(l-1, r-2):
            if s[i] == 'A' and s[i+1] == 'C':
                n += 1
                i += 1
        res = res + "\n" + str(n)

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input().strip())
        n = 0
        for i in range(l-1, r-2):
            if s[i] == 'A' and s[i+1] == 'C':
                n += 1
                i += 1
        # res = res + "\n" + n

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input().strip())
        n = 0
        # for i in range(l-1, r-1):
        #     if s[i] == 'A' and s[i+1] == 'C':
        #         n += 1
        #         i += 1
        # res = res + "\n" + n

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l= [input().split() for _ in range(Q)]
v = [a[i:i+2] for i in range(N-1)]

count=0
for v in "AC":
    count+=1

print(count)

Submission status: Wrong Answer

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

c = [0] * N

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

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

Submission status: Wrong Answer

Solution code:
 # -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n,q=map(int, io().split())
	s=list(io())
	
	ss=[0 for _ in s]
	sss=ss.copy()
	for i, c in enumerate(s[1:]):
		if s[i-1]=='A' and s[i]=='C':
			ss[i]=1
		sss[i] = ss[i] + sss[i-1]
	
	for i in range(q):
		r,l=map(int, io().split())
		#rr=sum(ss[r-1:l])-ss[l-1]
		rr=sss[l-1]-sss[r-1]
		#ret.append(str(rr))
		print(rr)
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n,q=map(int, io().split())
	s=list(io())
	
	ss=[0 for _ in s]
	for i, (c, cn) in enumerate(zip(s, s[1:])):
		if c=='A' and cn=='C':
			ss[i]=1
	print(ss)
	#ret=[]
	for i in range(q):
		r,l=map(int, io().split())
		rr=sum(ss[r-1:l])-ss[l-1]
		#ret.append(str(rr))
		print(rr)
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

Submission status: Wrong Answer

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

t=[0]*n

s=s.replace("AC", "Ac")
#s=s.translate(str.maketrans({'AC':'aC'})) maketransは置換元一文字じゃないといけんみたい
for i in range(n):
  if s[i] == "c":
    if i !=0:
      t[i]=1+t[i-1]
    else:
      t[i]=1
  else:
    t[i]=t[i-1]

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

Submission status: Wrong Answer

Solution code:
import re
N, Q = map(int, input().split())
S = input()
o = [m.start() for m in re.finditer('AC', S)]
le = len(o)
for _ in range(Q):
	l, r = map(lambda x: int(x) - 1, input().split())
	L = 0
	R = 0
	for i in range(le):
		if o[i] >= l:
			L = i
			break
	for i in range(le - 1, -1, -1):
		if o[i] < r:
			R = i
			break
	print(R - L + 1)

Submission status: Wrong Answer

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

m = []
total = 0
b = False

for c in s:
    if c == 'A':
        b = True
    elif c == 'C' and b:
        total += 1
        b = False
    else:
        b = False
    m.append(total)

print(m)

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

n, q = map(int, input().split(" "))
s = input()
cnt = 0
place_of_AC = [0] * n

for i in range(len(s) - 1):
  place_of_AC[i]=cnt
  if s[i:i+2] == "AC":
    cnt += 1


print(place_of_AC)
  
for _ in range(q):
  l, r = map(int, input().split(" "))
  out = place_of_AC[r-1] - place_of_AC[l-1]
  print(out)

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = []

for i in range(n):
    if s[i] == "A":
        flag = True
    if s[i] == "C" and flag is True:
        count += 1
        flag = False
    li.append(count)

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

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = [0]

for i in s:
    if i == "A":
        flag = True
    if i == "C" and flag is True:
        count += 1
        flag = False
    li.append(count)

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

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
l,r = [],[]
index = []
for i in range(Q):
    tmp1,tmp2 = map(int,input().split())
    l.append(tmp1)
    r.append(tmp2)
counter = 0
index.append(counter)
for i in range(1,len(S)):
    if(S[i-1] == 'A' and S[i] == 'C'):
        counter += 1
    index.append(counter)
print(index)
def f(l,r):
    return index[r-1] - index[l-1]
for i in range(Q):
    print(f(l[i],r[i]))

Submission status: Wrong Answer

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			flag += 1
			
		elif ((S[s-1] == 'C') and (flag == 1)):
			flag += 1
			
		elif (flag == 1):
			flag = 0
		
		if flag == 2:
			count += 1
			flag = 0
			
	print(count)
	
	count = 0
	flag = 0

Submission status: Wrong Answer

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			flag += 1
			
		elif ((S[s-1] == 'C') and (flag == 1)):
			flag += 1
			
		elif (flag == 1):
			flag = 0
		
		if flag == 2:
			count += 1
			flag = 0
			
	result.append(count)
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
a = [0] * len(s)
a[1] = 1 if a[:2] == 'AC' else 0
for i in range(2, len(s)):
  a[i] = a[i - 2] + 1 if a[i - 1:i + 1] == 'AC' else a[i - 1]
while q > 0:
  q -= 1
  l, r = map(int, input().split())
  print(a[r - 1] - a[l - 1])

Submission status: Wrong Answer

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			flag += 1
			
		elif ((S[s-1] == 'C') and (flag == 1)):
			flag += 1
			
		else:
			flag = 0
		
		if flag == 2:
			count += 1
			flag = 0
			
	result.append(count)
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
a = [0] * len(s)
a[1] = 1 if a[:2] == 'AC' else 0
for i in range(2, len(s)):
  a[i] = a[i - 2] + 1 if a[i - 1:i + 1] == 'AC' else a[i - 2]
while q > 0:
  q -= 1
  l, r = map(int, input().split())
  print(a[r - 1] - a[l - 1])

Submission status: Wrong Answer

Solution code:
import bisect

N, Q = list(map(int, input().split()))
S = list(input())
S2 = []
for i in range(N - 1):
    if S[i] == "A" and S[i + 1] == "C":
        S2.append(i)

for i in range(Q):
    l, r = list(map(int, input().split()))
    L = bisect.bisect_right(S2, l)
    R = bisect.bisect_left(S2, r - 1)
    print(R - L + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,q = list(map(int,input().split()))
s = list(input())
num = list()
check = [0]*n
for i in range(0,n-1):
        if s[i] == "A" and s[i+1] == "C":
                check[i] = check[i-1]+1
        else:
              check[i] =check[i-1] 
ans = 0
for i in range(0,q):
        num = list(map(int,input().split()))
        ans = check[num[1]-2]-check[num[0]-1]
        print(ans)

Submission status: Wrong Answer

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

cnt_list = [0]*n
judge = 0

for i in range(n):
    if s[i] == "A":
        judge = 1
        if i != 0:
            cnt_list[i] = cnt_list[i-1]
    elif judge == 1 and s[i] == "C":
        judge = 0
        cnt_list[i] = cnt_list[i-1] + 1
    else:
        cnt_list[i] = cnt_list[i-1]

for i in range(q):
    print(cnt_list[quiz[i][1] - 1] - cnt_list[quiz[i][0]-1])