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:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


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

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

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

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

	return True

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

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

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

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

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

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

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

main()

Submission status: Wrong Answer

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from itertools import accumulate

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,Q= map(int, sys.stdin.readline().split())
    S = sys.stdin.readline().rstrip()
    l= [list(map(int,list(sys.stdin.readline().split()))) for i in range(Q)]
    # 累積和
    flg = []
    for i in range(N-1):
        tmp_S = S[i:i+2] #２文字ずつ
        print(tmp_S)
        if tmp_S == "AC":
            flg.append(1)
        else:
            flg.append(0)

    flg2 = [0] + flg
    flg2 = list(accumulate(flg2)) #accumurateで累積和[0, 1, 1, 2, 2, 2, 3, 3]

    for e in l:
        print(flg2[e[1]-1] - flg2[e[0]-1]) #累積和から順番で引っ張ってくる

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#ABC122C
import sys
import copy
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
q=hoge[1]

s = input()

ans=[]
sum=0
print(s)

for j in range(0,n-1):
	if(s[j]=="A")and(s[j+1]=="C"):
		sum+=1
	ans.append(sum)
	#print(s[j])
ans.append(sum)
ans.append(0)
#ans[n-1]=sum
#print(ans)
print(ans)

l=[]
r=[]
sum=0
for i in range(0,q):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))

	print(ans[hoge[1]-2]-ans[hoge[0]-2])
	print("{} {}".format(hoge[0],hoge[1]))

Submission status: Wrong Answer

Solution code:
# GET AX
N, Q = map(int, input().split())
S = str(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

pos = []
for s in range(N):
	if s < 7 and S[s:s+2] == 'AC':
		pos.append(s+1)
for l, r in lr:
	lmin = [1 for p in pos if l > p]
	rmax = [1 for p in pos if r <=p]
	print(len(pos)-sum(lmin)-sum(rmax))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
ac = [0]
for i in range(len(s)):
  if s[i] == 'A' and s[i] == 'C':
    ac.append(ac[i]+1)
  else:
    ac.append(ac[i])
for i in range(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())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [s[i:i+2] == "AC" for i in range(n-1)]
idx2 = [sum(idx[:i]) for i in range(n)]

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

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

idx = [s[i:i+2] == "AC" for i in range(n-1)]

Submission status: Wrong Answer

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

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

cnt = [0]*n
for i in range(1, n):
    cnt[i] += cnt[i-1] + ac[i]
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 = input()

cnt = 0
n = [0]
for i in range(N-1):
    if s[i]+s[i+1] == 'AC':
        cnt += 1
    n.append(cnt)

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

Submission status: Wrong Answer

Solution code:
n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
for r in range(1,n+1):
  if 'AC' in s[l:r]:
    cnt+=1
    l+=2
  tmp.append(cnt)

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

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = input()
d = [0] * len(c)
e = 0
for i in range(1, len(c)):
    if c[i] == "C" and c[i-1] == "A":
        e += 1
    d[i] = e
print(d)
for i in range(b):
    f, g = map(int, input().split())
    print(d[g-1] - d[f-1])

Submission status: Wrong Answer

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

print(pos)
for i in range(q):
    l, r = map(int, input().split())
    pos_copy=pos.copy()
    pos_copy.append(l-1)
    pos_copy.append(r-1)
    pos_copy.sort()
    print(pos_copy.index(l-1) - pos_copy.index(r-1) - 1)

Submission status: Wrong Answer

Solution code:
N,Q = map(int, input().split())
S = input()
L = []
for i in range(Q):
    L.append([int(a) for a in input().split()])

Temp = [0 for i in range(N)]
num = 0
ac = 0
while num <= N-2:
    if S[num] == "A" and S[num+1] == "C":
        Temp[num] = ac
        Temp[num+1] = ac+1
        num += 2
        ac += 1
    else:
        Temp[num] = ac
        Temp[num+1] = ac
        num += 1
if Temp[-1] == 0:
    if S[-2] != "A" or S[-1] != "C":
        Temp[-1] = ac
Temp.append(ac)
print(Temp)
for j in range(Q):
    ini = L[j][0]-1
    fin = L[j][1]-1
    
    print(Temp[fin]-Temp[ini])

Submission status: Wrong Answer

Solution code:
N,Q = map(int, input().split())
S = input()
L = []
for i in range(Q):
    L.append([int(a) for a in input().split()])

Temp = [0 for i in range(N)]
num = 0
ac = 0
while num <= N-2:
    if S[num] == "A" and S[num+1] == "C":
        Temp[num] = ac
        Temp[num+1] = ac
        num += 2
        ac += 1
    else:
        Temp[num] = ac
        num += 1
if Temp[-1] == 0:
    Temp[-1] = Temp[-2]
for j in range(Q):
    ini = L[j][0]-1
    fin = L[j][1]-1
    print(Temp[fin]-Temp[ini])

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
qlist = [map(int,input().split()) for _ in range(Q)]
tarstr = "AC"
dp = []
maxnum = 0
flg = False
for c in S:
    if(c=="A"):
        flg = True
    elif(c=="C" and flg):
        maxnum += 1
    else:
        flg = False
    dp.append(maxnum)

for l,r in qlist:
    print(dp[r-1]-dp[l-1])

Submission status: Wrong Answer

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

acs = [0]
pre_a = False
for c in s:
  acs.append(acs[-1])
  if pre_a:
    if c == 'C':
      acs[-1] += 1
    pre_a = False
  else:
    if c == 'A':
      pre_a = True

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

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

P = [0] * (N+1)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][0]-2] - P[LR[i][1]-1])

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

