This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
n = int(input())
s = input()
q = int(input())
for _ in range(q):
a,b = map(int,input().split())
curr_c=0
curr_t=0
a-=1
curr = [1]*n
for i in range(a,b):
if s[i]=="C":
curr_c+=1
continue
curr_t+=1
if curr_t>curr_c:
curr_t-=1
curr[i]=0
b-=1
curr_c=0
curr_t=0
for i in range(b,a-1,-1):
if s[i]=="C":
curr_c+=1
continue
if curr[i]==0:
continue
curr_t+=1
if curr_t>curr_c:
curr_t-=1
curr[i]=0
print(curr.count(0))
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |