Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

from copy import deepcopy

def solve():
    N = int(raw_input())
    s = [int(_) for _ in raw_input().split()]
    ans = 0
    for A in range(1, N - 1):
        for B in range(1, A):
            if (N - 1) % (A - B) != 0 and (N - 1 - A) % (A - B) != 0:
                continue
            tmp_sum = 0
            pos = 0
            cnt = 0
            succ = True
            tmp_s = deepcopy(s)
            while pos < N - 1:
                if tmp_s[pos] is None:
                    succ = False
                    break
                else:
                    tmp_sum += tmp_s[pos]
                    tmp_s[pos] = None
                if cnt % 2 == 0:
                    pos += A
                else:
                    pos -= B
                cnt += 1
            if succ and pos == (N - 1):
                ans = max(ans, tmp_sum)
    print ans

if __name__ == '__main__':
    solve()


Fixed submission:
def solve2():
    N = int(raw_input())
    s = [int(_) for _ in raw_input().split()]
    ans = 0
    pass_set = set()
    for C in range(1, N - 1):
        pass_set.clear()
        maxK = (N - 1) / C
        score = 0 # when k = 0: 0 -> (N - 1)
        for k in range(1, maxK+1):
            if N - 1 - k*C < C:
                break
            if (N-1-k*C) in pass_set or k*C in pass_set or (N-1-k*C) == k*C:
                break
            else:
                score += s[N-1-k*C] + s[k*C] # DP
                pass_set.add(N-1-k*C)
                pass_set.add(k*C)
            ans = max(ans, score)
    print ans

if __name__ == '__main__':
    solve2()
Buggy python submission (verdict: Runtime Error):
MAX = 10**9 + 7

def solve():
    N = int(raw_input())
    arr = [int(_) for _ in raw_input().split()]
    xor_acu = [0] * (N + 1)
    for i in range(1, N + 1):
        xor_acu[i] = xor_acu[i - 1] ^ arr[i - 1]
    if xor_acu[N] != 0: # search for 0, X, 0, X ..., 0, X type
        X = xor_acu[N]
        dp0 = [1] * (N + 1)
        dpX = [0] * (N + 1)
        for i in range(1,N+1):
            dp0[i] = dp0[i-1] + dpX[i-1] if xor_acu[i] == 0 else dp0[i - 1]
            dpX[i] = dp0[i-1] + dpX[i-1] if xor_acu[i] == X else dpX[i - 1]
        ret = dp0[N - 1]
    else: # search for 0, X, 0, X ..., X, 0 type
        # X == 0 case
        tmp = 1
        Not0Set = set()
        for i in range(1, N):
            if xor_acu[i] == 0:
                tmp *= 2
            else:
                Not0Set.add(xor_acu[i])
        ret = tmp
        if ret > MAX:
            ret = ret % MAX
        # X != 0 case
        for X in list(Not0Set):
            RLE = [] # Run Length Encoding
            _tmp = xor_acu[0]
            cnt = 1
            all_cnt = 1
            for i in range (1, N+1):
                if xor_acu[i] == 0 or xor_acu[i] == X:
                    if xor_acu[i] == _tmp:
                        cnt += 1
                    else:
                        RLE.append((_tmp, cnt))
                        _tmp = xor_acu[i]
                        cnt = 1
                    all_cnt += 1
            RLE.append((_tmp, cnt))
            lRLE = all_cnt
            Not0dp0 = [1] * lRLE
            Not0dpX = [0] * lRLE
            ind = 1
            for i in range(len(RLE)):
                start = 1 if i == 0 else 0
                if RLE[i][0] == 0:
                    for j in range(start, RLE[i][1]):
                        Not0dp0[ind] = Not0dp0[ind - 1] + Not0dpX[ind - 1]
                        Not0dpX[ind] = Not0dpX[ind - 1]
                        ind += 1
                else:
                    for j in range(start, RLE[i][1]):
                        Not0dp0[ind] = Not0dp0[ind - 1]
                        Not0dpX[ind] = Not0dp0[ind - 1] + Not0dpX[ind - 1]
                        ind += 1
            ret += Not0dpX[ind - 2]
            if ret > MAX:
                ret = ret % MAX
    print str(ret)

