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())
list=[]
for i in range(0, N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append(i)
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for i in list:
        if l-1 <= j < r-1:
            count+=1
        else:
            count+=0
    print(count)

N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(0, N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append(i)
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for i in list:
        if l-1 <= j <= r+1:
            count+=1
            print(count)

N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r-2):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

N, Q = map(int, input().split())
S=list(input())
list=[0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list[i]+=1
count=0
for j in range(Q):
    l, r = map(int, input().split())
    print(list[l-1:r-1]).count(1))

N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r+1):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

N, Q = map(int, input().split())
S=list(input())
list=[0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list[i]+=1
count=0
for j in range(Q):
    l, r = map(int, input().split())
    count+=sum(list[l-1:r-1])
print(count)

N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(0, N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append(i)
count=0
for i in range(Q):
    l, r = map(int, input().split())
    for j in list:
        if l-1 <= j < r-1:
            count+=1
        else:
            count+=0
    print(count)

N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(0, N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append(i)
count=0
lis=[]
for i in range(Q):
    l, r = map(int, input().split())
    for j in range(l-1, r-1):
        lis.append(j)
        print(len(set(list) & set(lis)))

N, Q = map(int, input().split())
S=input()
count=0
for j in range(Q):
    l, r = map(int, input().split())
    s=S[l-1:r]
    count+=s.count("AC")
print(count)

N, Q = map(int, input().split())
S=list(input())
list=[0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list[i]+=1
count=0
for j in range(Q):
    l, r = map(int, input().split())
    count+=sum(list[l-1:r-1])
print(count)

N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(0, N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append(i)
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for i in list:
        if l-1 <= j < r-1:
            count+=1
            print(count)

N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(0, N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append(i)
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for i in list:
        if l-1 <= j <= r:
            count+=1
            print(count)

N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r+1):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

N, Q = map(int, input().split())
S=list(input())
list=[0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list[i]+=1
count=0
for j in range(Q):
    l, r = map(int, input().split())
    count+=sum(list[l-1:r])
print(count)

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

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

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

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Accepted