TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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?

Submission attempts (in order):
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)
  

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)

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)
  

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, Q = map(int,input().split())
S = input()
LRlist = []
for i in range(Q):
    LRlist.append(list(map(int,input().split())))
indexlist = []
for i in range(len(S)-1):
    if S[i] == 'A':
        if S[i+1] == 'C':
            indexlist.append(i)
for LR in LRlist:
    L = LR[0]
    R = LR[1]
    answer = 0
    for i in indexlist:
        if L - 1 <= i <= R - 2:
            answer += 1
        elif i < L - 1:
            break
    print(answer)

N, Q = map(int,input().split())
S = input()
LRlist = []
for i in range(Q):
    LRlist.append(list(map(int,input().split())))
t = [0] * (N + 1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0) 
for LR in LRlist:
     L = LR[0]
     R = LR[1]
     print(t[R-1] - t[L-1])

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):


n,q = map(int,input().split())
s = input() + 'A' 
li = [0]*(n+1)

for i in range(n):
  li[i+1] = li[i] + (1 if s[i] + s[i+1] == 'AC' else 0)
  
print(li)
for j in range(q):
  l,r = map(int,input().split())
  print(li[r-1] - li[l-1])



n,q = map(int,input().split())
s = input() + 'A' 
li = [0]*(n+1)

for i in range(n):
  li[i+1] = li[i] + (1 if s[i] + s[i+1] == 'AC' else 0)
  

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, Q = map(int, input().split())
S = input()
S = [1 if S[i] == 'A' and S[i+1] == 'C' else 0 for i in range(N-1)]
print(S)
for i in range(Q):
  l, r = map(int, input().split())
  print(sum(S[l-1:r-1]))



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


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, q = [int(i) for i in input().split()]
s = input()
l =[]
r =[]
for i in range(q):
    l1, r1 = [int(i) for i in input().split()]
    l.append(l1)
    r.append(r1)

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

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


n, q = [int(i) for i in input().split()]
s = input()
l =[]
r =[]
for i in range(q):
    l1, r1 = [int(i) for i in input().split()]
    l.append(l1)
    r.append(r1)

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

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


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
from pip._vendor.pep517.check import ansi
n, q = map(int, input().split())
s = input()
ans = []
for i in range(0, q):
    l, r = map(int, input().split())
    ans.append(s[l-1: r].replace('AC', ' ').count(' '))
for i in ans:
    print(i)

n, q = map(int, input().split())
s = input()
q_list = [list(map(int, input().split()))for _ in range(q)]

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

for i in range(q):
    print(cum_sum[q_list[i][1] - 1] - cum_sum[q_list[i][0] - 1])

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
# coding: utf-8
N, Q = map(int, input().split())
S = input()
l = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        l[i + 1] = 1
for _ in range(Q):
    ans = 0
    a, b = map(int, input().split())
    ans = sum(l[a - 1: b])
    if l[a - 1] == 1:
        ans -= 1
    print(ans, l)

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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] - r[l-1])

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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
nl = set(range(nl))
for i in nl:
    t[i + 1] = t[i] + (1 if s[i:i + 2] == 'AC' else 0)
ql = set(range(q))
for i in ql:
    l1, l2 = map(int, input().split())
    ans = t[l2-1] - t[l1-1]
    print(ans)

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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
8 3
ACACTACG
3 7
2 3
1 8

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

lLst = [list(map(int, input().split())) for i in range(Q)]

for i in range(Q):
    print(mLst[lLst[i][1] - 1] - mLst[lLst[i][0] - 1])

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, q = map(int, input().split())
S = input()
Q = [list(map(int ,input().split())) for _ in range(q)]

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

	tmp = S[i-1]

for l,r in Q:
	ans = cnt[r] - cnt[l-1]

	if S[l-2] == "A" and S[l-1] == "C":
		ans -= 1

	print(ans)

print(cnt)

N, q = map(int, input().split())
S = input()
Q = [list(map(int ,input().split())) for _ in range(q)]

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

	tmp = S[i-1]

for l,r in Q:
	ans = cnt[r] - cnt[l-1]

	if S[l-2] == "A" and S[l-1] == "C":
		ans -= 1

	print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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])


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]

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


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
from itertools import accumulate

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

#print(A)

flg = []
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)


ans = []
ans = [0] + flg 
ans = list(accumulate(flg)) 
#print(ans)

for li in A:
    print(ans[li[1]-1] - ans[li[0]-1] )

from itertools import accumulate

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

#print(A)

flg = []
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)