if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    N, K = [int(_) for _ in raw_input().split()]
    ret = N - K + 1
    print str(ret)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N, K = [int(_) for _ in raw_input().split()]
    S = raw_input()
    elms = [S[0]]
    cnts = []
    cnt = 1
    for i in range(1,N):
        if S[i] == elms[-1]:
            cnt += 1
        else:
            cnts.append(cnt)
            elms.append(S[i])
            cnt = 1
    cnts.append(cnt)
    num_elm = len(elms)
    max_cont1 = 0
    for i in range(num_elm):
        if elms[i] == '1':
            tmp = sum(cnts[i:(i+2*K+1)])
            max_cont1 = max(max_cont1, tmp)
        elif i == 0:
            tmp = sum(cnts[i:(i+2*K)])
            max_cont1 = max(max_cont1, tmp)
    print str(max_cont1)

if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    N, K = [int(_) for _ in raw_input().split()]
    S = raw_input()
    elms = [S[0]]
    cnts = []
    cnt = 1
    for i in range(1,N):
        if S[i] == elms[-1]:
            cnt += 1
        else:
            cnts.append(cnt)
            elms.append(S[i])
            cnt = 1
    cnts.append(cnt)
    num_elm = len(elms)
    max_cont1 = 0
    tmp = 0
    for i in range(num_elm):
        if i == 0:
            if elms[i] == '0':
                tmp = sum(cnts[i:(i+2*K)])
                max_cont1 = max(max_cont1, tmp)
            if elms[i] == '1':
                tmp = sum(cnts[i:(i+2*K+1)])
                max_cont1 = max(max_cont1, tmp)
        elif i == 1:
            if elms[i] == '1':
                tmp -= cnts[i-1]
                if i + 2*K - 1 < num_elm:
                    tmp += cnts[i + 2*K - 1]
                if i + 2*K < num_elm:
                    tmp += cnts[i + 2*K]
                max_cont1 = max(max_cont1, tmp)
        else:
            if elms[i] == '1':
                tmp -= cnts[i - 2]
                tmp -= cnts[i - 1]
                if i + 2*K - 1 < num_elm:
                    tmp += cnts[i + 2*K - 1]
                if i + 2*K < num_elm:
                    tmp += cnts[i + 2*K]
                max_cont1 = max(max_cont1, tmp)
    print str(max_cont1)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
NUM_CITY = 6

def is_finish(state):
    return sum(state[:-1]) == 0

def solve():
    N = int(raw_input())
    A = int(raw_input())
    B = int(raw_input())
    C = int(raw_input())
    D = int(raw_input())
    E = int(raw_input())
    state = [0] * NUM_CITY
    state[0] = N
    cnt = 0
    while not is_finish(state):
        cnt += 1
        f1to2 = min(state[0], A)
        f2to3 = min(state[1], B)
        f3to4 = min(state[2], C)
        f4to5 = min(state[3], D)
        f5to6 = min(state[4], E)
        state[0] -= f1to2
        state[1] = state[1] + f1to2 - f2to3
        state[2] = state[2] + f2to3 - f3to4
        state[3] = state[3] + f3to4 - f4to5
        state[4] = state[4] + f4to5 - f5to6
        state[5] += f5to6
    print cnt

if __name__ == '__main__':
    solve()


Fixed submission:
def get_input():
    N = int(raw_input())
    A = int(raw_input())
    B = int(raw_input())
    C = int(raw_input())
    D = int(raw_input())
    E = int(raw_input())
    return N, A, B, C, D, E

def solve2():
    N, A, B, C, D, E = get_input()
    X = min(A, B, C, D, E)
    NdivX = (N  + X - 1) / X
    ret = 5 + NdivX - 1
    print ret

if __name__ == '__main__':
    solve2()
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(raw_input())
    S = raw_input() # str
    min_need_change = N
    for i in range(N):
        count = 0
        for j in range(0, i):
            if S[j] == 'W':
                count += 1
        for j in range(i+1, N):
            if S[j] == 'E':
                count += 1
        if count < min_need_change:
            min_need_change = count
    print str(min_need_change)