P = [0] * (N+1)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][0]] - P[LR[i][1]-1])

Submission status: Wrong Answer

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

flag = False

ATList = [0]*n

for i in range(n):
    if (S[i] == "A"):
        ATList[i] = ATList[i-1]
        flag = True
    elif (S[i] == "C") and flag:
        ATList[i] = ATList[i-1] + 1
        flag = False
    else:
        ATList[i] = ATList[i-1]
        flag = False

print(ATList)

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

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, Q = MAP()
    S = input()
    t = [0] * (N + 1)
    for i in range(N - 1):
        if S[i:i+2] == 'AC':
            t[i + 1] = t[i] + 1
        else:
            t[i + 1] = t[i]
    ans = []
    for i in range(Q):
        l, r = MAP()
        ans.append(t[r] - t[l - 1])
    for i in range(Q):
        print(ans[i])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re
n,q = map(int,input().split())
s = input()
ac = s.count('AC')
for a in range(q):
    lm = list(map(int,input().split()))
    str1 = s[lm[0]-1:lm[1]:]
    if len(str1) > n:
        str2 = s[0:lm[0]-1:] + s[lm[1]::]
        print(ac)
    else:
        print(ac)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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]=ac[i-1]+1
  else:
    ac[i]=ac[i-1]
for i in range(q):
  l,r=map(int,input().split())
  print(sum(1 for i in ac if l-1<=i<=r-2))

Submission status: Wrong Answer

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

