Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import itertools

def main():
    a,b = map(int,input().split())
    datas = list(range(a,b+1))
    answer=1
    if a == 0 or b ==0 or (a<0 and b>0):
        print("Zero")
        exit()
    else:
        if abs(a-b)%2!=0:
            print("Positive")
        else:
            print("Negative")

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b = map(int,input().split())
    if a == 0 or b ==0 or (a<0 and b>0):
        print("Zero")
        exit()
    else:
        if a > 0 and b > 0:
            print("Positive")
        elif abs(a-b)%2!=0:
            print("Positive")
        else:
            print("Negative")

if __name__=="__main__":
    main()

Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import itertools

def main():
    a,b = map(int,input().split())
    datas = list(range(a,b+1))
    answer=1
    if 0 in datas:
        print("Zero")
        exit()
    else:
        for i in datas:
            answer*=i
    if answer>=0:
        print("Positive")
    else:
        print("Negative")

if __name__=="__main__":
    main()

Fixed submission:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b = map(int,input().split())
    if a == 0 or b ==0 or (a<0 and b>0):
        print("Zero")
        exit()
    else:
        if a > 0 and b > 0:
            print("Positive")
        elif abs(a-b)%2!=0:
            print("Positive")
        else:
            print("Negative")

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
l = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
  _a, _b = map(int, input().split())
  l[_a - 1][_b - 1] = 1

l = np.array(l)
csr = csr_matrix(l)

print(connected_components(csr, return_labels=False) - 1)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
data = [1 for i in range(m)]
a = []
b = []

for i in range(m):
  _a, _b = map(int, input().split())
  a.append(_a - 1)
  b.append(_b - 1)

csr = csr_matrix((data, (a, b)), (n, n))

print(connected_components(csr, return_labels=False) - 1)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb_flag = [[False for i in range(w)] for j in range(h)]

for i in range(m):
  _h, _w = map(int, input().split())
  h_cnt[_h - 1] += 1
  w_cnt[_w - 1] += 1
  bomb_flag[_h - 1][_w - 1] = True

h_max = max(h_cnt)
w_max = max(w_cnt)

max_h = []
max_w = []

for i in range(h):
  if h_cnt[i] == h_max:
    max_h.append(i)

for j in range(w):
  if w_cnt[j] == w_max:
    max_w.append(j)

flag = True

for i in max_h:
  for j in max_w:
    if not bomb_flag[i][j]:
      flag = False
      break

print(h_max + w_max - 1 if flag else h_max + w_max)

Fixed submission:
h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()

for i in range(m):
  _h, _w = map(int, input().split())
  h_cnt[_h - 1] += 1
  w_cnt[_w - 1] += 1
  bomb.add(((_h - 1),(_w - 1)))

h_max = max(h_cnt)
w_max = max(w_cnt)

max_h = []
max_w = []

for i in range(h):
  if h_cnt[i] == h_max:
    max_h.append(i)

for j in range(w):
  if w_cnt[j] == w_max:
    max_w.append(j)

flag = True

for i in max_h:
  for j in max_w:
    if (i, j) not in bomb:
      flag = False
      break

print(h_max + w_max - 1 if flag else h_max + w_max)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb_flag = [[False for i in range(w)] for j in range(h)]

for i in range(m):
  _h, _w = map(int, input().split())
  h_cnt[_h - 1] += 1
  w_cnt[_w - 1] += 1
  bomb_flag[_h - 1][_w - 1] = True

h_max = max(h_cnt)
w_max = max(w_cnt)
flag = True

for i in range(h):
  if not flag:
    break
  if h_cnt[i] != h_max:
    continue
  for j in range(w):
    if w_cnt[j] != w_max:
      continue
    if not bomb_flag[i][j]:
      flag = False
      break

print(h_max + w_max - 1 if flag else h_max + w_max)

Fixed submission:
h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()

for i in range(m):
  _h, _w = map(int, input().split())
  h_cnt[_h - 1] += 1
  w_cnt[_w - 1] += 1
  bomb.add(((_h - 1),(_w - 1)))

h_max = max(h_cnt)
w_max = max(w_cnt)