if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    N = int(raw_input())
    S = raw_input() # str
    count = 0
    for i in range(1, N): # count for leader is the 1st person case
        if S[i] == 'E':
            count += 1
    min_need_change = count
    for i in range(1,N): # count for leader is the 2nd, ... (N + 1)th person cases
        if S[i] == 'E':
            count -= 1
        if S[i - 1] == 'W':
            count += 1
        if count < min_need_change:
            min_need_change = count
    print str(min_need_change)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(raw_input())
    arr = []
    for i in range(N):
        arr.append(int(raw_input()))
    turning_on = 1
    count = 0
    turned_on_set = [1]
    while turning_on != 2:
        count += 1
        turning_on = arr[turning_on - 1]
        if turning_on in turned_on_set:
            count = -1
            break
        turned_on_set.append(turning_on)
    print str(count)

if __name__ == '__main__':
    solve()


Fixed submission:
def solve():
    N = int(raw_input())
    arr = []
    for i in range(N):
        arr.append(int(raw_input()))
    turning_on = 1
    count = 0
    while turning_on != 2:
        count += 1
        turning_on = arr[turning_on - 1]
        if count > N + 1:
            count = -1
            break
    print str(count)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
m = 10 ** 9 + 7
for i in range(N - 1):
    ans += A[i] * sum(A[i + 1:])
    ans %= m
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(a ** 2 for a in A)
m = 10 ** 9 + 7
ans = int((sum(A) ** 2) // 2)
ans %= m
ans -= int(sum(B) // 2)
ans %= m
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 0
m = 10 ** 9 + 7
for i in range(N - 1):
    for j in range(i + 1, N):
        ans += A[i] * A[j]
        ans %= m
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(a ** 2 for a in A)
m = 10 ** 9 + 7
ans = int((sum(A) ** 2) // 2)
ans %= m
ans -= int(sum(B) // 2)
ans %= m
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
a = 1
for i in range(N):
    if i < K:
        a *= A[i]
    else:
        old = a
        a //= A[i - K]
        a *= A[i]
        ans = 'No'
        if a > old:
            ans = 'Yes'
        print(ans)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N - K):
    ans = 'No'
    if A[i] < A[i + K]:
        ans = 'Yes'
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
a = 1
for i in range(K):
    a *= A[i]
old = a
for i in range(N - K):
    a //= A[i]
    a *= A[K + i]
    ans = 'No'
    if a > old:
        ans = 'Yes'
    print(ans)
    old = a

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N - K):
    ans = 'No'
    if A[i] < A[i + K]:
        ans = 'Yes'
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
a = 1
for i in range(K):
    a *= A[i]
B.append(a)
for i in range(N - K):
    a //= A[i]
    a *= A[K + i]
    B.append(a)
    ans = 'No'
    if a > B[i]:
        ans = 'Yes'
    print(ans)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N - K):
    ans = 'No'
    if A[i] < A[i + K]:
        ans = 'Yes'
    print(ans)
Buggy python submission (verdict: Runtime Error):
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
A = [0 for i in range(26)]
ans = 0
for i in range(D):
  t = int(input())
  A[t-1] = i+1
  c = 0
  for j in range(26):
    c += C[j] * (i+1-A[j])
  ans += S[i][t-1]-c
  print(ans)
  

Fixed submission:
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
for i in range(D):
  T = S[i]
  T.sort()
  a = S[i].index(T[-1])
  print(a)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
ans = 1
b = 1
c = 1
p = 10**18
    
for i in range(N):
  elif A[i] == 0:
    c = 0
    break
  else:
    ans *= A[i]
    if p < ans:
      b = -1
      ans = 0
if c == 0:
  print(c)
elif b == -1:
  print(b)
else:
  print(ans)
    
  

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
n0 = A.count(0)
n1 = A.count(1)
import math
ans = 1
if N-n0-n1>60:
  ans = -1
for i in range(N):
  if A[i] == 0 or ans == 0:
    ans = 0
    break
  elif ans <0:
    ans = -1
  elif math.log10(A[i])+math.log10(ans)>18:
    ans = -1
    b = 1
  else:
    ans *= A[i]

if ans == 0:
  print(0)
elif ans < 0:
  print(-1)
elif ans>10**18:
  print(-1)
else:
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
b = 1
c = 1
p = 10**18
for i in range(N):
  if A[i] == 0:
    c = 0
    break
  else:
    ans *= A[i]
    if p < ans:
      b = -1
if c == 0:
  print(c)
elif b == -1:
  print(b)
else:
  print(ans)
    
  

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
n0 = A.count(0)
n1 = A.count(1)
import math
ans = 1
if N-n0-n1>60:
  ans = -1
for i in range(N):
  if A[i] == 0 or ans == 0:
    ans = 0
    break
  elif ans <0:
    ans = -1
  elif math.log10(A[i])+math.log10(ans)>18:
    ans = -1
    b = 1
  else:
    ans *= A[i]

if ans == 0:
  print(0)
elif ans < 0:
  print(-1)
elif ans>10**18:
  print(-1)
else:
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
b = 0
import math
for i in range(N):
  if A[i] > 0 and ans >0:
    if math.log10(A[i])+math.log10(ans)>18:
    
      ans = -1
      b = 1
    else:
      ans *= A[i]
  else:
    ans *= A[i]

if ans == 0:
  print(ans)
elif b == 1:
  print(-1)
elif ans>10**18:
  print(-1)
else:
  print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
n0 = A.count(0)
n1 = A.count(1)
import math
ans = 1
if N-n0-n1>60:
  ans = -1
for i in range(N):
  if A[i] == 0 or ans == 0:
    ans = 0
    break
  elif ans <0:
    ans = -1
  elif math.log10(A[i])+math.log10(ans)>18:
    ans = -1
    b = 1
  else:
    ans *= A[i]

if ans == 0:
  print(0)
elif ans < 0:
  print(-1)
elif ans>10**18:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] != S[j]:
            for k in range(j + 1, N):
                if i - j != j - k:
                    if S[j] != S[k] and S[k] != S[i]:
                        ans += 1
