Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]

for i in range(n - 1):
    if nums[i + 1] != nums[i]:
        break
else:
    print(n // 2)
    sys.exit()


odd = Counter(nums[1::2]).most_common()
even = Counter(nums[::2]).most_common()
odd.append((0, 0))
even.append((0, 0))
if odd[0][0] != even[0][0]:
    ans = n - (odd[0][1] + even[0][1])
else:
    s = n - (odd[0][1] + even[1][1])
    t = n - (odd[1][1] + even[0][1])
    ans = min(s, t)
print(ans)

Fixed submission:
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]

odd = Counter(nums[1::2]).most_common()
even = Counter(nums[::2]).most_common()
odd.append((0, 0))
even.append((0, 0))
if odd[0][0] != even[0][0]:
    ans = n - (odd[0][1] + even[0][1])
else:
    s = n - (odd[0][1] + even[1][1])
    t = n - (odd[1][1] + even[0][1])
    ans = min(s, t)
print(ans)
'''
6
1 1 1 1 2 1
'''
Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())
cities = [[0] * (n + 1) for _ in range(n + 1)]
trains = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
    l, r = map(int, input().split())
    trains[l][r] += 1

for i in range(n):
    for j in range(n):
        cities[i + 1][j + 1] = cities[i + 1][j] + trains[i + 1][j + 1]
for _ in range(q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p, q + 1):
        ans += cities[i][q] - cities[i][p - 1]
    print(ans)


Fixed submission:
n, m, q = map(int, input().split())
cities = [[0] * (n + 1) for _ in range(n + 1)]
trains = [[0] * (n + 1) for _ in range(n + 1)]
for _ in range(m):
    l, r = map(int, input().split())
    trains[l][r] += 1

for i in range(n):
    for j in range(n):
        cities[i + 1][j + 1] = cities[i + 1][j] + trains[i + 1][j + 1]
for _ in range(q):
    p, q = map(int, input().split())
    ans = 0
    for i in range(p, q + 1):
        ans += cities[i][q] - cities[i][p - 1]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/arc097/tasks/arc097_a

s = input()
K = int(input())
k = K
done = set()
for i in range(26):
    w = chr(i + ord('a'))
    for j in range(len(s)):
        if s[j] == w:
            for m in range(j, len(s)):
                t = s[j:m + 1]
                if t not in done:
                    k -= 1
                    done.add(t)
    if k < 1:
        done = list(done)
        done.sort()
        print(done[K - 1])
        import sys;sys.exit()

Fixed submission:
# https://atcoder.jp/contests/arc097/tasks/arc097_a

s = input()
k = int(input())
ans = set()

for i in range(len(s)):
    for j in range(k):
        ans.add(s[i:i + j + 1])
print(sorted(list(ans))[k - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/arc097/tasks/arc097_a

s = input()
k = int(input())

done = set()
for i in range(26):
    w = chr(i + ord('a'))
    for j in range(len(s)):
        if s[j] == w:
            for m in range(j, len(s)):
                t = s[j:m + 1]
                if t not in done:
                    k -= 1
                    done.add(t)
    if k < 1:
        done = list(done)
        done.sort()
        print(done[k - 1])
        import sys;sys.exit()

Fixed submission:
# https://atcoder.jp/contests/arc097/tasks/arc097_a

s = input()
k = int(input())
ans = set()

for i in range(len(s)):
    for j in range(k):
        ans.add(s[i:i + j + 1])
print(sorted(list(ans))[k - 1])
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc094/tasks/arc095_b
n = int(input())
nums = [int(i) for i in input().split()]

# すべてを計算する時間はなさそう
# 最大のモノを選らんで、それと絶対値差が大きいモノを選ぶ。いや、ここは全部やればいいのかな。
mod = (10 ** 9 + 7) ** 2
MAX = 2 * (10 ** 6) + 1 # これは変動するので注意。せいぜい10 ** 6くらいまでがTLEの限界

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n, r):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

t = -float('inf')
MAX = max(nums)
ans = None
for num in nums:
    if num == MAX:
        continue
    r = nCr(MAX, num)
    if r > t:
        t = r
        ans = (MAX, num)
print(*ans)

Fixed submission:
# https://atcoder.jp/contests/abc094/tasks/arc095_b
n = int(input())
nums = [int(i) for i in input().split()]

# すべてを計算する時間はなさそう
# 最大のモノを選らんで、それと絶対値差が大きいモノを選ぶ。いや、ここは全部やればいいのかな。
# numsの値がめちゃくちゃでかいので、全部はできない。

MAX = max(nums)
t = 0
ans = 0
for num in nums:
    if num == MAX:
        continue
    d = min(MAX - num, num)
    if t < d:
        t = d
        ans = num
print(MAX, ans)

Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc094/tasks/arc095_b
n = int(input())
nums = [int(i) for i in input().split()]

# すべてを計算する時間はなさそう
# 最大のモノを選らんで、それと絶対値差が大きいモノを選ぶ。いや、ここは全部やればいいのかな。
mod = (10 ** 9 + 7) ** 2
MAX = 2 * (10 ** 5) + 1 # これは変動するので注意。せいぜい10 ** 6くらいまでがTLEの限界

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n, r):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