ans = []
ans = [0] + flg 
ans = list(accumulate(ans)) 
#print(ans)

for li in A:
    print(ans[li[1]-1] - ans[li[0]-1] )

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import product

def main():
    N = II()
    A, G, C, T = range(4)
    def code(c0, c1, c2):
        return c0 + 4 * c1 + 16 * c2
    dp = [0] * 64
    dp[code(T, T, T)] = 1
    for _ in range(N):
        tmp = [0] * 64
        for p1, p2, p3 in product(range(4), repeat=3):
            for cur in range(4):
                if (p2, p1, cur) == (A, G, C):
                    continue
                if (p2, p1, cur) == (A, C, G):
                    continue
                if (p2, p1, cur) == (G, A, C):
                    continue
                if (p3, p1, cur) == (A, G, C):
                    continue
                if (p3, p2, cur) == (A, G, C):
                    continue
                tmp[code(cur, p1, p2)] += dp[code(p1, p2, p3)]
                tmp[code(cur, p1, p2)] %= MOD
        dp = tmp
    ans = sum(dp)

    return ans % MOD

print(main())

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import accumulate

def main():
    N, Q = LI()
    S = SI()
    LR = []
    for _ in range(Q):
        LR.append(LI_())

    AC = [0] * (N + 1)
    for i in range(N - 1):
        if S[i:i + 2] == 'AC':
            AC[i] = 1
    acc = [0] + list(accumulate(AC))
    for l, r in LR:
        print(acc[r] - acc[l])

    return 0

main()


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
def get_ac(N: int, Q: int, S: str, queries: list)->list:
    before = ''
    cum = [0] * (N+1)
    for i, c in enumerate(S):
        cum[i+1] = cum[i]
        if before + c == 'AC':
            cum[i+1] += 1
        before = c

    print(cum)

    res = []
    for l, r in queries:
        res.append(cum[r] - cum[l])

    return res


if __name__ == "__main__":
    Q = 0
    N, Q = map(int, input().split())
    S = input()
    queries = [tuple(int(s) for s in input().split()) for _ in range(Q)]
    ans = get_ac(N, Q, S, queries)
    
    for a in ans:
        print(a)


def get_ac(N: int, Q: int, S: str, queries: list)->list:
    before = ''
    cum = [0] * (N+1)
    for i, c in enumerate(S):
        cum[i+1] = cum[i]
        if before + c == 'AC':
            cum[i+1] += 1
        before = c

    # print(cum)

    res = []
    for l, r in queries:
        res.append(cum[r] - cum[l])

    return res


if __name__ == "__main__":
    Q = 0
    N, Q = map(int, input().split())
    S = input()
    queries = [tuple(int(s) for s in input().split()) for _ in range(Q)]
    ans = get_ac(N, Q, S, queries)

    for a in ans:
        print(a)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
#!/usr/bin/env python3


def main():
    n, q = map(int, input().split())
    s = input()
    x = [0] * n
    if s[0:2] == 'AC':
        x[0] = 1
    for i in range(n - 1):
        if s[i+1:i+3] == 'AC':
            x[i+1] = x[i] + 1
        else:
            x[i+1] = x[i]

    print(x)
    result = []
    for _ in range(q):
        li, ri = map(int, input().split())
        li -= 1
        ri -= 1
        lsum = 0 if li == 0 else x[li-1]
        rsum = x[ri-1]
        result.append(rsum - lsum)

    for v in result:
        print(v)

if __name__ == '__main__':
    main()


#!/usr/bin/env python3


def main():
    n, q = map(int, input().split())
    s = input()
    x = [0] * n
    if s[0:2] == 'AC':
        x[0] = 1
    for i in range(n - 1):
        if s[i+1:i+3] == 'AC':
            x[i+1] = x[i] + 1
        else:
            x[i+1] = x[i]

    for _ in range(q):
        li, ri = map(int, input().split())
        li -= 1
        ri -= 1
        lsum = 0 if li == 0 else x[li-1]
        rsum = x[ri-1]
        print(rsum - lsum)

if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, Q, S, lrs):
    S2 = [0] * (N+1)
    for i in range(N):
        if S[i] == 'A' and S[i+1] == 'C':
            S2[i+1] = S2[i] + 1
        else:
            S2[i+1] = S2[i]
    print(S2)
    for l, r in lrs:
        count = S2[r-1] - S2[l-1] 
        print(count)

N, Q = i2nn()
S = i2s()
lr = ss2nnn(ii2ss(Q))
main(N, Q, S, lr)