print(ans)

Fixed submission:
N = int(input())
S = list(input())
r, g, b = 0, 0, 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1
ans = r * g * b
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if j - i != k - j:
                if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                    ans += 1
print(ans)

Fixed submission:
N = int(input())
S = list(input())
r, g, b = 0, 0, 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1
ans = r * g * b
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X, Y = map(int, input().split())
c = [0 for i in range(N)]
print(c)
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c[a]+=1

for i in range(1,N+1):
  ans = c[i]
  print(ans)
  


Fixed submission:
N, X, Y = map(int, input().split())
c = [0 for i in range(N)]
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c[a]+=1

for i in range(1,N):
  ans = c[i]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
c = []
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c.append(a)
for i in range(1,N):
  ans = c.count(i)
  print(ans)
  


Fixed submission:
N, X, Y = map(int, input().split())
c = [0 for i in range(N)]
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c[a]+=1

for i in range(1,N):
  ans = c[i]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
d = Y-X
c = []
for i in range(1,N):
  for j in range(i+1,N+1):
    if i <= X and j >= Y:
      c.append(j-i-d+1)
    elif i>=X and j <= Y:
      a = min(j-i, i-X+1+Y-j)
      c.append(a)
    elif i<= X and j <= Y:
      a = min(X-i+1+Y-j,j-i)
      c.append(a)
    else:
      a = min(j-Y+1+i-X,j-i)
      c.append(a)
for i in range(1,N):
  ans = c.count(i)
  print(ans)
  


Fixed submission:
N, X, Y = map(int, input().split())
c = [0 for i in range(N)]
for i in range(1,N):
  for j in range(i+1,N+1):
    x = abs(X-i)
    y = abs(Y-j)
    a = min(x+y+1,j-i)
    c[a]+=1

for i in range(1,N):
  ans = c[i]
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))
A = [(p + 1) / 2 for p in P]
ans = 0
for i in range(K - 1, N):
    a = 0
    for j in range(K):
        a += A[i - j]
    if a > ans:
        ans = a
print(ans)


Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
A = [(p + 1) / 2 for p in P]
B = [0 for i in range(N)]
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i - 1] + A[i]
ans = 0
for i in range(K - 1, N):
    if i == K - 1:
        a = B[i]
    else:
        a = B[i] - B[i - K]
    if ans < a:
        ans = a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
