Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# D
import collections

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination_count(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
N = int(input())
A = list( map(int,input().split()))
c = dict(collections.Counter(A))
su = 0
for i in c.values():
    if (i >= 2):
        su += combinations_count(i, 2)

for i in A:
    if (c[i]  >= 3):
        print(su - combinations_count(c[i],2) + combinations_count(c[i]-1,2))
    elif (c[i] == 2):
        print(su - 1)
    else:
        print(su)

Fixed submission:
# D
import collections

def combinations_count(n, r):
    return n*(n-1) // 2

N = int(input())
A = list( map(int,input().split()))
c = dict(collections.Counter(A))
su = 0
for i in c.values():
    if (i >= 2):
        su += combinations_count(i, 2)

for i in A:
    if (c[i]  >= 3):
        print(su - combinations_count(c[i],2) + combinations_count(c[i]-1,2))
    elif (c[i] == 2):
        print(su - 1)
    else:
        print(su)

Buggy python submission (verdict: Time Limit Exceeded):
# D
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
A = list( map(int,input().split()))
c = dict(collections.Counter(A))
su = 0
for i in c.values():
    if (i >= 2):
        su += combinations_count(i, 2)

for i in A:
    if (c[i]  >= 3):
        print(su - combinations_count(c[i],2) + combinations_count(c[i]-1,2))
    elif (c[i] == 2):
        print(su - 1)
    else:
        print(su)

Fixed submission:
# D
import collections

def combinations_count(n, r):
    return n*(n-1) // 2

N = int(input())
A = list( map(int,input().split()))
c = dict(collections.Counter(A))
su = 0
for i in c.values():
    if (i >= 2):
        su += combinations_count(i, 2)

for i in A:
    if (c[i]  >= 3):
        print(su - combinations_count(c[i],2) + combinations_count(c[i]-1,2))
    elif (c[i] == 2):
        print(su - 1)
    else:
        print(su)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
Query = []
cnt_re = 0
for i in range(Q):
  tmp = input().split()
  Query.append(tmp)
  if (len(tmp) == 1):
    cnt_re += 1
prev = ''
after = ''
if (cnt_re % 2 != 0):
  S = list(reversed(S))
for q in Query:
  if (len(q) == 3):
    if q[1] == '1':
      if (cnt_re % 2 == 0):
        prev = q[2] + prev
      else:
        after = after + q[2]
    else:
      if (cnt_re % 2 == 0):
        after = after + q[2]
      else:
        prev = q[2] + prev
  else:
    cnt_re -= 1
print(prev + ''.join(list(S)) + after)

Fixed submission:
from collections import deque

S = list(input())
Q = int(input())
Query = []
cnt_re = 0
for i in range(Q):
    tmp = input().split()
    Query.append(tmp)
    if (len(tmp) == 1):
        cnt_re += 1
prev = deque()
after = deque()
if (cnt_re % 2 != 0):
    S = list(reversed(S))
for q in Query:
    if (len(q) == 3):
        if q[1] == '1':
            if (cnt_re % 2 == 0):
                prev.appendleft(q[2])
            else:
                after.append(q[2])
        else:
            if (cnt_re % 2 == 0):
                after.append(q[2])
            else:
                prev.appendleft(q[2])
    else:
        cnt_re -= 1
print(''.join(list(prev)) + ''.join(list(S)) + ''.join(list(after)))
Buggy python submission (verdict: Time Limit Exceeded):
# D

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N,A,B = map(int,input().split())
if (N == 2):
    print(0)
else:
    print((2**N - 1 - combinations_count(N, A) - combinations_count(N, B)) % (10**9+7))

Fixed submission:
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

N,A,B = map(int,input().split())
if (N == 2):
    print(0)
else:
    print((2**N - 1 - combination(N, A) - combination(N, B)) % (10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
# D
N, K = map(int, input().split())
lst = list(map(int, input().split()))
ma = 0
for i in range(len(lst)-(K-1)):
    if (ma < sum(lst[i:i+K])):
        ma = sum(lst[i:i+K])
print((ma + K) / 2)


Fixed submission:
# D
N, K = map(int, input().split())
lst = list(map(int, input().split()))
lst1 = [(lst[0] + 1) / 2]
ma = 0
for i in range(1, len(lst)):
    lst1.append(lst1[i-1] + ((lst[i]+1) / 2))
    if (i >= K):
        ma = max(ma,lst1[i] - lst1[i-K])
ma = max(ma,lst1[K-1])
print(ma)

Buggy python submission (verdict: Time Limit Exceeded):
# D
N, K = map(int, input().split())
lst = list(map(int, input().split()))
ma = 0
idx = 0
for i in range(len(lst)-(K-1)):
    if (ma < sum(lst[i:i+K])):
        ma = sum(lst[i:i+K])
        idx = i
ans = 0
for i in lst[idx:idx+K]:
    ans += (i+1) / 2 
print(ans)


Fixed submission:
# D
N, K = map(int, input().split())
lst = list(map(int, input().split()))
lst1 = [(lst[0] + 1) / 2]
ma = 0
for i in range(1, len(lst)):
    lst1.append(lst1[i-1] + ((lst[i]+1) / 2))
    if (i >= K):
        ma = max(ma,lst1[i] - lst1[i-K])
ma = max(ma,lst1[K-1])
print(ma)
Buggy python submission (verdict: Runtime Error):
# C
X = int(input())
import math

def isPrime(n):
    if n % 2 == 0:
        return False
  
    m = math.floor(math.sqrt(n))
    for p in prime_numbers:
        if n % p == 0:
            return False
        if p > m:
        # 素数がnの平方根を超えたら終了
            break
    return True

for i in range(X, 10**9):
    if (is_prime(i)):
        print(i)
        break

Fixed submission:
# C
X = int(input())
import math

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

for i in range(X, 10**9):
    if (is_prime(i)):
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
N = int(input())
lst = []
for i in range(N):
  for j in range(int(input())):
    lst.append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
  flag = True
  bin_lst = list(bin(i)[2:].zfill(N))
  for idx,j in enumerate(bin_lst):
    if (j == '1'):
      for v, w in zip(lst[idx][:-1],lst[idx][1:]):
        if (bin_lst[v-1] != str(w)):
          flag = False
  if (flag):
    ans = max(ans,bin_lst.count('1'))
print(ans)


Fixed submission:
N = int(input())
lst = [[] for i in range(N)]
for i in range(N):
  for j in range(int(input())):
    lst[i].append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
  flag = True
  bin_lst = list(bin(i)[2:].zfill(N))
  for idx,j in enumerate(bin_lst):
    if (j == '1'):
      for v, w in lst[idx]:
        if (bin_lst[v-1] != str(w)):
          flag = False
  if (flag):
    ans = max(ans,bin_lst.count('1'))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = input()
ans = 0
for i in range(1000):
  num = str(i).zfill(3)
  flag1 = True
  flag2 = True
  flag3 = True
  first = -1
  second = -1
  third = -1
  for j in range(s):
    if (s[j] == num[0] and flag1):
      first = j
      flsg1 = False
    if (s[j] == num[1] and j > first and flag2):
      second = j
      flsg2 = False
    if (s[j] == num[2] and j > second and flag3):
      second = j
      flsg3 = False
  if (first != -1 and second != -1 and third != -1):
    ans += 1
print(ans)

Fixed submission:
N = int(input())
s = input()
ans = 0
for i in range(1000):
  code = str(i).zfill(3)
  f = 0
  for j in range(len(s)):
    if (s[j] == code[f]):
      f += 1
    if (f == 3):
      break
  if (f == 3):
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
# C
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
ans = N - 1
lst = make_divisors(N)
for i in range(0, len(lst), 2):
    num = lst[i] + lst[i+1] - 2
    ans = min(ans,num)

print(ans)

Fixed submission:
# C
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
ans = N - 1
lst = make_divisors(N)
if (len(lst) % 2 == 0):
    for i in range(0, len(lst), 2):
        num = lst[i] + lst[i+1] - 2
        ans = min(ans,num)
else:
    for i in range(0, len(lst)-1, 2):
        num = lst[i] + lst[i+1] - 2
        ans = min(ans,num)
    ans = min(ans,2*lst[-1] - 2)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
lst = []

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

ans = 0
for i in lst:
  ans += i // 2
print(ans*K)

Fixed submission:
S = input()
K = int(input())
lst = []

cnt = 1
ans = 0
if (len(S) != 1):
  for i in range(len(S)-1):
    if (S[i] == S[i+1]):
      cnt += 1
      if (i == len(S)-2):
        lst.append(cnt)
    else:
      lst.append(cnt)
      cnt = 1
      
  if (len(lst) == 1):
    ans = len(S)*K // 2
  else:
    for i in lst:
      ans += i // 2
    ans *= K
    
    if (S[0] == S[-1] and lst[0] % 2 != 0 and lst[-1] % 2 != 0):
      ans += K-1
else:
  ans = K // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# D
import math
A,B = map(int,input().split())

def cf(x1,x2):
    cf=[1]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def coprime(a, b):
    return len(cf(a, b)) == 1

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
ans = 0
for i in cf(A,B):
    if (is_prime(i)):
        ans += 1
print(ans+1)

Fixed submission:
a,b = list(map(int, input().split()))
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

c = set(make_divisors(a))
d = set(make_divisors(b))
e = list(c & d)

f = []
for i in range(len(e)):
        if is_prime(e[i]):
            f.append(e[i])
print(len(f) + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = [i for i in range(N)]
print(sum(ans))

Fixed submission:
N = int(input())

print(N * (N-1) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0
for i in range(N):
  ans += i
print(ans)

Fixed submission:
N = int(input())

print(N * (N-1) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0
for i in range(N):
  ans += i
print(ans)

Fixed submission:
N = int(input())

print(N * (N-1) // 2)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

def dfs(graph, start):
    stack = [start]
    visited = []
    while stack:
        label = stack.pop(0)
        if label not in visited:
            visited.append(label)
            stack = graph.get(label, []) + stack
    return visited
  
tree = defaultdict(list)
N,Q = map(int, input().split())

lst1 = [list(map(int, input().split())) for i in range(N-1)]
lst2 = [list(map(int, input().split())) for i in range(Q)]
for i in range(N):
  dict(tree)[i+1] = []
for i in lst1:
  tree[i[0]].append(i[1])
ans = [0] * N
memo = {}
for i in lst2:
  start = i[0]
  visited = []
  if (start == 1):
      ans = list(map(lambda x: x + i[1], ans))
  else:
    if start not in memo.keys():
      memo[start] = dfs(dict(tree), start)
    for j in memo[start]:
      if (start <= j):
        ans[j-1] += i[1]
print(" ".join(list(map(str,ans))))

Fixed submission:
a = int(input())

s = input()
ans = s
if (a < 3200):
  ans = 'red'
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

lst = list(map(int, input().split()))

flag = "Yes"
cnt = 0
if (N > 1):
  for i in range(len(lst) - 1):
    if (lst[i+1] - lst[i] < 0):
      cnt += 1
    else:
      cnt = 0
      
    if (cnt > 1):
      flag = "No"

print(flag)

Fixed submission:
A, B, C = map(int, input().split())

if (A - B >= C):
  print(0)
else:
  print(C - (A - B))
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = 0
lst = list(map(int, input().split()))
slice_lst = lst[:int(N / 2)]
for i,k in enumerate(reversed(slice_lst)):
  sub_lst = lst[len(slice_lst)-i-1:len(lst):len(slice_lst)-i]
  if (k != sum(sub_lst) % 2):
    if (k == 0):
      lst[len(slice_lst)-i-1] = 1
    else:
      ans = -1
      break

if (ans == -1):
  print(ans)
else:
  ans_lst = []
  for i,k in enumerate(lst):
    if (k == 1):
      ans_lst.append(str(i+1))
  print(len(ans_lst))
  result = ' '.join(ans_lst)
  print(result)

Fixed submission:
r = int(input())

print(3 * r **2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
lst = list(map(int, input().split()))
S = sum(lst)
ans = []

for i in range(2, N, 2):
  S -= 2 *lst[i-1]
  
ans.append(S)

for i in range(1, N):
  ans.append(2 * lst[i-1] - ans[i-1])
print("".join(ans))

Fixed submission:
N = int(input())
lst = list(map(int, input().split()))
S = sum(lst)
ans = []

for i in range(2, N, 2):
  S -= 2 *lst[i-1]
  
ans.append(S)

for i in range(1, N):
  ans.append(2 * lst[i-1] - ans[i-1])

s = " ".join([str(n) for n in ans])
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int, input().split()))

lst1 = [int(input()) for i in range(M)]

from functools import lru_cache
@lru_cache(maxsize=None)

def fib(n):
  a, b = 1, 2
  for i in range(1,n+1):  
    if (i == 1):
      if (i in lst1):
        a, b = 0, 1
    else:
      if (i in lst1):
        a, b = 0, a
      else:
        a, b = b, b+a
  return a

print(fib(N)  % 1000000007)

Fixed submission:
n,m=map(int,input().split())
D=[1] * (n + 1)
for _ in range(m):
    D[int(input())] = 0
for i in range(n+1):
    if i > 1:
        D[i] = (D[i-1] + D[i-2]) % 1000000007 * D[i]
print(D[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int, input().split()))

lst1 = [int(input()) for i in range(M)]

def fib(n):
  a, b = 1, 2
  for i in range(1,n+1):  
    if (i == 1):
      if (i in lst1):
        a, b = 0, 1
    else:
      if (i in lst1):
        a, b = 0, a
      else:
        a, b = b, b+a
  return a

print(fib(N)  % 1000000007)

Fixed submission:
n,m=map(int,input().split())
D=[1] * (n + 1)
for _ in range(m):
    D[int(input())] = 0
for i in range(n+1):
    if i > 1:
        D[i] = (D[i-1] + D[i-2]) % 1000000007 * D[i]
print(D[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int, input().split()))

lst1 = [int(input()) for i in range(M)]

from functools import lru_cache
@lru_cache(maxsize=1000000007)
def fib(n):
  a, b = 1, 2
  for i in range(1,n+1):  
    if (i == 1):
      if (i in lst1):
        a, b = 0, 1
      yield a
    else:
      if (i in lst1):
        a, b = 0, a
      else:
        a, b = b, b+a
      yield a

lst2 = [i for i in fib(N)]
print(lst2[-1] % 1000000007)

Fixed submission:
n,m=map(int,input().split())
D=[1] * (n + 1)
for _ in range(m):
    D[int(input())] = 0
for i in range(n+1):
    if i > 1:
        D[i] = (D[i-1] + D[i-2]) % 1000000007 * D[i]
print(D[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int, input().split()))

lst1 = [int(input()) for i in range(M)]

def fib(n):
  a, b = 1, 2
  for i in range(1,n+1):  
    if (i == 1):
      if (i in lst1):
        a, b = 0, 1
      yield a
    else:
      if (i in lst1):
        a, b = 0, a
      else:
        a, b = b, b+a
      yield a

lst2 = [i for i in fib(N)]
print(lst2[-1] % 1000000007)

Fixed submission:
n,m=map(int,input().split())
D=[1] * (n + 1)
for _ in range(m):
    D[int(input())] = 0
for i in range(n+1):
    if i > 1:
        D[i] = (D[i-1] + D[i-2]) % 1000000007 * D[i]
print(D[i])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
l, r = map(int, input().split())
for i in range(M-1):
  L, R = map(int, input().split())
  if (L >= l):
    l = L
  if (R =< r):
    r = R
print(r - l + 1)

Fixed submission:
N, M = map(int, input().split())
l, r = map(int, input().split())
cnt = 0
num = 0
if (l == r):
  cnt += 1
  num = l
for i in range(M-1):
  L, R = map(int, input().split())
  if (cnt == 1 and L == R and num == L):
    num = L
  elif (cnt == 1 and L == R and num != L):
    cnt += 1
    print(0)
    break
  elif (cnt == 0 and L == R):
    cnt += 1
    num = L
  elif ((cnt == 0 or cnt == 1) and L != R):
    if (L >= l):
      l = L
    if (R <= r):
      r = R
      
if (l > r and (cnt == 0 or cnt == 1)):
  print(0)
elif(l <= r and (cnt == 0 or cnt == 1)):
  if (num != 0 and cnt == 1):
    if (num >= l and num <= r):
      print(1)
    else:
      print(0)
  elif(cnt == 0 or cnt == 1):
    print(r - l + 1)
Buggy python submission (verdict: Runtime Error):
lst = list(map(int, input().split()))
N = lst.pop(3)
lst.sort(reverse=True)
R,G,B = lst
sum = 0
for i in range(int(N / R) + 1):
  for j in range(int((N - (i * R)) / G) + 1):
    for k in range(int((N - (i * R) - (j * G)) / B) + 1):
      ans = i * R + j * G + k * B
      if (ans == N):
        sum += 1
print(sum)

Fixed submission:
N, K = map(int, input().split())
print(N-K+1)
Buggy python submission (verdict: Time Limit Exceeded):
lst = list(map(int, input().split()))
N = lst.pop(3)
lst.sort(reverse=True)
R,G,B = lst
sum = 0
for i in range(int(N / R) + 1):
  for j in range(int((N - (i * R)) / G) + 1):
    for k in range(int((N - (i * R) - (j * G)) / B) + 1):
      ans = i * R + j * G + k * B
      if (ans == N):
        sum += 1
print(sum)

Fixed submission:
R,G,B,N = map(int, input().split())

sum = 0
for i in range(N // R + 1):
  for j in range(N // G + 1):
    b = N - (i * R) - (j * G)
    if (b >= 0 and b % B == 0):
      sum += 1
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int, input().split())
sum = 0
for i in range(int(N / R) + 1):
  for j in range(int((N - (i * R)) / G) + 1):
    for k in range(int((N - (i * R) - (j * G)) / B) + 1):
      ans = i * R + j * G + k * B
      if (ans == N):
        sum += 1
print(sum)


Fixed submission:
R,G,B,N = map(int, input().split())

sum = 0
for i in range(N // R + 1):
  for j in range(N // G + 1):
    b = N - (i * R) - (j * G)
    if (b >= 0 and b % B == 0):
      sum += 1
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int, input().split())
sum = 0
for i in range(int(N / R) + 1):
  for j in range(int(N / G) + 1):
    for k in range(int(N / B) + 1):
      ans = i * R + j * G + k * B
      if (ans == N):
        sum += 1
print(sum)


Fixed submission:
R,G,B,N = map(int, input().split())

sum = 0
for i in range(N // R + 1):
  for j in range(N // G + 1):
    b = N - (i * R) - (j * G)
    if (b >= 0 and b % B == 0):
      sum += 1
print(sum)
Buggy python submission (verdict: Runtime Error):
import math
array1 = [int(input()) for i in range(6)]
array2 = array1[1:6]
num = array1[0]
minimum = min(array2)
print(math.ceil(num / minimum + 4)

Fixed submission:
import math
array1 = [int(input()) for i in range(6)]
array2 = array1[1:6]
num = array1[0]
minimum = min(array2)
print(math.ceil(num / minimum) + 4)

Buggy python submission (verdict: Time Limit Exceeded):
array1 = [int(input()) for i in range(6)]
array2 = array1[1:6]
array2.append(0)
array3 = [array1[0], 0, 0, 0, 0, 0]
move = [0, 0, 0, 0, 0]
t = 0
while (array3[-1] != array1[0]):
  for i in range(5):
    if ( array3[i] >= array2[i]):
      move[i] = array2[i]
    else:
      if (array3[i] == 0):
        move[i] = 0
      else:
        move[i] = array3[i]
  for i in range(5):
    array3[i] = array3[i] - move[i]
    array3[i+1] = array3[i+1] + move[i]
  t += 1
print(t)

Fixed submission:
import math
array1 = [int(input()) for i in range(6)]
array2 = array1[1:6]
num = array1[0]
minimum = min(array2)
print(math.ceil(num / minimum) + 4)
Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
str = input()
for i in range(q):
  l,r = map(int, input().split())
  sub_str = str[(l-1):r]
  count = 0
  for j in range(len(sub_str)):
    if (sub_str[j:j+2] == 'AC'):
      count += 1
  print(count)

Fixed submission:
b = input()
 
if (b == 'A'):
  print('T')
elif (b == 'T'):
  print('A')
elif (b == 'C'):
  print('G')
elif (b == 'G'):
  print('C')
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
str = input()
for i in range(q):
  l,r = map(int, input().split())
  sub_str = str[(l-1):r]
  count = 0
  for j in range(len(sub_str)):
    if (sub_str[j:j+2] == 'AC'):
      count += 1
  print(count)

Fixed submission:
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])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
str = input()
for i in range(q):
  l,r = map(int, input().split())
  sub_str = str[(l-1):r]
  print(sub_str.count('AC'))

Fixed submission:
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])

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q = map(int, input().split())
str = input()
for i in range(q):
  l,r = map(int, input().split())
  sub_str = str[(l-1):r]
  print(len(re.findall('AC', sub_str)))


Fixed submission:
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])

Buggy python submission (verdict: Runtime Error):
import re
 
a = []
for i in range(5):
    a.append(input().split())
n = int(a[0][0])
q = int(a[0][1])
str = a[1][0]
b = a[2:]
for i in b:
  l = int(i[0])
  r = int(i[1])
  sub_str = str[(l-1):r]
  print(len(re.findall('AC', sub_str)))

Fixed submission:
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])

Buggy python submission (verdict: Runtime Error):
import re

a = []
for i in range(5):
    a.append(input().split())
n = int(a[0][0])
q = int(a[0][1])
str = a[1][0]
b = a[2:]
for i in b:
  l = int(i[0])
  r = int(i[1])
  sub_str = str[(l-1):r]
  print(len(re.findall('AC', sub_str)))

Fixed submission:
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])
Buggy python submission (verdict: Runtime Error):
H,W = map(int, input())
h,w = map(int, input())

sum = H * w
cnt = W * h + w * (H - h)
print(sum - cnt)

Fixed submission:
H,W = map(int, input().split())
h,w = map(int, input().split())

sum = H * W
cnt = (W * h) + (w * (H - h))
print(sum - cnt)
Buggy python submission (verdict: Runtime Error):
def cd(a,b):
  p = min(a,b)
  q = max(a,b)
  lst = []
  for i in range(1, p + 1):
    if (p % i == 0 and q % i == 0):
      lst.append(i)
  return lst
 
A,B,K = map(int, input().split())
lst = cd(A,B)
print(lst[-1 - K-1])

Fixed submission:
def cd(a,b):
  p = min(a,b)
  q = max(a,b)
  lst = []
  for i in range(1, p + 1):
    if (p % i == 0 and q % i == 0):
      lst.append(i)
  return lst
 
A,B,K = map(int, input().split())
lst = cd(A,B)
print(lst[-K])