max_h = []
max_w = []

for i in range(h):
  if h_cnt[i] == h_max:
    max_h.append(i)

for j in range(w):
  if w_cnt[j] == w_max:
    max_w.append(j)

flag = True

for i in max_h:
  for j in max_w:
    if (i, j) not in bomb:
      flag = False
      break

print(h_max + w_max - 1 if flag else h_max + w_max)
Buggy python submission (verdict: Runtime Error):
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))

left = 0
right = max(a)

while True:
  mid = (left + right) // 2
  
  cnt = 0
  for _a in a:
    cnt += math.ceil(_a / mid - 1)
  
  if cnt > k:
    left = mid
  else:
    right = mid
  
  if right - left <= 1:
    break

print(right)

Fixed submission:
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))

left = 0
right = max(a)

while True:
  mid = (left + right) // 2
  
  if mid == 0:
    cnt = 10 ** 10
  else:
    cnt = 0
    for _a in a:
      cnt += math.ceil(_a / mid - 1)
  
  if cnt > k:
    left = mid
  else:
    right = mid
  
  if right - left <= 1:
    break

print(right)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
history = []

pos = 0
cnt = 0
while pos not in history and cnt < k:
  history.append(pos)
  pos = a[pos] - 1
  cnt += 1

if cnt == k:
  print(pos + 1)
else:
  cnt_before = history.index(pos)
  print(history[cnt_before + (k - cnt_before) % (cnt - cnt_before)] + 1)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
history = []
mark = set()

pos = 0
cnt = 0
while pos not in mark and cnt < k:
  history.append(pos)
  mark.add(pos)
  pos = a[pos] - 1
  cnt += 1

if cnt == k:
  print(pos + 1)
else:
  cnt_before = history.index(pos)
  print(history[cnt_before + (k - cnt_before) % (cnt - cnt_before)] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
reverse_flag = False

for i in range(q):
  query = input().split()
  if query[0] == "1":
    reverse_flag = not reverse_flag
  else:
    if (query[1] == "1") ^ reverse_flag:
      s = query[2] + s
    else:
      s += query[2]

print(s[::-1] if reverse_flag else s)

Fixed submission:
from collections import deque

d = deque(input())
q = int(input())
reverse_flag = False

for i in range(q):
  query = input().split()
  if query[0] == "1":
    reverse_flag = not reverse_flag
  else:
    if (query[1] == "1") ^ reverse_flag:
      d.appendleft(query[2])
    else:
      d.append(query[2])

print("".join(list(d)[::-1]) if reverse_flag else "".join(d))
Buggy python submission (verdict: Runtime Error):
from scipy.misc import comb

def f(n_str, k):
  while n_str[0] == '0':
    n_str = n_str[1:]
  if n_str == "":
    return 0
  if k == 1:
    return int(n_str[0]) + 9 * (len(n_str) - 1)
  else:
    return (int(n_str[0]) - 1) * f('9' * (len(n_str) - 1), k - 1) + f(n_str[1:], k - 1) + 9 ** k * comb(len(n_str) - 1, k, exact=True)

n = input()
k = int(input())

print(f(n, k))

Fixed submission:
from scipy.misc import comb

def f(n_str, k):
  while len(n_str) > 0 and n_str[0] == '0':
    n_str = n_str[1:]
  if len(n_str) < k:
    return 0
  if k == 1:
    return int(n_str[0]) + 9 * (len(n_str) - 1)
  else:
    return (int(n_str[0]) - 1) * f('9' * (len(n_str) - 1), k - 1) + f(n_str[1:], k - 1) + 9 ** k * (comb(len(n_str) - 1, k, exact=True) if len(n_str) > k else 0)

n = input()
k = int(input())

print(f(n, k))
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
monster = [[0, 0] for i in range(n)]

for i in range(n):
  a, b = map(int, input().split())
  monster[i][0], monster[i][1] = a, b

dps = [0 for i in range(h + 1)]
for i in range(1, h + 1):
  ans = 10 ** 10
  for m in monster:
    ans = min(ans, dps[max(i - m[0], 0)] + m[1])
  dps[i] = ans

print(dps[h])

Fixed submission:
h, n = map(int, input().split())
monster = [[0, 0] for i in range(n)]
 
for i in range(n):
  a, b = map(int, input().split())
  monster[i][0], monster[i][1] = a, b

dps = [0 for i in range(h + 1)]
for i in range(1, h + 1):
  ans = 10 ** 10
  for m in monster:
    ans = min(ans, dps[max(i - m[0], 0)] + m[1])
  dps[i] = ans

print(dps[h])
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

PRIME = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))