t = -float('inf')
MAX = max(nums)
ans = None
for num in nums:
    if num == MAX:
        continue
    r = nCr(MAX, num)
    if r > t:
        t = r
        ans = (MAX, num)
print(*ans)

Fixed submission:
# https://atcoder.jp/contests/abc094/tasks/arc095_b
n = int(input())
nums = [int(i) for i in input().split()]

# すべてを計算する時間はなさそう
# 最大のモノを選らんで、それと絶対値差が大きいモノを選ぶ。いや、ここは全部やればいいのかな。
# numsの値がめちゃくちゃでかいので、全部はできない。

MAX = max(nums)
t = 0
ans = 0
for num in nums:
    if num == MAX:
        continue
    d = min(MAX - num, num)
    if t < d:
        t = d
        ans = num
print(MAX, ans)
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc093/tasks/arc094_a
a, b, c = map(int, input().split())

nums = [a, b, c]
nums.sort()

ans = 0
if (nums[1] - nums[0]) % 2 == 1:
    # 小さい2つの差が奇数の場合、偶数になるように
    # 小さい2つの数字両方にならないように、1を足す。
    # ここでは、二番目に大きいのと、最大の数に1を足す。
    nums[1] += 1
    nums[2] += 1
    ans += 1
ans += (nums[1] - nums[0]) // 2　# 一番小さい数が、二番目に大きい数に追いつくようにする。それには2ずつ足すのが良い。
ans += (nums[2] - nums[1]) # 一番目も二番目も同じかずになったので、両方に１つづ足していき、最大の数と同じになる様にする。
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
a, b, c = map(int, input().split()) # 入力が複数
nums = sorted([a, b, c])

ans = 0
if (nums[1] - nums[0]) % 2 != 0:
    nums[2] += 1
    nums[1] += 1
    ans += 1
