Buggy python submission (verdict: Time Limit Exceeded):
# 2019/03/24
# AtCoder Beginner Contest 122 - C
 
# Input
n, q = map(int,input().split())
s = input()
sab = list()
aclist = list()
 
j = 0
while(j < n-1):
    if s[j] == "A":
        if s[j+1] == "C":
            aclist.append(j+1)
            j += 2
        else:
            j += 1
    else:
        j += 1

for k in range(q):
    l, r = map(int,input().split())
    ans = 0
    
    t_idx = len(aclist) - 1
    b_idx = 0
    search_idx = int(len(aclist) / 2)
 
    while(b_idx + 1 < t_idx and aclist[search_idx] != l):
        if aclist[search_idx] > l:
            t_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)
        elif aclist[search_idx] < l:
            b_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)
    for i in range(search_idx, len(aclist), 1):
        if aclist[i] >= l:
            if aclist[i] < r:
                ans += 1
            else:
                break
        else:
            continue
 
    # Output
    print(ans)

Fixed submission:
# 2019/04/28
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()

acgt = ["A", "C", "G", "T"]
acgtl = list()
acgtl.append(0)

# Search AC and make Accumed sum
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acgtl.append(acgtl[i]+1)
    else:
        acgtl.append(acgtl[i])
        
# Calc AC count
for x in range(q):
    l, r = map(int,input().split())
    ans = acgtl[r-1] - acgtl[l-1]
    print(ans)

Buggy python submission (verdict: Runtime Error):
# 2019/03/24
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()
sab = list()
aclist = list()

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

for k in range(q):
    l, r = map(int,input().split())
    ans = 0
    
    t_idx = 0
    b_idx = len(aclist)
    search_idx = int(len(aclist) / 2)

    while(b_idx + 1 < t_idx and aclist[search_idx] == l):
        if aclist[search_idx] > l:
            t_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)
        elif aclist[search_idx] < l:
            b_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)

    for i in range(search_idx-1, len(aclist), 1):
        if aclist[i] >= l:
            if aclist[i] < r:
                ans += 1
            else:
                break
        else:
            continue

    # Output
    print(ans)


Fixed submission:
# 2019/04/28
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()

acgt = ["A", "C", "G", "T"]
acgtl = list()
acgtl.append(0)

# Search AC and make Accumed sum
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acgtl.append(acgtl[i]+1)
    else:
        acgtl.append(acgtl[i])
        
# Calc AC count
for x in range(q):
    l, r = map(int,input().split())
    ans = acgtl[r-1] - acgtl[l-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 2019/03/24
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()
sab = list()
aclist = list()

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

for k in range(q):
    l, r = map(int,input().split())
    ans = 0
    for i in range(len(aclist)):
        if aclist[i] >= l:
            if aclist[i] < r:
                ans += 1
            else:
                break
        else:
            continue

    # Output
    print(ans)


Fixed submission:
# 2019/04/28
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()

acgt = ["A", "C", "G", "T"]
acgtl = list()
acgtl.append(0)

# Search AC and make Accumed sum
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acgtl.append(acgtl[i]+1)
    else:
        acgtl.append(acgtl[i])
        
# Calc AC count
for x in range(q):
    l, r = map(int,input().split())
    ans = acgtl[r-1] - acgtl[l-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 2019/03/24
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()
sab = list()

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


Fixed submission:
# 2019/04/28
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()

acgt = ["A", "C", "G", "T"]
acgtl = list()
acgtl.append(0)

# Search AC and make Accumed sum
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acgtl.append(acgtl[i]+1)
    else:
        acgtl.append(acgtl[i])
        
# Calc AC count
for x in range(q):
    l, r = map(int,input().split())
    ans = acgtl[r-1] - acgtl[l-1]
    print(ans)