import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, Q = i2nn()
    S = i2s()
    LR = ii2nnn(Q)
    rsw = [0] * (N+1)
    for i in range(N-1):
        rsw[i+1] = rsw[i]
        if S[i] == 'A' and S[i+1] == 'C':
            rsw[i+1] += 1
    rsw[N] = rsw[N-1]
    # 0 1 2 3 4 5
    # 0 1 1 1 2 2
    #  a c c a c
    #  1 2 3 4 5
    for l, r in LR:
        n = rsw[r-1] - rsw[l-1]
        print(n)

main()

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
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])

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

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
for i in range(N - 1):
    a[i + 1] = a[i] + int(S[i] == 'A' and S[i + 1] == 'C')

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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)


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


s = input()
arr = []
c = 0
for i in range(len(s)):
    if i == 0:
        arr.append(0)
    else: 
        # print(s[i-1]+s[i])
        if (s[i-1]+s[i]) == "AC":
            c+=1
        arr.append(c)

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n ,q=map(int, input().split())
s=input()
t=[0]*(n+1)

for i in range(n):
    if s[i:i+2]=="AC":
        c=1
    else:
        c=0

    t[i+1]=t[i]+c

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

n ,q=map(int, input().split())
s=input()
t=[0]*(n+1)

for i in range(n):
    if s[i:i+2]=="AC":
        c=1
    else:
        c=0

    t[i+1]=t[i]+c

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,Q=map(int,input().split())
S=input()

plc=[0]*N

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

for i in range(len(S)-1):
  plc[i+1]=plc[i]+plc[i+1]
  
for i in range(Q):
  l,r=list(map(int,input().split()))
  
print(plc[r-1]-plc[l-1])

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,Q = [int(x) for x in input().split()]
S = list(input())
lrlist =[]
for _ in range(Q):
    l,r = [int(x) for x in input().split()]
    lrlist.append((l,r))

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

for _ in range (Q):
    l = lrlist[_][0]
    r = lrlist[_][1]
    ans = sum(sumls[r-1]-sumls[l-1])
    print(ans)






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

N,Q = [int(x) for x in input().split()]
S = list(input())
lrlist =[]
for _ in range(Q):
    l,r = [int(x) for x in input().split()]
    lrlist.append((l,r))

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

for _ in range (Q):
    l = lrlist[_][0]
    r = lrlist[_][1]
    ans = sumls[r-1]-sumls[l-1]
    print(ans)






Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N,Q=map(int,input().split())
S=input()

s=[0]

for i in range(len(S)):
    s.append(s[-1]+(1 if(S[i:i+2]=="AC") else 0))

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

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

s=[0]

for i in range(len(S)):
    s.append(s[-1]+(1 if(S[i:i+2]=="AC") else 0))

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


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,Q=map(int,input().split())
S=str(input())
AC_list=[0]*N
t=0
for i in range(1,N):
  if S[i]=='C' and S[i-1]=='A':
    t+=1
  AC_list[i]=t
print(AC_list)
for i in range(Q):
  l,r=map(int,input().split())
  print(AC_list[r-1]-AC_list[l-1])

N,Q=map(int,input().split())
S=str(input())
AC_list=[0]*N
t=0
for i in range(1,N):
  if S[i]=='C' and S[i-1]=='A':
    t+=1
  AC_list[i]=t
ans=0
for i in range(Q):
  l,r=map(int,input().split())
  print(AC_list[r-1]-AC_list[l-1])

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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)

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)

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


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
from sys import stdin
def main():
  readline = stdin.readline
  n, q = map(int, readline().split())
  s = input()
  c = [0] * (n + 1)
  pch = ''
  pc = 0
  for i in range(2, n + 1):
    cch = s[i - 1]
    if cch == 'C' and pch == 'A':
      t = pc + 1
    else:
      t = pc
    c[i] = t
    pc = t
    pch = cch
  for _ in range(q):
    l, r = map(int, readline().split())
    t = c[r] - c[l - 1]
    if l >= 2 and s[l - 2: l] == 'AC':
      t -= 1
    print(t)
main()


from sys import stdin
def main():
  readline = stdin.readline
  n, q = map(int, readline().split())
  s = input()
  c = [0] * (n + 1)
  pch = s[0]
  pc = 0
  for i in range(2, n + 1):
    cch = s[i - 1]
    if cch == 'C' and pch == 'A':
      t = pc + 1
    else:
      t = pc
    c[i] = t
    pc = t
    pch = cch
  for _ in range(q):
    l, r = map(int, readline().split())
    t = c[r] - c[l - 1]
    if l >= 2 and s[l - 2: l] == 'AC':
      t -= 1
    print(t)
  print(c)
main()



N, Q = map(int, input().split())
S = input()
cs = [0] * N
for i in range(1, N):
  if S[i - 1:i + 1] == 'AC':
    cs[i] = 1
for i in range(1, N):
  cs[i] += cs[i - 1]
for _ in range(Q):
  l, r = map(int, input().split())
  t = cs[r - 1]
  if l != 1:
    t -= cs[l - 2]
    if S[l - 2:l] == 'AC':
      t -= 1
  print(t)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
# C - GeT AC

import sys
n, q = list(map(int, sys.stdin.readline().split()))

s = input()

separators = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

# n = 8


# separators = [[3, 7],[2, 3],[1, 8]]

cnt = []

for index in range(0, len(separators)):
    cnt.append(s[separators[index][0]:separators[index][1]].count('AC'))

for i in cnt:
    print(i)

# C - GeT AC




import sys
n, q = list(map(int, sys.stdin.readline().split()))
s = list(sys.stdin.readline())

cnt = [0] * (len(s)+1)



for i in range(1, len(s)):
    

    if s[i] == "C" and s[i-1] == "A":
        cnt[i+1] = cnt[i] + 1
    else:
        cnt[i+1] = cnt[i]


r_and_l = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

for e in r_and_l:
    num = e[0]
    print(cnt[e[1]] - cnt[num] )


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,Q = map(int,input().split())
S = list(input())
num = list(range(N))
dic1 = dict(zip(num,S))
q = [list(map(lambda x: int(x)-1,input().split())) for _ in range(Q)]
dic2 = {}
for i in range(N-1):
    if dic1[i]+dic1[i+1] == "AC":
        dic2[i] = i
print(dic1)
print(dic2)
print(q)
for i in range(Q):
    ans = 0
    for j in range(len(dic2)):
        if q[i][0] <= list(dic2.values())[j] < q[i][1]:
            ans += 1
    print(ans)

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(0,Q):
  l[i],r[i]=map(int,input().split())
  print(S[l-1:r].count('AC'))
  

N,Q=map(int,input().split())
S=input()
count = [1 for i in range(0,N) if S[i:i+1] =='AC' else 0]
for i in range(0,Q):
  l,r=map(int,input().split())
  print(sum(count[l-1:r-1]))


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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
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)

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

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

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

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

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

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()
rr = (list(map(int, input().split())) for _ in range(k))

from collections import Counter

dc = [0, 0]
c = 0
for i in range(1, len(s)):
  if s[i-1]+s[i] == 'AC':
    c += 1
  dc.append(c)
for a, b in rr:
  print(dc[b] - dc[a-1])


import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()
rr = (list(map(int, input().split())) for _ in range(k))

from collections import Counter

dc = [0, 0]
c = 0
for i in range(1, len(s)):
  if s[i-1]+s[i] == 'AC':
    c += 1
  dc.append(c)
for a, b in rr:
  print(dc[b] - dc[a])

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,q,s,l):
    lst_ac = [0]*(len(s))
    for i in range(len(s)-1):
        if s[i]+s[i+1] == "AC":
            lst_ac[i+1] = lst_ac[i]+1
        else:
            lst_ac[i+1] = lst_ac[i]
    print(lst_ac)
    for item in l:
        print(lst_ac[item[1]-1] - lst_ac[item[0]-1])

def resolve():
    n,q = mi()
    s = input()
    l = mix(q)
    main(n,q,s,l)

if __name__ == "__main__":
    resolve()

ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,q,s,l):
    lst_ac = [0]*(len(s))
    for i in range(len(s)-1):
        if s[i]+s[i+1] == "AC":
            lst_ac[i+1] = lst_ac[i]+1
        else:
            lst_ac[i+1] = lst_ac[i]
    for item in l:
        print(lst_ac[item[1]-1] - lst_ac[item[0]-1])

def resolve():
    n,q = mi()
    s = input()
    l = mix(q)
    main(n,q,s,l)

if __name__ == "__main__":
    resolve()

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,Q=[int(i) for i in input().split()]
S=input()
lr=[]
for i in range(Q):
  lr.append([int(i) for i in input().split()])

acn=[0 for i in range(N)]
count=0
for i in range(1,N):
  if S[i-1]+S[i]=="AC":
    count+=1
  acn[i]=count
for i in range(Q):
  l=lr[i][0]
  r=lr[i][1]
  print(l,r)
  print(acn[r-1]-acn[l-1])

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