ans += (nums[1] - nums[0]) // 2
ans += nums[2] - nums[1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc084/tasks/abc084_d
from bisect import bisect_left, bisect_right
q = int(input())
queries = []
MAX = 0
for _ in range(q):
    l, r = map(int, input().split())
    queries.append((l, r))
    MAX = max([MAX, l, r])

def is_prime(x):
    sqrt = x ** 0.5
    i = 2
    while i <= sqrt:
        if x % i == 0:
            return False
        i += 1
    return True

def eratos(x):
    dp = [True] * (x + 1)
    dp[0] = dp[1] = False
    i = 2
    sqrt = x ** 2
    while i <= sqrt:
        for j in range(i * 2, x + 1, i):
            dp[j] = False
        i += 1
    primes = []
    for i in range(len(dp)):
        if dp[i]:
            primes.append(i)
    return primes, dp
primes, dp = eratos(MAX)
sub_prims = []
for p in primes:
    x = (p + 1) // 2
    if dp[x]:
        sub_prims.append(p)

for l, r in queries:
    left = bisect_left(sub_prims, l)
    right = bisect_left(sub_prims, r + 1)
    print(right - left)

Fixed submission:
# https://atcoder.jp/contests/abc084/tasks/abc084_d
from bisect import bisect_left, bisect_right
q = int(input())
queries = []
MAX = 0
for _ in range(q):
    l, r = map(int, input().split())
    queries.append((l, r))
    MAX = max([MAX, l, r])
from datetime import datetime
s = datetime.now()
def eratos(x):
    dp = [True] * (x + 1)
    dp[0] = dp[1] = False
    i = 2
    sqrt = x ** 0.5
    while i <= sqrt:
        if dp[i]:
            for j in range(i ** 2, x + 1, i):
                dp[j] = False
        i += 1
    primes = []
    for i in range(len(dp)):
        if dp[i]:
            primes.append(i)
    return primes, dp

primes, dp = eratos(MAX)
sub_prims = []
for p in primes:
    x = (p + 1) // 2
    if dp[x]:
        sub_prims.append(p)

for l, r in queries:
    left = bisect_left(sub_prims, l)
    right = bisect_left(sub_prims, r + 1)
    print(right - left)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
d = [int(i) for i in input().split()] # 配列で数字

m = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
t = [int(i) for i in input().split()]

def bs(nums, target):
    l = 0
    r = len(nums) - 1
    while l <= r:
        mid = (l + r) // 2
        if nums[mid] == target:
            return mid
        elif nums[mid] > target:
            r = mid - 1
        else:
            l = mid + 1
    return -1

if n < m:
    print('NO')
else:
    d.sort()
    for p in t:
        r = bs(d, p)
        if r == -1:
            print('NO')
            break
        else:
            del d[r]
    else:
        print('YES')

Fixed submission:
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
d = [int(i) for i in input().split()] # 配列で数字

m = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
t = [int(i) for i in input().split()]

def bs(nums, target):
    l = 0
    r = len(nums) - 1
    while l <= r:
        mid = (l + r) // 2
        if nums[mid] == target:
            return mid
        elif nums[mid] > target:
            r = mid - 1
        else:
            l = mid + 1
    return -1

if n < m:
    print('NO')
else:
    d.sort()
    t.sort()
    i = j = 0
    while i < n and j < m:
        if d[i] == t[j]:
            i += 1
            j += 1
        else:
            i += 1
    if j == m:
        print('YES')
    else:
        print('NO')
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/agc018/tasks/agc018_a

n, k = map(int, input().split())
nums = [int(i) for i in input().split()]
# ボールはどんどん増えていく
nums.sort()
if k <= nums[-1]:
    diff = set([])
    for i in range(1, n):
        diff.add(abs(nums[i] - nums[i - 1]))

    diff = list(diff)
    dp = [False] * (k + 1)
    dp[0] = True
    for num in nums:
        if num <= k:
            dp[num] = True
    for i in range(len(diff)):
        num = nums[i]
        for j in range(k + 1):
            if j - num >= 0:
                dp[j] = dp[j - num] or dp[j]

    if dp[k]:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')

Fixed submission:
# https://atcoder.jp/contests/agc018/tasks/agc018_a

n, k = map(int, input().split())
nums = [int(i) for i in input().split()]

def gcd(x, y): #GCD
    # greatest_common_divisor
    if x < y:
        x, y = y, x
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)

MAX = max(nums)
GCD = nums[0]
for num in nums:
    GCD = gcd(GCD, num)

if k <= MAX and k % GCD == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
mport sys

n = int(input())
nums = []
for _ in range(n):
    nums.append(int(input()))
s = sum(nums)
if s % 10 != 0:
    print(s)
else:
    nums.sort()
    for num in nums:
        t = s - num
        if t % 10 != 0:
            print(t)
            break
    else:
        print(0)

Fixed submission:
# https://atcoder.jp/contests/abc063/tasks/arc075_a

n = int(input())
nums = []
for _ in range(n):
    nums.append(int(input()))

total = sum(nums)
dp = [[False for _ in range(total + 1)] for _ in range(n + 1)]
dp[0][0] = True
for i in range(n):
    num = nums[i]
    dp[i + 1][num] = True
    for j in range(total + 1):
        if dp[i][j] and num + j <= total:
            dp[i + 1][num + j] = True

        dp[i + 1][j] = dp[i][j] or dp[i + 1][j]

for i in range(len(dp[0]))[::-1]:
    if dp[-1][i] and i % 10 != 0:
        print(i)
        break
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/agc015/tasks/agc015_a

import math
n, a, b = map(int, input().split())

if b < a:
    print(0)
elif a != b and n == 1:
    print(0)
else:
    t = b - a + 1 - 2
    ans = math.factorial(t + n) // (math.factorial(t) * math.factorial(n))
    print(ans)

Fixed submission:
# https://atcoder.jp/contests/agc015/tasks/agc015_a

n, a, b = map(int, input().split())

if b < a:
    print(0)
elif a != b and n == 1:
    print(0)
else:
    MIN = a * (n - 1) + b
    MAX = a + (n - 1) * b
    ans = MAX - MIN + 1
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,ma,mb=map(int,input().split())
dp=[[0]*401 for _ in range(401)]
for _ in range(n):
  a,b,c=map(int,input().split())
  for i in range(400,-1,-1):
    for j in range(400,-1,-1):
      if i-a<0 or j-b<0:
        continue
      else:
        if dp[i-a][j-b]==0:
          continue
        else:
          if dp[i][j]==0:
            dp[i][j]=dp[i-a][j-b]+c
          else:
            dp[i][j]=min(dp[i][j],dp[i-a][j-b]+c)
  if dp[a][b]==0:
    dp[a][b]=c
  else:
    dp[a][b]=min(dp[a][b],c)