for i in range(len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        ac.append(i)
        ac.append(i+1)
print(ac)
for i in range(Q):
    ac2=ac
    p=lr[i][0]-1
    q=lr[i][1]-1
    ac2.append(p)
    ac2.append(q)
    ac2.sort()
    print(ac2)
    num1=ac2.index(p)
    if num1%2!=0:
        num1+=1
    num2=ac2.index(q)
    if num2<len(ac2)-1:
        if ac2[num2]==ac2[num2+1]:
            num2+=1
    print(num1,num2)
    ac2.pop(ac2.index(p))
    ac2.pop(ac2.index(q))
    print((num2-num1-1)//2)

Submission status: Wrong Answer

Solution code:
"""
n = int(sys.stdin.readline())
a, b = map(int, sys.stdin.readline().split())
c = list(map(int, sys.stdin.readline().split()))
s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

a = 100
b = 0.987654321
print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)


mod = 1000000007

if __name__ == "__main__":
    N, Q = map(int, sys.stdin.readline().split())
    origin = sys.stdin.readline()
    dp = [0 for _ in range(N + 1)]
    a_flag = False
    for i in range(N):

        if a_flag and origin[i] == "C":
            dp[i + 1] = dp[i] + 1
            a_flag = False
            continue

        if origin[i] == "A":
            a_flag = True

        dp[i + 1] = dp[i]

    for _ in range(Q):
        l, r = map(int, sys.stdin.readline().split())
        print(dp[r] - dp[l])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = str(input())
count = [0]*(N+1)
lists = []
for i in range(1, N):
    if S[i-1] == "A" and S[i] == "C":
        count[i + 1] = count[i] + 1
    else:
        count[i + 1] = count[i]
for i in range(Q):
    l, r = map(int, input().split())
    ans = count[r-1] - count[l-1]
    lists.append(ans)
for i in range(len(lists)):
    print(lists[i])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S=input()
A=[]
AC=[0]*100001
count=0
total=0
for i in range (Q):
    A.append(list(map(int, input().split())))

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

for i in range(Q):
    total+=AC[int(A[i][1])-1]-AC[int(A[i][0])-1]
    #print(AC[int(A[i][1])-2])
    #print(AC[int(A[i][0])-1])
    print(total)
    total=0

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S=input()
A=[]
AC=[0]*100001
count=0
total=0
for i in range (Q):
    A.append(list(map(int, input().split())))

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


for i in range(Q):
    total+=AC[int(A[i][1])-1]-AC[int(A[i][0])-1]
    if S[AC[int(A[i][1])]]=='C' and S[AC[int(A[i][1])-1]]=='A':
        total -=1
    print(total)
    total=0

Submission status: Wrong Answer

Solution code:
import bisect

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

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

print(idx)
for i in range(Q):
  l, r = map(int, input().split())
  lid = bisect.bisect_left(idx, l)
  rid = bisect.bisect_right(idx, r-1)
  print(rid-lid)

Submission status: Wrong Answer

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

s1 = input()

na1 = [[0] * 2] * n2

ma1 = 0
mi1 = 100000
for i1 in range(n2):
    na1[i1] = [int(j) for j in input().split()]
    na1[i1].append(i1+1)
    if ma1 <= na1[i1][1]:
        ma1 = na1[i1][1]
    if mi1 >= na1[i1][0]:
        mi1 = na1[i1][0]

t1 = s1.rfind("AC")
if ma1 > t1 + 1:
    ma1 = t1 + 1

t2 = s1.find("AC")
if mi1 < t2:
    mi1 = t2
    
na1.sort(key=lambda x: x[1])

na2 = [0] * n2
for i7 in range(n2):
    na2[i7] = [na1[i7][2], 0]

f1 = False
n6 = mi1 - 1
n5 = 0
nt1 = 0

for i2 in range(n1 - n6):
    if s1[i2 + n6] == "A":
        f1 = True
    elif s1[i2 + n6] == "C" and f1 == True:
        n5 += nt1
        nt1 = 0
        for i4 in range(len(na2) - n5):
            if (i2 + n6) >= na1[i4 + n5][0] and (i2 + 1) <= na1[i4 + n5][1]:
                na2[i4][1] += 1
            if (i2 + n6) > na1[i4 + n5][1]:
                nt1 += 1
        f1 = False
    else:
        f1 = False

    if (i2 + n6) >= ma1:
        break

na2.sort()
for i5 in range(n2):
    print(na2[i5][1])

Submission status: Wrong Answer

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

s1 = input()

na1 = [[0] * 2] * n2

ma1 = 0
mi1 = 100000
for i1 in range(n2):
    na1[i1] = [int(j) for j in input().split()]
    na1[i1].append(i1+1)
    if ma1 <= na1[i1][1]:
        ma1 = na1[i1][1]
    if mi1 >= na1[i1][0]:
        mi1 = na1[i1][0]

na1.sort()

na2 = [0] * n2
for i7 in range(n2):
    na2[i7] = [na1[i7][2], 0]

f1 = False
n6 = mi1 - 1
n5 = 0
nt1 = 0

print(n6)
for i2 in range(n1 - n6):
    if s1[i2 + n6] == "A":
        f1 = True
    elif s1[i2 + n6] == "C" and f1 == True:
        for i4 in range(len(na2) - n5):
            if (i2 + n6) >= na1[i4 + n5][0] and (i2 + 1) <= na1[i4 + n5][1]:
                na2[i4][1] += 1
    else:
        f1 = False

    if (i2 + n6) >= ma1:
        break

na2.sort()
for i5 in range(n2):
    print(na2[i5][1])

Submission status: Wrong Answer

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

for i in range(q):
  ans=0
  l,r=map(int,input().split())
  sublist=s[l-1:r]
  print(sublist)
  for j in range(len(sublist)-1):
    if sublist[j]=='A' and sublist[j+1]=='C':
      ans=ans+1
  ans_list.append(ans)
  
for i in range(q):
  print(ans_list[i])

Submission status: Wrong Answer

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

s1 = input()

na1 = [[0] * 2] * n2

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

na2 = []
f1 = False

for i2 in range(n1):
    if s1[i2] == "A":
        f1 = True
    elif s1[i2] == "C":
        na2.append(i2 - 1)
    else:
        f1 = False


for i3 in range(n2):
    c1 = 0
    for i4 in range(len(na2)):
        if na1[i3][0] <= (na2[i4] + 1) and  na1[i3][1] >= (na2[i4] + 2):
            c1 += 1

print(c1)

Submission status: Wrong Answer

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

for _ in range(q):
	l,r=map(int,input().split())
	# list_=[s[l-1:r]]
	print(s[l-1:r])
	ans=0
	for i in range(l-1,r-1):
		if s[i] == 'A' and s[i+1] == 'C':
			ans +=1



	print(ans)

Submission status: Wrong Answer

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

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[i] + 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()

cc = []

acc = 0

for idx in range(N):
    if S[idx:idx + 2] == "AC":
        acc = acc + 1
    cc.append(acc)

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
data = input()
result = [0] * N
for i in range(N-1):
  if data[i] == "A" and data[i+1]:
    result[i+1] = result[i] + 1
  else:
    result[i+1] = result[i]

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

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=len(s):
  try:
    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)
  except:
      a.append(x)
      break
#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=len(s):
  try:
    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)
  except:
      break
#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

Submission status: Wrong Answer

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

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i+1] = ans

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

Submission status: Wrong Answer

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

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i] = ans

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

Submission status: Wrong Answer

Solution code:
def resolve():
    (N, Q) = list(map(int, input().split(" ")))
    S = input()
    LRs = [list(map(int, input().split(" "))) for i in range(Q)]
    mem = [0] * N
    for i in range(N-1):
        if S[i] == "A" and S[i+1] == "C":
            mem[i+1] = mem[i] + 1
        else:
            mem[i+1] = mem[i]
    print(mem)

    for (l, r) in LRs:
        print(mem[r-1]-mem[l-1])

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    (N, Q) = list(map(int, input().split(" ")))
    S = input()
    LRs = [list(map(int, input().split(" "))) for i in range(Q)]
    mem = [S[i:i+2] == "AC" for i in range(len(S)-1)]
    print(mem)
    for (l, r) in LRs:
        print(mem[l-1:r-1].count(True))

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

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

start = []
end = []
c = s.count("AC")

for i in range(q):
    s1, e1 = [int(i) for i in input().split()]
    start.append(s1-1)
    end.append((e1-1))

for i in range(c):
    list[i] = s.find("AC")
    s = s.replace("AC", "XX", 1)

result = [0]*q

for i in range(q):
    result[i] = sum(start[i]<=x<end[i] for x in list)


for i in result:
    print(i)

Submission status: Wrong Answer

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

start = []
end = []
c = s.count("AC")

for i in range(q):
    s1, e1 = [int(i) for i in input().split()]
    start.append(s1)
    end.append((e1))

for i in range(c):
    list[i] = s.find("AC")
    s = s.replace("AC", "XX", 1)

result = [0]*q

for i in range(q):
    for j in range(c):
        if start[i] < list[i] < end[i]:
            result[i] += 1
for i in list:
    print(i)

Submission status: Wrong Answer

Solution code:

def checkATCG(S) :

    default = len(S)
    change = len(S.replace("AC",""))
    cnt = default - change
    cnt = cnt /2

    return cnt

fstInp = input()
fstInp = fstInp.split()
N = int(fstInp[0])
Q = int(fstInp[1])
S = input()
inList = []
cnt = 0
while cnt < Q:
    inputNum = input()
    inputNum = inputNum.split()
    num1 = int(inputNum[0])
    num2 = int(inputNum[1])
    
    inList.append(num1)
    inList.append(num2)
    checkStr = S[num1:num2]
    print(int(checkATCG(checkStr)))
    cnt += 1

Submission status: Wrong Answer

Solution code:

def checkATCG(S) :

    default = len(S)
    change = len(S.replace("AC",""))
    cnt = default - change
    cnt = cnt /2

    return cnt

fstInp = input()
N = int(fstInp[0])
Q = int(fstInp[len(fstInp)-1])
S = input()
inList = []
cnt = 0
while cnt < Q:
    inputNum = input()
    num1 = int(inputNum[0])
    num2 = int(inputNum[len(inputNum)-1])
    
    inList.append(num1)
    inList.append(num2)
    cnt += 1

ansList = []
cnt = 0
while cnt < len(inList):
    checkStr = S[inList[cnt] -1:inList[cnt + 1]]
    print(int(checkATCG(checkStr)))
    cnt += 2

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
C = [0]*N
for i in range(1,N):
	if S[i-1] == 'A' and S[i] == 'C':
		C[i] = C[i-1] + 1
	else:
		C[i] = C[i-1]
print(C)
for i in range(Q):
	print(C[L[i][1] - 1]- C[L[i][0] - 1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]
s_count = [0 for i in range(n + 1)]
print(s_count)
for i in range(n):
    s_count[i + 1] = s_count[i] + (1 if s[i:i + 2] == 'AC' else 0)

for i in range(q):
    print(s_count[lr[i][1] - 1] - s_count[lr[i][0] - 1])

Submission status: Wrong Answer

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

# 1文字目から n 文字目までの AC の数 = 1文字目から n - 1 文字目までの、Cを右に持つ A の数

where_ac = [0] * N

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

count = [sum(where_ac[0:i+1]) for i in range(N)]

for lr in lr_list:
    print(count[lr[1]-1] - count[lr[0]-1])

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = input()
l = [0]*(N-1)
for n,(i , j) in enumerate(zip(a,a[1:])):
    if i == "A" and j == "C":
        l[n] +=1
l = [0]+ l
print(l)
for i,n in enumerate(l[:-1]):
    l[i+1] +=l[i]
for i in range(K):
    ta,tb = map(int, input().split())
    print(l[tb-1]-l[ta-1])

Submission status: Wrong Answer

Solution code:
S = input()
 
cnt = 0
ans = 0
 
for ss in S:
	if ss in 'ACGT':
		cnt += 1
	else:
		cnt = 0
	ans = max(ans,cnt)
	
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s=input()
l=[0]
x,y=0,0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":x+=1
    l.append(x)
l.append(x)
print(l)
for i in range(m):
    a,b=map(int,input().split())
    print(l[b-1]-l[a-1])

Submission status: Wrong Answer

Solution code:
import sys
imput =sys.stdin.readline
N, Q =map(int,input().split())
S =[i for i in input()]
q = [[int(i) for i in input().split()] for _ in range(Q)]
num = 0
for i in range(N-1):
    if S[i]+S[i+1]=="AC":
        num += 1
    S[i] = num
S[-1] = num
S.append(0)
print(q)
print(S)
for lr in q:
  print(S[lr[1]-2] -S[lr[0]-2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
c=[0]
t=0

for i in range(0,n-1):
    if s[i]=="A" and s[i+1]:
        t+=1
        c.append(t)
    else:
        c.append(t)

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

Submission status: Wrong Answer

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

for i in range(q):
    ans=0
    l,r=map(int,input().split())
    x=s[l-1:r]
    for h in range(len(x)+1):
        if s[i:i+1]==["A","C"]:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#Coding:Utf-8

N,Q=input().split()
S=input()
Num=S.count("AC")
count=0

if Num==0:
  print(0)
  exit()
else:
  index=[]
  for i in range(len(S)-1):
    if count<Num and S[i]=="A" and S[i+1]=="C":
      index.append(i)
      count+=1
a=[]
for j in range(int(Q)):
  a.extend(input().split())

for k in range(0,int(Q)*2,2):
  count=0
  for l in range(len(index)):
    if index[l]+1>=int(a[k]) and index[l]+1<int(a[k+1]):
      count+=1
  else:
    print(count)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
s = input()
l = [0,0]
for i in range(0,n-1):
    l.append(l[i+1]+(s[i]+s[i+1]=="AC"))
for i in range(q):
    x,y = map(int,input().split())
    if l[x-1]+1==l[x]:
        print(l[y] - l[x - 1]-1)
    else:
        print(l[y] - l[x - 1])
print(l)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

S = input()
cumurative_sum_lst = np.zeros(N+1)
for i in range(N-2):
    if S[i] == "A" and S[i+1] == "C":
        cumurative_sum_lst[i+2:] += 1

#print(cumurative_sum_lst)

outputs = []
for i in range(Q):
    l, r = map(int, input().split())
    l, r = l - 1, r
#    print(l, r)
#    print()
    tmp = cumurative_sum_lst[r] - cumurative_sum_lst[l]
    outputs.append(int(tmp))

for i in outputs:
    print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

S = input()
cumurative_sum_lst = np.zeros(N)
for i in range(N-2):
    if S[i] == "A" and S[i+1] == "C":
        cumurative_sum_lst[i+2:] += 1

#print(cumurative_sum_lst)

outputs = []
for i in range(Q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
#    print(l, r)
#    print()
    tmp = cumurative_sum_lst[r] - cumurative_sum_lst[l]
    outputs.append(int(tmp))

for i in outputs:
    print(i)

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
c=[0]
t = 0
for i in range(1,N):
    t += 1 if  S[i-1:i+1]=='AC' else 0
    c.append(t)
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:
N,Q=[int(i) for i in input().split()]
S=input()

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

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