if n == 1:
  print(1)
else:
  lcm = a[0]
  for i in range(1, n):
    lcm = lcm * a[i] // int(fractions.gcd(lcm, a[i]))
  
  ans = 0
  for i in range(n):
    ans = (ans + lcm // a[i]) % PRIME
  
  print(ans)

Fixed submission:
import fractions
 
PRIME = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
 
if n == 1:
  print(1)
else:
  lcm = a[0]
  for i in range(1, n):
    lcm = lcm * a[i] // int(fractions.gcd(lcm, a[i]))
  
  ans = 0
  for i in range(n):
    ans += lcm // a[i]
  
  print(ans % PRIME)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions

PRIME = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))

if n == 1:
  print(1)
else:
  lcm = a[0]
  for i in range(1, n):
    lcm = lcm * a[i] // int(fractions.gcd(lcm, a[i]))
  
  ans = 0
  for i in range(n):
    ans = (ans + lcm // a[i]) % PRIME
  
  print(ans)

Fixed submission:
import fractions
 
PRIME = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
 
if n == 1:
  print(1)
else:
  lcm = a[0]
  for i in range(1, n):
    lcm = lcm * a[i] // int(fractions.gcd(lcm, a[i]))
  
  ans = 0
  for i in range(n):
    ans += lcm // a[i]
  
  print(ans % PRIME)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

k = 0
idx = -1
while True:
  if k + 1 in a[(idx + 1):]:
    idx += a[(idx + 1):].index(k + 1) + 1
    k += 1
  else:
    break

print(n - k if k > 0 else -1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

k = 0

for i in range(n):
  if a[i] == k + 1:
    k += 1

print(n - k if k > 0 else -1)
Buggy python submission (verdict: Runtime Error):
import bisect

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
  a[i] -= 1
  a[i + 1] += a[i]
a[n - 1] -= 1

memo = {}
for i in range(n):
  if a[i] % k not in memo.keys():
    memo[a[i] % k] = [i]
  else:
    memo[a[i] % k].append(i)

ans = bisect.bisect_left(memo[0], k - 1)

for i in memo.keys():
  for j in range(len(memo[i]) - 1):
    ans += bisect.bisect_left(memo[i], memo[i][j] + k) - 1 - j

print(ans)

Fixed submission:
import bisect

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
  a[i] -= 1
  a[i + 1] += a[i]
a[n - 1] -= 1

memo = {0 : []}
for i in range(n):
  if a[i] % k not in memo.keys():
    memo[a[i] % k] = [i]
  else:
    memo[a[i] % k].append(i)

ans = bisect.bisect_left(memo[0], k - 1)

for i in memo.keys():
  for j in range(len(memo[i]) - 1):
    ans += bisect.bisect_left(memo[i], memo[i][j] + k) - 1 - j

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
l = list(map(int, input().split()))

l.sort()

ans = 0

for i in range(1, n - 1):
  for j in range(i + 1, n):
    if l[i] * 2 > l[j]:
      idx = bisect.bisect_left(l, l[j] - l[i] + 0.5)
      ans += max(i - idx, 0)

print(ans)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))

l.sort()

ans = 0

for i in range(1, n - 1):
  for j in range(i + 1, n):
    if l[i] * 2 > l[j]:
      idx = bisect.bisect_left(l, l[j] - l[i] + 0.5)
      ans += max(i - idx, 0)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
m = {}

for i in range(n):
  s = "".join(sorted(list(input())))
  if s in m.keys():
    m[s] = m[s] + 1
  else:
    m[s] = 1

ans = 0
for s in m.keys():
  ans += m[s] * (m[s] - 1) // 2