AC = []
WA = []
wa = 0
for i in range(M):
  p, S = input().split()
  p = int(p)
  if S == 'AC':
    if p in set(AC):
      continue
    else:
      AC.append(p)
      if p in set(WA):
        wa += WA.count(p)
  else:
    if p in set(AC):
      continue
    else:
      WA.append(p)
c = len(AC)
print(c, wa, sep=' ')

  

Fixed submission:
N, M = map(int, input().split())
AC = [0 for i in range(N)]
WA = [0 for i in range(N)]
a = [0 for i in range(N)]
for i in range(M):
  p, S = input().split()
  p = int(p)
  if S == 'AC':
    AC[p-1] = 1
    a[p-1] = 0
  else:
    if AC[p-1] == 0:
      WA[p-1] += 1
      a[p-1] += 1
c = sum(AC)
wa = sum(WA) - sum(a)
print(c, wa, sep=' ')

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
AC = []
WA = []
for i in range(M):
  p, S = input().split()
  p = int(p)
  if S == 'AC':
    AC.append(p)
  else:
    if p in set(AC):
      continue
    else:
      WA.append(p)
AC = list(set(AC))
c = len(AC)
wa = 0
for w in WA:
  if w in set(AC):
    wa += 1
print(c, wa, sep=' ')

Fixed submission:
N, M = map(int, input().split())
AC = [0 for i in range(N)]
WA = [0 for i in range(N)]
a = [0 for i in range(N)]
for i in range(M):
  p, S = input().split()
  p = int(p)
  if S == 'AC':
    AC[p-1] = 1
    a[p-1] = 0
  else:
    if AC[p-1] == 0:
      WA[p-1] += 1
      a[p-1] += 1
c = sum(AC)
wa = sum(WA) - sum(a)
print(c, wa, sep=' ')
Buggy python submission (verdict: Runtime Error):
N = int(input())
import math
n = int(math.sqrt(N))
s = 0
for i in range(1,n):
  if N%i == 0 and i > s:
    s = i
    
p = int(s+N/s-2)
print(p)

Fixed submission:
N = int(input())
s = N+1
import math
m = int(math.sqrt(N))+1
for i in range(1,m):
  if N%i==0:
    a = i
    b = N/a
    s = min(a+b, s)
print(int(s)-2)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
A = [0 for i in range(N)]
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    A[i] = 1
for i in range(Q):
  l, r = map(int, input().split())
  T = A[(l-1):(r-1)]
  ans = sum(T)
  print(ans)

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
A = [0 for i in range(N)]
a = 0
if S[0] == 'A':
  a = 1
for i in range(1,N):
  if a == 1 and S[i] == 'C':
    A[i] = 1
    a = 0
  if S[i] == 'A':
    a = 1
  else:
    a = 0
for i in range(Q):
  l, r = map(int, input().split())
  T = A[l:r]
  ans = sum(T)
  print(ans)

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
for i in range(Q):
  l, r = map(int, input().split())
  T = S[(l-1):r]
  n = len(T)
  a = 0
  ans = 0
  if T[0] == 'A':
    a = 1
  for j in range(1,n):
    if a == 1 and T[j] == 'C':
      ans += 1
      a = 0
    if T[j] == 'A':
      a = 1
    else:
      a = 0
  print(ans)

Fixed submission:
N, Q = map(int, input().split())
S = input()
A = []
a = 0
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    a += 1
    A.append(a)
  else:
    A.append(a)
for i in range(Q):
  l, r = map(int, input().split())
  if l>=2:
    ans = A[r-2]-A[l-2]
    print(ans)
  else:
    ans = A[r-2]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
ans = 0
i = 0
while len(S)>i+1:
  if S[i] != S[i+1]:
    S.pop(i)
    S.pop(i)
    ans += 2
    i = 0
  else:
    i = i+1
    
print(ans)

Fixed submission:
S = list(input())
a = 0
b = 0
for s in S:
  if s == '0':
    a += 1
  else:
    b += 1
ans = min(a,b)
ans = ans * 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A.sort()
i = 0
while i < N-1:
  
  if A[-1]%A[i]==0:
    A[-1] = 0
    i += 1
    A.sort()
  else:
    A[-1] = A[-1]%A[i]
    A.sort()
ans = A[-1]
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
g=A[0]
import fractions
for i in range(1,N):
  g = fractions.gcd(g,A[i])
print(g)