ans=10**10
for i in range(401):
  if i*ma>400 or i*mb>400:
    break
  if dp[i*ma][i*mb]==0:
    continue
  else:
    ans=min(ans,dp[i*ma][i*mb])
if ans==10**10:
  print(-1)
else:
  print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
a, b = map(int, input().split()) # 入力が複数

if a == b:
    print('Draw')
elif a == 1:
    print('Alice')
elif b == 1:
    print('Bob')
elif a > b:
    print('Alice')
else:
    print('Bob')
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
graph = [[] for _ in range(m + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

def my_permutations(nums, t, path):
    if len(nums) == 0:
        path.append(t)
        return
    for i in range(len(nums)):
        my_permutations(nums[:i] + nums[i + 1:], t + [nums[i]], path)

def dfs(graph, permu, n):
    visited = [False] * (n + 1)
    next_nodes = set([1])
    for p in permu:
        if visited[p]:
            return False
        if p not in next_nodes:
            return False
        visited[p] = True
        next_nodes = set(graph[p])
    return True

path = []
my_permutations([i for i in range(1, n + 1)], [], path)
ans = 0
for permu in path:
    if permu[0] != 1:
        continue
    if dfs(graph, permu, n):
        ans += 1
print(ans)

Fixed submission:
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

def my_permutations(nums, t, path):
    if len(nums) == 0:
        path.append(t)
        return
    for i in range(len(nums)):
        my_permutations(nums[:i] + nums[i + 1:], t + [nums[i]], path)

def dfs(graph, permu, n):
    visited = [False] * (n + 1)
    next_nodes = set([1])
    for p in permu:
        if visited[p]:
            return False
        if p not in next_nodes:
            return False
        visited[p] = True
        next_nodes = set(graph[p])
    return True

path = []
my_permutations([i for i in range(1, n + 1)], [], path)
ans = 0
for permu in path:
    if permu[0] != 1:
        continue
    if dfs(graph, permu, n):
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/agc009/tasks/agc009_a

n = int(input())

A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

ans = 0
for i in range(n)[::-1]:
    a = A[i]
    b = B[i]
    if a % b != 0:
        multi = a // b + 1
        t = b * multi - a
        ans += t
        for j in range(i + 1):
            A[j] += t
print(ans)

Fixed submission:
# https://atcoder.jp/contests/agc009/tasks/agc009_a

n = int(input())

A = []
B = []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

ans = 0
plus = 0
for i in range(n)[::-1]:
    a = A[i] + plus
    b = B[i]
    if a % b != 0:
        multi = a // b + 1
        t = b * multi - a
        ans += t
        plus += t
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

graph = [[float('infinity') for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a][b] = c
    graph[b][c] = c
ans = 0
# 頂点g -> 頂点vへのコストを計算する。直接のpathが最小なら、カウントしない。
# そうでなければ、他の経路があるので、カウントする。
for g in range(1, len(graph)):
    for v in range(1, N + 1):
        if g == v:
            continue
        paths = graph[g]
        direct = paths[v]
        if direct == float('infinity'):
            continue
        min_path = float('infinity')
        for i in range(len(paths)):
            p = paths[i]
            cost = p + graph[i][v]
            if min_path > cost:
                min_path = cost
        if direct > min_path:
            ans += 1
print(ans)


Fixed submission:
from copy import deepcopy
N, M = map(int, input().split())

graph = [[float('infinity')] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
ans = 0
# 頂点g -> eまでの最短経路コストと、その経路を記録する

for i in range(N):
    for j in range(N):
        if i == j:
            graph[i][j] = 0

original = deepcopy(graph)

def warshall_floyd(graph, v):
    for k in range(v):
        for i in range(v):
            for j in range(v):
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])

warshall_floyd(graph, N)

ans = 0
for i in range(N):
    for j in range(i):
        if original[i][j] != float('infinity') and graph[i][j] != original[i][j]:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c

s = input()
k = int(input())
n = len(s)
ans = []
for i in range(n):
    t = (ord('z') - ord(s[i]) + 1) % 26
    if t <= k:
        ans.append('a')
        k -= t
    else:
        ans.append(s[i])
ans[-1] = chr(ord(ans[-1]) + k)
print(''.join(ans))

Fixed submission:
# https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_c

s = input()
k = int(input())
n = len(s)
ans = []
for i in range(n):
    t = (ord('z') - ord(s[i]) + 1) % 26
    if k - t >= 0:
        ans.append('a')
        k -= t
    else:
        ans.append(s[i])
if k > 0:
    k %= 26
    ans[-1] = chr(ord(ans[-1]) + k)
print(''.join(ans))
Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc045/tasks/arc061_a

s = input()

length = len(s)
ans = 0
for i in range(2 << length - 2):
    temp = []
    for j in range(length):
        t = (i >> j) & 1
        temp.append(s[j])
        if t:
            temp.append('+')
    ans += eval(''.join(temp))
print(ans)

Fixed submission:
# https://atcoder.jp/contests/abc045/tasks/arc061_a

s = input()

length = len(s)
if length == 1:
    print(s)
else:
    ans = 0
    for i in range(2 << length - 2):
        temp = []
        for j in range(length):
            t = (i >> j) & 1
            temp.append(s[j])
            if t:
                temp.append('+')
        ans += eval(''.join(temp))
    print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np
    from scipy.sparse import csgraph
    from scipy.sparse import csr_matrix

    N, M = map(int, input().split())
    H = np.array(list(map(int, input().split())))
    AB = np.array([list(map(int, input().split())) for i in range(M)])-1

    ab0 = list(AB[:, 0])
    ab1 = list(AB[:, 1])
    csr = csr_matrix(
        ([1]*(2*M), (ab0+ab1, ab1+ab0)), shape=(N, N)).toarray()

    count = 0
    for i, indices in enumerate(csr):
        if (indices == 0).all():
            count += 1
            continue
        if np.max(H[indices != 0]) < H[i]:
            count += 1

    print(count)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np
    from scipy.sparse import csr_matrix

    N, M = map(int, input().split())
    H = np.array(list(map(int, input().split())))

    AB = [[] for i in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        AB[a].append(b)
        AB[b].append(a)
    count = 0
    for i, ab in enumerate(AB):
        ind = list(set(ab))
        if ind == []:
            count += 1
            continue
        if np.max(H[ind]) < H[i]:
            count += 1
    print(count)

    # AB = np.array([list(map(int, input().split())) for i in range(M)])-1

    # ab0 = list(AB[:, 0])
    # ab1 = list(AB[:, 1])
    # csr = csr_matrix(
    #     ([1]*(2*M), (ab0+ab1, ab1+ab0)), shape=(N, N)).toarray()

    # count = 0
    # for i, indices in enumerate(csr):
    #     if (indices == 0).all():
    #         count += 1
    #         continue
    #     if np.max(H[indices != 0]) < H[i]:
    #         count += 1

    # print(count)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    # from collections import deque
    N = int(input())
    A = list(map(int, input().split()))

    count = 0
    for now in range(N):
        for v in range(now+1, N):
            if A[now]+A[v] == v-now:
                count += 1
    print(count)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    import numpy as np
    from collections import Counter
    N = int(input())
    A = np.array(list(map(int, input().split())))

    count = 0

    tmp = np.arange(N)
    X = A-tmp
    Y = A+tmp

    # print(X)
    # print(Y)
    XX = Counter(list(X))
    YY = Counter(list(Y))

    count = 0
    # print(XX)
    # print(YY)
    for number, c in XX.items():
        count += YY[-number] * c
        # count +=
    print(count)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N,M,Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for i in range(Q)]
score=0
for i in range(1, M+1):
  dfs([i])
print(score)


def dfs(l):
    # 末端まで探索したか判定
    if judge_end(l,N):
        global score
        
        tmp_score = calc_score(ABCD,l)
        score = max(tmp_score, score)
        return
    else:
        # 現時点から選べる選択肢の列挙と探索
        nexts = listup_next(l[-1], M)
        for x in nexts:
            dfs(num_list+[x])


def judge_end(l,N):
    return len(l)==N


def calc_score(ABCD, l):
    s=0
    for a,b,c,d in ABCD:
      if l[b-1] - l[a-1] ==c:
        s+=d
    return s


def listup_next(m, M):
    return range(m,M+1)


Fixed submission:

s = 0


def main():
    import sys
    from copy import copy
    input = sys.stdin.readline

    N, M, Q = map(int, input().split())
    ABCD = [list(map(int, input().split())) for i in range(Q)]

    def dfs(num_list):
        if len(num_list) == N:
            global s
            tmp_s = 0
            for a, b, c, d in ABCD:
                if num_list[b-1] - num_list[a-1] == c:
                    tmp_s += d
            s = max(tmp_s, s)

            return
        else:
            for i in range(num_list[-1], M+1):
                dfs(num_list+[i])

    for i in range(1, M+1):
        dfs([i])
    print(s)


if __name__ == "__main__":
    main()