print(ans)

Fixed submission:
n = int(input())
m = {}
 
for i in range(n):
  s = "".join(sorted(list(input())))
  if s in m.keys():
    m[s] = m[s] + 1
  else:
    m[s] = 1
 
ans = 0
for s in m.keys():
  ans += m[s] * (m[s] - 1) // 2
 
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.matrix(list(map(int, input().split()))).T
_a = np.eye(n) + np.roll(np.eye(n),1, axis=1)
ans = map(int, np.linalg.inv(_a) * a * 2)
ans = map(str, ans)
print(" ".join(ans))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
b[0] = sum(a) - sum(a[1::2]) * 2
b[1] = a[0] * 2
for i in range(2, n):
  b[i] = b[i-2] + a[i-1] * 2
c = [0 for i in range(n)]
c[0] = b[0]
for i in range(1, n):
  c[i] = b[i] - b[i-1]

ans = map(str, c)
print(" ".join(ans))

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
_a = np.eye(n) + np.roll(np.eye(n),1, axis=1)
ans = map(int, np.linalg.solve(_a, a) * 2)
ans = map(str, ans)
print(" ".join(ans))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
b[0] = sum(a) - sum(a[1::2]) * 2
b[1] = a[0] * 2
for i in range(2, n):
  b[i] = b[i-2] + a[i-1] * 2
c = [0 for i in range(n)]
c[0] = b[0]
for i in range(1, n):
  c[i] = b[i] - b[i-1]