acn=[0 for i in range(N)]
count=0
for i in range(1,N):
  if S[i-1]+S[i]=="AC":
    count+=1
  acn[i]=count
for i in range(Q):
  l=lr[i][0]
  r=lr[i][1]
  print(acn[r-1]-acn[l-1])

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, Q = map(int, input().split())
S = str(input())
li = []
cnt = 0

for i in range(N-1):
  if S[i]=='A' and S[i+1]=='C':
    cnt += 1
    li.append(cnt)
  else:
    li.append(cnt)

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


N, Q = map(int, input().split())
S = str(input())
li = []
cnt = 0

for i in range(N-1):
  if S[i]=='A' and S[i+1]=='C':
    cnt += 1
    li.append(cnt)
  else:
    li.append(cnt)

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


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n,q=map(int,input().split())
s=input()
cnt=0
a=[0]*n

for i in range(n-1):
  if s[i:i+2]=='AC':
    cnt+=1
    a[i+1]=cnt
    print(a)
  else:
    a[i+1]=cnt

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, q = map(int, input().split())
s = input()
t = [0] * n
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for _ in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

#!/usr/bin/env python3
n, q = map(int, input().split())
s = input()
t = [0] * -~n
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for _ in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, Q = map(int, input().split())
S = input()
x = [0 for i in range(N)]
T = ""
for i in range(len(S)):
    c = S[i]
    if c == 'A':
        A = True
    elif A and c == 'C':
        x[i] += 1
        A = False
    else:
        A = False
        T += c
s = [0 for i in range(N+1)]
for i in range(N):
    s[i+1] = s[i]+x[i]
print(s)
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    if s[l] != s[l+1]:
        print(s[r]-s[l]-1)
    else:
        print(s[r]-s[l])


N, Q = map(int, input().split())
S = input()
x = [0 for i in range(N)]
A = False
for i in range(len(S)):
    c = S[i]
    if c == 'A':
        A = True
    elif A and c == 'C':
        x[i] += 1
        A = False
    else:
        A = False
s = [0 for i in range(N+1)]
for i in range(N):
    s[i+1] = s[i]+x[i]
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    if s[l] != s[l+1]:
        print(s[r]-s[l]-1)
    else:
        print(s[r]-s[l])


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(N)]

for lr_ in lr:
    l, r = lr_[0], lr_[1]
    
    print(S[l - 1: r].count('AC'))

n, q = map(int, input().split())
s = input()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

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

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0] * N
Rsub = [0] * N
L = 0
R = 0


for k in range(1,N):
  if SS[k-1] == "A" and SS[k] == "C":
    L += 1
  Lsub[k] = L

for j in (0,N-1)[::-1]:
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[0] - Lsub[L-1] - Rsub[R-1])

N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]*N
Rsub = [0]*N
L = 0
R = 0


for j in range(1,N):
  if SS[j-1] == "A" and SS[j] == "C":
    L += 1
  Lsub[j] = L

for j in reversed(range(0,N-1)):
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R



ans = [0] * Q

for i in range(Q):
  L, R = map(int, input().split())
  ans[i] = Rsub[0] - Lsub[L-1] - Rsub[R-1]


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

N, Q  = map(int, input().split())
S = list(input())
Lsub = [0] * N
Rsub = [0] * N
L = 0
R = 0


for k in range(1,N):
  if SS[k-1] == "A" and SS[k] == "C":
    L += 1
  Lsub[k] = L

for j in reversed(range(0,N-1)):
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R
  

for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[0] - Lsub[L-1] - Rsub[R-1])

N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]
Rsub = [0]
L = 0
R = 0


for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    L += 1
  Lsub.append(L)

for j in range(0,N-1)[::-1]:
  if S[j] == "A" and S[j+1] == "C":
    R += 1
  Rsub.append(R)


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[N-1] - Lsub[L-1] - Rsub[N-R])

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n,q=list(map(int,input().split()))
s=" "+input()
a=[0]
for i in range(1,n+1):
  if c[i]=="C" and c[i-1]=="A":
    a.append(a[i-1]+1)
  else:
    a.append(a[i-1])
for i in range(q):
  l,r=list(map(int,input().split()))
  print(a[r]-a[l])

n,q=list(map(int,input().split()))
s=" "+input()
a=[0]
for i in range(1,n+1):
  if s[i]=="C" and s[i-1]=="A":
    a.append(a[i-1]+1)
  else:
    a.append(a[i-1])
for i in range(q):
  l,r=list(map(int,input().split()))
  print(a[r]-a[l])

Verdicts: Runtime Error

Accepted