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 = 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
        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])

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n, q = map(int, input().split())
s = input()
L = [0]*n
for i in range(1, n-1):
    if(s[i-1:i+1] == 'AC'):
        L[i] = 1
c = list(accumulate(L))
for i in range(q):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [1 if S[j:j+2] == "AC" else 0 for j in range(N)]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum(t[l-1:r])))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [1 if S[j:j+2] == "AC" else 0 for j in range(N)]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(np.sum(t[l-1:r]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [1 if S[j:j+2] == "AC" else 0 for j in range(N)]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(t[r-1]-t[l-1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
# print(N, Q)
S = li()
Alist = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    l, r = mi()
#     if AClist[l - 1] != AClist[l]:
#         print(AClist[r] - AClist[l])
#     else:
#         print(AClist[r] - AClist[l-1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
# print(N, Q)
S = li()
Alist = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
# for i in range(N - 1):
#     if i in Alist:
#         AClist[i + 2] = AClist[i+1] + 1
#     else:
#         AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    l, r = mi()
#     if AClist[l - 1] != AClist[l]:
#         print(AClist[r] - AClist[l])
#     else:
#         print(AClist[r] - AClist[l-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for j in range(l-1, r-2) if S[j:j+2] == "AC"])))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
# print(N, Q)
S = li()
Alist = []
# for i in range(N - 1):
#     if S[i] == 'A' and S[i + 1] == 'C':
#         Alist.append(i)
# AClist = [0]*(N+1)
# for i in range(N - 1):
#     if i in Alist:
#         AClist[i + 2] = AClist[i+1] + 1
#     else:
#         AClist[i+2] = AClist[i+1]

# print(AClist)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for j in range(l-1, r) if S[j:j+2] == "AC"])))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for i in range(len(S[l-1:r])) if S[i:i+2] == "AC"])))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for i in range(len(S[l:r+1])) if S[i:i+2] == "AC"])))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for i in range(len(S[l:r])) if S[i:i+2] == "AC"])))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for i in range(len(S)) if S[i:i+2] == "AC"])))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for i in range(len(S)) if S[i:i+1] == "AC"])))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(np.sum([1 for i in range(len(S)) if S[i:i+1] == "AC"]))

Submission status: Wrong Answer

Solution code:
from itertools import*
a,b=map(int,input().split())
s=input()
table=[0]*(a-1)
for i in range(a-2):
    if s[i:i+2]=="AC":
        table[i]=1
x=[0]+list(accumulate(table))
#print(x)
for i in range(b):
    c,d=map(int,input().split())
    print(x[d-1]-x[c-1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = [0]*(N+1)
#"AC"が何文字目か判断
terget = "AC"
index = -1
for i in range(N):
    C[i+1] = C[i] + (S[i:i+2] == "AC")
print(C)
for l,r in lr:
    print(C[r-1] - C[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = list(map(int, input().split()))
S = input()
ac = [0, 0]
count = 0
for i in range(1, len(S)):
    if S[i-1:i+1] == 'AC':
        count += 1
    ac.append(count)
for _ in range(Q):
    li, ri = list(map(int, input().split()))
    li -= 1
    print(ac[ri]-ac[li])

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
s = input()

ma = 0
for i in range(0,len(s)):
    for j in range(i,len(s)):
        sbstr = s[i:j+1]
        # print(i,j,sbstr)
        is_good = True
        for c in sbstr:
            if c not in "AGCT":
                is_good = False
                break
        if is_good:
            if (len(sbstr)) > ma :
                ma = len(sbstr)

print(ma)

Submission status: Wrong Answer

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

import sys


def main():
    input = sys.stdin.readline
    n, q = [int(i) for i in input().split()]
    s = input().strip()
    qs = [[int(i) for i in input().split()] for _ in range(q)]
    for (l, r) in qs:
        print(s[l - 1 : r - 1].count("AC"))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    n, q = [int(i) for i in input().split()]
    s = input()
    qs = [[int(i) for i in input().split()] for _ in range(q)]
    hoges = [False] + [s[i : i + 2] == "AC" for i in range(n - 1)]
    for (l, r) in qs:
        print(sum(hoges[l : r - 1]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

N, Q = map(int, input().split())
S = sys.stdin.readline()
P = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

a = [0] * N
a[0] = int(S[0] == 'A' and S[1] == 'C')
for i in range(1, N):
    a[i] = a[i - 1] + int(S[i] == 'A' and S[i + 1] == 'C')

for q in P:
    print(a[q[1] - 2] - a[q[0] - 1])

Submission status: Wrong Answer

Solution code:
import sys

N, Q = map(int, input().split())
S = sys.stdin.readline()
P = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

a = [0] * N
a[0] = int(S[0] == 'A' and S[1] == 'C')
for i in range(1, N):
    a[i] = a[i - 1] + int(S[0] == 'A' and S[1] == 'C')

for q in P:
    print(a[q[1] - 2] - a[q[0] - 1])

Submission status: Wrong Answer

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
qs = [[int(i) for i in input().split()] for _ in range(q)]
hoges = [False] + [s[i: i + 2] == 'AC' for i in range(n - 1)]
for (l, r) in qs:
    print(sum(hoges[l:r-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]
  
for q in lr:
  st = q[0]-1
  en = q[1]
  left = st
  right = st
  s = S[st:en]
  ans = 0
  K = 2
  while left < en+1:
    dif = right - left
    if dif == 2:
      if S[left:right] == 'AC':
        ans += 1
      left += 1
    elif dif == 1:
      right += 1
    elif dif == 0:
      right += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
lr=[input() for __ in range(q)]
cs=[0]*(n+1)

#端がACで-1で止まる文字列指定は大丈夫？.
for i in range(n):
    cs[i+1]=cs[i] + (1 if s[i:i+2] == 'AC' else 0)

for num in lr:
    l,r=map(int,num.split())
    print(cs[r] - cs[l-1])

Submission status: Wrong Answer

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

accum = [0] * N

def countAC():
    count = 0
    for i in range(1, N):
        if(S[i-1] == "A" and S[i] == "C"):
            count += 1
        accum[i] = count



countAC()

for i in range(Q):
    print(accum[LR[i][1]-1] - accum[LR[i][0]-1])

print(accum)

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = str(input())
# 累積和をもとめておく
count = [0]*(N)
for i in range(1, N):
    if S[i]=='C' and S[i-1]=='A':
        count[i] = count[i-1] + 1
    else:
        count[i] = count[i-1]
print(count)
LR = [list(map(int, input().split())) for _ in range(Q)]
for l, r in LR:
    print(count[r-1]-count[l-1])

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
list1=[list(map(int,input().split())) for _ in range(Q)]
list2=[0]*(N+1)
count=0
for i in range(N):
    if i>0:
        list2[i+1]=list2[i]
    if i==N-1:
        continue
    elif S[i:i+2]=="AC":
        list2[i+1]+=1
print(list2)
for tmp in list1:
    print(list2[tmp[1]-1]-list2[tmp[0]-1])

Submission status: Wrong Answer

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
qs = [[int(i) for i in input().split()] for _ in range(q)]
hoges = [False] + [s[i:i+2] == 'AC' for i in range(n - 1)]
print(hoges)
for (l, r) in qs:
    print(sum(hoges[l:r]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

AClist = [0]
counter = 0

i=0
while i < N:
    if S[i:i+2] == "AC":
        counter+=1

    AClist.append(counter)
    i+=1


while Q > 0:
    l, r = input().split()
    r = int(r) 
    l = int(l)

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

    Q -= 1

Submission status: Wrong Answer

Solution code:

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

AClist = [0]
counter = 0

i=0
while i < N:
    if S[i:i+2] == "AC":
        counter+=1

    AClist.append(counter)
    i+=1


while Q > 0:
    l, r = input().split()
    r = int(r) 
    l = int(l)

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

    Q -= 1

Submission status: Wrong Answer

Solution code:
import sys
import io
import math
import re

question_info = input().split()
question_string_num = question_info[0]
question_num = int(question_info[1])

datalist = input().split()
data = list(datalist[0])

data_new = []
flag = 0
num_match = 0
for num in data:
    if num == 'A' and flag == 0:
        flag = 1
    elif num == 'C' and flag == 1:
        data_new.append(num_match)
        num_match += 1
        data_new.append(num_match)
        flag = 0
    elif flag == 1:
        data_new.append(num_match)
        data_new.append(num_match)
        flag = 0
    else:
        data_new.append(num_match)
        flag = 0

# print(data_new)
# print(sum(data_new))

answer_list= []
for num in range(question_num):
    data_info = input().split()
    start = int(data_info[0]) - 1
    end = int(data_info[1])-1
    answer = data_new[end] - data_new[start]
    answer_list.append(answer)

for num in answer_list:
    print(num)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

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

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

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = total_list[r - l]
    print(num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

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

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

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = total_list[r - l]
    print(num)

Submission status: Wrong Answer

Solution code:
#累積和　なるほど！

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

ac = [0]*n


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

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

	print(answer)

Submission status: Wrong Answer

Solution code:
n,q = map(int, input().split())
s =input()
A = [[int(j) for j in input().split()] for i in range(q)]
ls = [0] * (n+1)
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ls[i+1]= ls[i]+1
    else:
        ls[i+1]= ls[i]

for k in range(q):
    print(ls[A[k][0]-1]-ls[A[k][1]-1])

Submission status: Wrong Answer

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

ac = [0]*n


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

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

	print(answer)

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
s = input()
nlis = [0]
cnt = 0
for i in range(len(s)-1):
    if(s[i:i+2] == "AC"): 
        cnt += 1
    nlis.append(cnt)
print(nlis)
for i in range(Q):
    in0, in1 = map(int, input().split())
    print(nlis[in1-1]-nlis[in0-1])

Submission status: Wrong Answer

Solution code:

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

AClist = []
counter = 0

i=0
while i < N:
    if S[i:i+1] == "AC":
        counter+=1

    AClist.append(counter)
    i+=1


while Q > 0:
    l, r = input().split()
    r = int(r) 
    l = int(l)

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

    Q -= 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


input = sys.stdin.readline
n, q = map(int, input().split())
s = input()
flag = 0 
check_list = []
cnt = 0
for i in range(n):
    if flag == 1:
        if s[i] == 'C':
            cnt += 1
        flag = 0
    else:
        if s[i] == 'A':
            flag = 1
        else:
            flag = 0
    check_list.append(cnt)
for _ in range(q):
    l, r = map(int, input().split())
    print(check_list[r-1]-check_list[l-1])

Submission status: Wrong Answer

Solution code:
import sys
 
stdin = sys.stdin

N,Q = map(int,input().split())
S = input()
se = [list(map(int, stdin.readline().split())) for i in range(Q)]

list_out = [0] * N
cnt = 0
f = 0

# AC文字列のAの位置をリストに収めた
for i in range(len(S)):
  if S[i] == 'A':
    f = 1
    list_out[i] = list_out[i-1]    
  elif S[i] == 'C':
    if f == 1:
      cnt += 1
      f = 0
      list_out[i] = cnt
  else:
    f = 0
    list_out[i] = list_out[i-1]    


# 指定した文字列範囲を含む要素数を表示
for i in se:
  print(list_out[i[1]-1] - list_out[i[0]-1])

Submission status: Wrong Answer

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

for i in range(1, N+1):
  t[i] = t[i-1] + (1 if S[i-1:i+1] == '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())		# 5 7
S = input()

#print(N,Q,S)

a=[0]*N

for i in range(N):
	if i==0: continue;
	s = S[i:i+2]
	x = 0
	if s=="AC": x=1
	a[i] = a[i-1] + x


for q in range(1,Q+1):
	l, r = map(int, input().split())		# 5 7
	print(a[r-1]-a[l-1])

Submission status: Wrong Answer

Solution code:
import sys
 
stdin = sys.stdin

N,Q = map(int,input().split())
S = input()
se = [list(map(int, stdin.readline().split())) for i in range(Q)]

list_out = [0] * N
cnt = 0
f = 0

# AC文字列のAの位置をリストに収めた
for i in range(len(S)):
  if S[i] == 'A':
    f = 1
    list_out[i] = list_out[i-1]    
  elif S[i] == 'C':
    if f == 1:
      cnt += 1
      list_out[i] = cnt
  else:
    list_out[i] = list_out[i-1]    


# 指定した文字列範囲を含む要素数を表示
for i in se:
  print(list_out[i[1]-1] - list_out[i[0]-1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import numpy as np
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [S[i:i+2] == "AC" for i in range(N)]
AC_csum = np.cumsum(is_AC)


for i in range(Q):
  l, r = [int(i) for i in input().split()]
  ans = AC_csum[r-1] - AC_csum[l-1] - is_AC[r-1]
  if ans > 0: ans += 1
  print(ans)

Submission status: Wrong Answer

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

#print(N,Q,S)

a=[0]*N

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


for q in range(1,Q+1):
	l, r = map(int, input().split())		# 5 7
	print(a[r-1]-a[l-1])

Submission status: Wrong Answer

Solution code:
p = 'ACGT'
s = input()
l = len(s)
r = 0
i = -1
while i < l:
 j = next((i for i in range(i + 1, l) if s[i] in p), l)
 i = next((i for i in range(j + 1, l) if s[i] not in p), l)
 r = max(r, i - j)
print(r)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

for i in range(0, len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        index.append(i)

for i in range(Q):
    a, b = map(int, input().split())
    num1 = -1
    for x in range(len(index)):
        if index[x] >= a-1:
            num1 = x
            break
    num2 = 0
    for y in range(len(index)-1, -1, -1):
        if index[y]+1 <= b-1:
            num2 = y
            break
    print(len(index[num1:num2+1]))

Submission status: Wrong Answer

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

for i in range(1,len(S)+1):
    num=S[0:i].count('AC')
    num_count.append(num)
print(num_count)
for j in range(Q):
    l,r=map(int,input().split())
    k=int(num_count[r-1])-int(num_count[l-1])
    print(k)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

for i in range(0, len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        index.append(i)
print(index)

for i in range(Q):
    a, b = map(int, input().split())
    num1 = -1
    for x in range(len(index)):
        if index[x] >= a-1:
            num1 = x
            break
    num2 = 0
    for y in range(len(index)-1, -1, -1):
        if index[y]+1 <= b-1:
            num2 = y
            break
    print(len(index[num1:num2+1]))

Submission status: Wrong Answer

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

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 = ""
a = [0] * n
b = [0] * n
for i in range(n):
    if s[i] == "A":
        ss = s[i]
    elif s[i] == "C":
        ss += s[i]
    if ss == "AC":
        a[i] = a[i - 1] - 1
        b[i] += b[i - 1] + 1
        ss = ""
    else:
        if i > 0:
            a[i] = a[i - 1]
            b[i] = b[i - 1]
 
for i in range(q):
    x, y = map(int, input().split())
    print(max(0, b[y - 1] + a[x - 1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
ac_list = [0]*len(s)

'''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:i+2] == 'AC':
        ac_list[i+1] = ac_list[i] + 1

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

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])
for i in range(q):
    l,r = map(int,input().split())
    print(x[r-1]-x[l-1])

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.readline
# def ii(): return int(input())
# def mi(): return map(int, input().rstrip().split())
# def lmi(): return list(map(int, input().rstrip().split()))
# def li(): return list(input().rstrip())
# # template


N, Q = map(int, sys.stdin.readline().rstrip().split())
print(N, Q)
S = list(sys.stdin.readline().rstrip())
Alist = []
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, sys.stdin.readline().rstrip().split())
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

# for i in range(Q):
#     if AClist[l[i] - 1] != AClist[l[i]]:
#         print(AClist[r[i]] - AClist[l[i]])
#     else:
#         print(AClist[r[i]] - AClist[l[i]-1])

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
    ACpoint=whereAC(S)
    ACend=[ACpoint[i]+1 for i in range(len(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(ACend,r-2),len(ACend)-1)
        
        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:
x = input()
y = x.split()
y = [int (i) for i in y]
haha = input()

result   = 0
num    = y[1]
count = 0
length = y[0]
arr    = [0] * (length + 1)
arr[0] = 0

for i in range(length-1):
    if haha[i] == "A" and haha[i+1] == "C":
        arr[i+1] = count

        count +=1
    else:
        arr[i+1] = arr[i]

for i in range(num):
    hoho = input()
    xd = hoho.split()
    xd = [int (i) for i in xd]
    lqq = xd[0]
    rqq = xd[1]
    result = arr[rqq-1] - arr[lqq-1]

    print(result)

    result = 0

Submission status: Wrong Answer

Solution code:
import re
if __name__ == '__main__':
  N, Q = map(int, input().split())
  l = input()
  m = re.finditer('AC', l)
  anslist = []
  for match in m:
    anslist.append(match.start())
  for i in range(Q):
    counter = 0
    left, right = map(int, input().split())
    for j in anslist:
      if j < left-1:
        pass
      elif j >= left-1 and j < right:
        counter += 1
    print(counter)

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.readline
# def ii(): return int(input())
# def mi(): return map(int, input().rstrip().split())
# def lmi(): return list(map(int, input().rstrip().split()))
# def li(): return list(input().rstrip())
# # template


N, Q = map(int, sys.stdin.readline().rstrip().split())
print(N, Q)
S = list(sys.stdin.readline().rstrip())
Alist = []
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, sys.stdin.readline().rstrip().split())
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    if AClist[l[i] - 1] != AClist[l[i]]:
        print(AClist[r[i]] - AClist[l[i]])
    else:
        print(AClist[r[i]] - AClist[l[i]-1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = [int(i) for i in input().split()]
s = input()
t = [0] *(n[0])
for i in range(n[0]-2):
    
    if s[i:i+2] == "AC":
        t[i] = 1
        i += 1
    elif s[i+1:i+2] !="A":
        if s[i+2:i+3] !="A":
            i += 2
        else:
            i +=1
print(t)       
for i in range(n[1]):
    m = [int(j) for j in input().split()]   
    print(sum(t[j-1] for j in range(m[0],m[1])))

Submission status: Wrong Answer

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

# In[78]:


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()+1)
        #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:
from bisect import bisect_left

def getIdx(data, val):
    idx = len(data) // 2
    step = idx // 2 + 1

    while step > 0:
        if data[idx] < val:
            idx += step
        else:
            idx -= step
        
        if step > 1:
            step //= 2
    
    return idx


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)

ans = []

for q in range(Q):
    l, r = map(int, input().split())
    ans.append([bisect_left(idxList, r-1), bisect_left(idxList, l-1)])

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
import re

n, q = input().split()
data = input()

iin = int(n)
iq = int(q)
for x in range(iq):
    l, r = input().split()
    il = int(l)
    ir = int(r)
    t = re.findall('[AC]+', data[il:il + ir])
    print(len(t))

Submission status: Wrong Answer

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

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  len_Si = len(Si)
  for i in range(len_Si-1):
    if Si[i] == 'A' and Si[i+1] == 'C':
      count += 1
  print(count)