ans = map(str, c)
print(" ".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

a1 = np.roll(a, -1)

for i in range(1, (n - 1) // 2):
  a1 += np.roll(a, -1 - 2 * i)

ans_list = map(str, (np.sum(a) - a1 * 2).tolist())
print(" ".join(ans_list))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
b[0] = sum(a) - sum(a[1::2]) * 2
b[1] = a[0] * 2
for i in range(2, n):
  b[i] = b[i-2] + a[i-1] * 2
c = [0 for i in range(n)]
c[0] = b[0]
for i in range(1, n):
  c[i] = b[i] - b[i-1]

ans = map(str, c)
print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = []

for i in range(m):
    a.append(int(input()))

p = [0 for i in range(n)]

if 1 not in a:
    p[0] = 1

if n >= 2 and 2 not in a:
    p[1] = p[0] + 1

for i in range(2, n):
    if i + 1 not in a:
        p[i] = p[i - 1] + p[i - 2]

print(p[n - 1] % 1000000007)

Fixed submission:
n, m = map(int, input().split())
a = set()

for i in range(m):
    a.add(int(input()))

p = [0 for i in range(n)]

if 1 not in a:
    p[0] = 1

if n >= 2 and 2 not in a:
    p[1] = p[0] + 1

for i in range(2, n):
    if i + 1 not in a:
        p[i] = p[i - 1] + p[i - 2]

print(p[n - 1] % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())

s = []

for i in range(h):
    s.append(input())

_h = [[0 for i in range(w)] for j in range(h)]
_w = [[0 for i in range(w)] for j in range(h)]
_h2 = [[0 for i in range(w)] for j in range(h)]
_w2 = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    _h[i][0] = 1 if s[i][0] == "." else 0

for i in range(w):
    _w[0][i] = 1 if s[0][i] == "." else 0

for i in range(h):
    for j in range(1, w):
        _h[i][j] = _h[i][j - 1] + 1 if s[i][j] == "." else 0

for i in range(1, h):
    for j in range(w):
        _w[i][j] = _w[i - 1][j] + 1 if s[i][j] == "." else 0

for i in range(h):
    _h2[i][w - 1] = 1 if s[i][w - 1] == "." else 0

for i in range(w):
    _w2[h - 1][i] = 1 if s[h - 1][i] == "." else 0

for i in range(h):
    for j in range(w - 2, -1, -1):
        _h2[i][j] = _h2[i][j + 1] + 1 if s[i][j] == "." else 0

for i in range(h - 2, -1, -1):
    for j in range(w):
        _w2[i][j] = _w2[i + 1][j] + 1 if s[i][j] == "." else 0

maximum = 0

for i in range(h):
    for j in range(w):
        ans = _h[i][j] + _h2[i][j] + _w[i][j] + _w2[i][j] - 3
        if ans >= maximum:
            maximum = ans

print(maximum)

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

s = []

for i in range(h):
    s.append(input())

_h = [[0 for i in range(w)] for j in range(h)]
_w = [[0 for i in range(w)] for j in range(h)]
_h2 = [[0 for i in range(w)] for j in range(h)]
_w2 = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    _h[i][0] = 1 if s[i][0] == "." else 0

for i in range(w):
    _w[0][i] = 1 if s[0][i] == "." else 0

for i in range(h):
    for j in range(1, w):
        _h[i][j] = _h[i][j - 1] + 1 if s[i][j] == "." else 0

for i in range(1, h):
    for j in range(w):
        _w[i][j] = _w[i - 1][j] + 1 if s[i][j] == "." else 0

for i in range(h):
    _h2[i][w - 1] = 1 if s[i][w - 1] == "." else 0

for i in range(w):
    _w2[h - 1][i] = 1 if s[h - 1][i] == "." else 0

for i in range(h):
    for j in range(w - 2, -1, -1):
        _h2[i][j] = _h2[i][j + 1] + 1 if s[i][j] == "." else 0

for i in range(h - 2, -1, -1):
    for j in range(w):
        _w2[i][j] = _w2[i + 1][j] + 1 if s[i][j] == "." else 0

maximum = 0

for i in range(h):
    for j in range(w):
        ans = _h[i][j] + _h2[i][j] + _w[i][j] + _w2[i][j] - 3
        if ans >= maximum:
            maximum = ans

print(maximum)
Buggy python submission (verdict: Time Limit Exceeded):
l = input()
length = len(l)

idx = 0
ones = 0

pattern = 3 ** len(l)

for s in l:
    idx += 1
    if s == "1":
        ones += 1
    else:
        pattern -= (2 ** (ones + 1)) * (3 ** (length - idx))

print(pattern % 1000000007)

Fixed submission:
l = input()
length = len(l)

idx = 0
ones = 0

prime = 1000000007

pattern = pow(3, length, prime)

for s in l:
    idx += 1
    if s == "1":
        ones += 1
    else:
        pattern -= (pow(2, ones + 1, prime) * pow(3, length - idx, prime)) % prime

print(pattern % prime)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
 
for i in range(sa[1], 0, -1):
  cnt = 0
  for j in range(n):
    if a[j] % i != 0:
      cnt += 1
    if cnt >= 2:
      break  
  if cnt <= 1:
    print(i)
    break

Fixed submission:
a, b, t = map(int, input().split())
print((t // a) * b)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
s = input()

# 100101 => [1,2,1,1,1]
# 011000 => [0,1,2,3,0]
human = []

is_handstood = False
cnt = 0

for ch in s:
    if ch == "0" and not is_handstood:
    	human.append(cnt)
    	is_handstood = True
    	cnt = 1
    elif ch == "1" and is_handstood:
    	human.append(cnt)
    	is_handstood = False
    	cnt = 1
    else:
        cnt += 1
human.append(cnt)
if is_handstood:
    human.append(0)

max_human = 0

if len(human) <= 2 * k + 1:
    max_human = n
else:
    for i in range(0, len(human) - 2 * k, 2):
        max_human = max(sum(human[i:i+2*k+1]), max_human)

print(max_human)

Fixed submission:
n, k = map(int, input().split())
s = input()

# 100101 => [1,2,1,1,1]
# 011000 => [0,1,2,3,0]
human = []

is_handstood = False
cnt = 0

for ch in s:
    if ch == "0" and not is_handstood:
    	human.append(cnt)
    	is_handstood = True
    	cnt = 1
    elif ch == "1" and is_handstood:
    	human.append(cnt)
    	is_handstood = False
    	cnt = 1
    else:
        cnt += 1
human.append(cnt)
if is_handstood:
    human.append(0)

total_human = [0 for i in range(len(human))]
total_human[0] = human[0]
for i in range(1, len(human)):
    total_human[i] = total_human[i - 1] + human[i]

if len(human) <= 2 * k + 1:
    max_human = n
else:
    max_human = total_human[k * 2]
    for i in range(k * 2 + 2, len(total_human), 2):
        if total_human[i] - total_human[i - k * 2 - 1] > max_human:
        	max_human = total_human[i] - total_human[i - k * 2 - 1]

print(max_human)
Buggy python submission (verdict: Time Limit Exceeded):
import re
 
n, q = map(int, input().split())
s = input()
 
l = []
r = []
 
for i in range(q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)

for i in range(q):
    m = re.findall("AC", s[l[i] - 1 : r[i]])
    print(len(m))

Fixed submission:
import re
 
n, q = map(int, input().split())
s = input()
 
l = []
r = []
 
for i in range(q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
 
memo = [0 for i in range(len(s))]
cnt = 0
 
for i in range(1, len(s)):
    if s[i - 1] == "A" and s[i] == "C":
        cnt += 1
    memo[i] = cnt
 
for i in range(q):
    print(memo[r[i] - 1] - memo[l[i] - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

l = []
r = []

for i in range(q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)

for i in range(q):
    ac = 0
	
    for j in range(l[i] - 1, r[i] - 1):
        if s[j : j + 2] == "AC":
            ac += 1
    
    print(ac)

Fixed submission:
import re
 
n, q = map(int, input().split())
s = input()
 
l = []
r = []
 
for i in range(q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
 
memo = [0 for i in range(len(s))]
cnt = 0
 
for i in range(1, len(s)):
    if s[i - 1] == "A" and s[i] == "C":
        cnt += 1
    memo[i] = cnt
 
for i in range(q):
    print(memo[r[i] - 1] - memo[l[i] - 1])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x,m=nii()

ans=x
x_list=[x]
zan=0
for i in range(n-1):
  a=(x**2)%m
  ans+=a
  x=a
  if x in x_list:
    inx=x_list.index(x)
    zan=(n-1)-i-1

    inx=x_list.index(x)+1
    nx_list=x_list[inx:]+[x_list[inx-1]]

    if zan<=len(nx_list):
      ans+=sum(nx_list[:zan])
    else:
      num=zan//len(nx_list)
      q=zan%len(nx_list)
      ans+=sum(nx_list)*num
      ans+=sum(nx_list[:q])
    break
  else:
    x_list.append(x)

print(ans)


Fixed submission:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x,m=nii()

ans=x
x_list=[x]
zan=0
for i in range(n-1):
  a=(x**2)%m
  ans+=a
  x=a
  if x in x_list:
    inx=x_list.index(x)
    zan=(n-1)-i-1

    inx=x_list.index(x)+1
    nx_list=x_list[inx:]+[x_list[inx-1]]

    if zan<=len(nx_list):
      ans+=sum(nx_list[:zan])
    else:
      num=zan//len(nx_list)
      q=zan%len(nx_list)
      ans+=sum(nx_list)*num
      ans+=sum(nx_list[:q])
    break
  else:
    x_list.append(x)

print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

l=lnii()

if len(l)==1:
  print(0)
  exit()

x_max=0
x_min=10**10
y_max=0
y_min=10**10

for x,y in l:
  s=x-y
  x_max=max(x_max,s)
  x_min=min(x_min,s)

  t=x+y
  y_max=max(y_max,t)
  y_min=min(y_min,t)

x_ans=x_max-x_min
y_ans=y_max-y_min
print(max(x_ans,y_ans))

Fixed submission:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:tuple(map(int,stdin.readline().split()))

n=int(input())

l=set(tuple([lnii() for i in range(n)]))

if len(l)==1:
  print(0)
  exit()

x_max=0
x_min=10**10
y_max=0
y_min=10**10

for x,y in l:
#  s=abs(x-y)
  s=x-y
  x_max=max(x_max,s)
  x_min=min(x_min,s)

#  t=abs(x+y)
  t=x+y
  y_max=max(y_max,t)
  y_min=min(y_min,t)

x_ans=x_max-x_min
y_ans=y_max-y_min
print(max(x_ans,y_ans))