Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,Q = map(int, input().split())
to = [[] for _ in range(N+1)]
ans = [0]*N

for _ in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

for _ in range(Q):
    pa, x = map(int, input().split())
    pa -= 1
    ans[pa] += x

def dfs(v, p=-1):
    for i in to[v]:
        if i == p: continue
        ans[i] += ans[v]
        dfs(i, v)
        
dfs(0)        
print(' '.join([str(x) for x in ans[0:]]))

Fixed submission:
N,Q = map(int, input().split())
to = [[] for _ in range(N+1)]
ans = [0]*N

for _ in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

for _ in range(Q):
    pa, x = map(int, input().split())
    pa -= 1
    ans[pa] += x

q = [(0, -1)]
while(q):
    v, p = q.pop()
    for nv in to[v]:
        if nv == p: continue
        ans[nv] += ans[v]
        q.append((nv, v))

print(*ans)

Buggy python submission (verdict: Runtime Error):
N,Q = map(int, input().split())
to = [[] for _ in range(N+1)]
ans = [0]*N

for _ in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

for _ in range(Q):
    pa, x = map(int, input().split())
    pa -= 1
    ans[pa] += x

def dfs(v, p=-1):
    for i in to[v]:
        if i == p: continue
        ans[i] += ans[v]
        dfs(i, v)
        
dfs(0)        
print(' '.join([str(x) for x in ans[0:]]))

Fixed submission:
N,Q = map(int, input().split())
to = [[] for _ in range(N+1)]
ans = [0]*N

for _ in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

for _ in range(Q):
    pa, x = map(int, input().split())
    pa -= 1
    ans[pa] += x

q = [(0, -1)]
while(q):
    v, p = q.pop()
    for nv in to[v]:
        if nv == p: continue
        ans[nv] += ans[v]
        q.append((nv, v))

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10 ** 9 + 7

S = input()

dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i+1)]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul*k+j) % 13] += dp[i][j]
                dp[i+1][(mul*k+j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(mul*k+j) % 13] += dp[i][j]
            dp[i+1][(mul*k+j) % 13] %= INF
    mul = mul * 10 % 13

print(dp[len(S)][5])

Fixed submission:
INF = 10 ** 9 + 7

S = input()

dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i+1)]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(mul*k+j) % 13] += dp[i][j]
                dp[i+1][(mul*k+j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(mul*k+j) % 13] += dp[i][j]
            dp[i+1][(mul*k+j) % 13] %= INF
    mul = mul * 10 % 13

print(dp[len(S)][5])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

ans = 0
for i in range(N):
    tmp = A[:]
    tmp.sort(reverse=True)
    
    if tmp[0] == A[i]:
      print(tmp[1])
    else:
      print(tmp[0])   

Fixed submission:
N = int(input())

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

tmp = A[:]
tmp.sort(reverse=True)
for i in range(N):
    
    if tmp[0] == A[i]:
        print(tmp[1])
    else:
        print(tmp[0])

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

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

for i in range(N):
    tmp = A[:]
    ans = max(tmp)
    if ans == A[i]:
        ans = sorted(tmp)[-2]
    print(ans)   

Fixed submission:
N = int(input())

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

tmp = A[:]
tmp.sort(reverse=True)
for i in range(N):
    
    if tmp[0] == A[i]:
        print(tmp[1])
    else:
        print(tmp[0])

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

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

for i in range(N):
    tmp = A[:]
    tmp.pop(i)
    print(max(tmp))

Fixed submission:
N = int(input())

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

tmp = A[:]
tmp.sort(reverse=True)
for i in range(N):
    
    if tmp[0] == A[i]:
        print(tmp[1])
    else:
        print(tmp[0])

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

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

for i in range(N):
    tmp = A[:]
    tmp.pop(i)
    print(max(tmp))

Fixed submission:
N = int(input())

A = [0] * N
for i in range(N):
    a = int(input())
    A[i] = a

tmp = A[:]
tmp.sort(reverse=True)
for i in range(N):
    
    if tmp[0] == A[i]:
        print(tmp[1])
    else:
        print(tmp[0])
Buggy python submission (verdict: Runtime Error):
def dist(a, b):
  res = 0
  for i in range(D):
    res += (a[i] - b[i]) ** 2
    res = res ** 0.5

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N - 1):
  for j in range(i +1, N):
    if dist(X[i], X[j]).is_integer():
      ans += 1
print(ans)      

Fixed submission:
def dist(a, b):
  res = 0
  for i in range(D):
    res += (a[i] - b[i]) ** 2
  res = res ** 0.5
  return res

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N - 1):
  for j in range(i +1, N):
    if dist(X[i], X[j]).is_integer():
      ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = list(map(int, input().split()))

R = min(R, L+4038)

ans =  2018

for i in range(L, R+1):
    for j in range(i+1, R+1):
        x = i*j%2019
        ans = min(ans, x)
print(ans)

Fixed submission:
L, R = list(map(int, input().split()))

R = min(R, L+4038)

ans =  2018

for i in range(L, R+1):
    for j in range(i+1, R+1):
        x = i*j%2019
        ans = min(ans, x)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())

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

ans = 0
for i in range(N):
    new_list = A[:i] + A[i+1:]
    ans = max(ans, gcd_list(new_list))

print(ans)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())

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

gcd_front = gcd(A[0], A[1])
gcd_front_list = [A[0],gcd_front, ]
for i in range(2, N):
    gcd_front = gcd(gcd_front, A[i])
    gcd_front_list.append(gcd_front)

gcd_rear = gcd(A[N-1], A[N-2])
gcd_rear_list = [A[N-1], gcd_rear, ]

for i in range(N-3, -1, -1):
    gcd_rear = gcd(gcd_rear, A[i])
    gcd_rear_list.append(gcd_rear)

ans = 0

for i in range(N):
    if i == 0:
        ans = max(ans, gcd_rear_list[-2])
    if i == N-1:
        ans = max(ans, gcd_front_list[-2])   

    ans = max(ans, gcd(gcd_front_list[i-1],gcd_rear_list[N-2-i]))
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())

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

ans = 0
for i in range(N):
    new_list = A[:i] + A[i+1:]
    ans = max(ans, gcd_list(new_list))

print(ans)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())

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

gcd_front = gcd(A[0], A[1])
gcd_front_list = [A[0],gcd_front, ]
for i in range(2, N):
    gcd_front = gcd(gcd_front, A[i])
    gcd_front_list.append(gcd_front)

gcd_rear = gcd(A[N-1], A[N-2])
gcd_rear_list = [A[N-1], gcd_rear, ]

for i in range(N-3, -1, -1):
    gcd_rear = gcd(gcd_rear, A[i])
    gcd_rear_list.append(gcd_rear)

ans = 0

for i in range(N):
    if i == 0:
        ans = max(ans, gcd_rear_list[-2])
    if i == N-1:
        ans = max(ans, gcd_front_list[-2])   

    ans = max(ans, gcd(gcd_front_list[i-1],gcd_rear_list[N-2-i]))
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

order = [int(input()) for _ in range(5)]

extra_list = []

tmp = 11
for i in range(5):
    extra = order[i] % 10
    if extra != 0:
        if extra < tmp:
            tmp = extra
            extra_list.append(i)

ans = 0
for i in range(5):
    if i == extra_list[-1]:
        continue
    if order[i] % 10 == 0:
        ans += order[i]
    else:
        ans += 10 * (order[i] // 10 + 1)

print(ans + order[extra_list[-1]])

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

order = [int(input()) for _ in range(5)]

extra_list = []

tmp = 11
for i in range(5):
    extra = order[i] % 10
    if extra != 0:
        if extra < tmp:
            tmp = extra
            extra_list.append(i)


ans = 0
for i in range(5):
    if extra_list and i == extra_list[-1]:
        continue
    if order[i] % 10 == 0:
        ans += order[i]
    else:
        ans += 10 * (order[i] // 10 + 1)
if extra_list:
    print(ans + order[extra_list[-1]])
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

N,M = map(int, input().split())

match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

A = list(map(int, input().split()))
queue = deque()
queue.append((0, ""))

ans = 0
while queue:
    c_num, c_str = queue.popleft()
    if c_num == N:
        ans = max(ans, int(c_str))
        continue
    if c_num > N:
        continue
    for num in A:
        match_num = match_dict[num]
        new_str = c_str + str(num)
        queue.append((c_num + match_num, new_str))

print(ans)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

match_dict = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

N,M = map(int, input().split())
A = list(map(int, input().split()))

#桁数のMAX
dp = [-1] * (N+1)
dp[0] = 0

for a in A:
    for i in range(match_dict[a], N+1):
        if dp[i - match_dict[a]] >= 0:
            dp[i] = max(dp[i], dp[i - match_dict[a]] + 1)

ans = ''
A.sort(reverse=True)

i = N
while i:
    for a in A:
        if i - match_dict[a] >= 0 and dp[i - match_dict[a]] == dp[i] - 1:
            ans += str(a)
            i -= match_dict[a]
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

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

X.sort()

if M == 1:
    print(0)
    sys.exit()

dist = []

for i in range(len(X)-1):
    dist.append(X[i+1] - X[i])

dist.sort(reverse=True)

ans = X[-1] - X[0]
for i in range(N-1):
    ans -= dist[i]
print(ans)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

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

if N >= M:
    print(0)
    sys.exit()
X.sort()

dist = []
for i in range(len(X)-1):
    dist.append(X[i+1]-X[i])

dist.sort()
print(sum(dist[:len(dist)-(N-1)]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
	if i < N - 2:
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[N - 1])
B – Frog 2

Fixed submission:
N = int(input())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
	if i < N - 2:
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def rec(n,x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return rec(n-1, x-1)
    elif x == 2 + a[n-1]:
        return p[n-1] + 1
    elif 2 + a[n-1] < x <= 2 + 2*a[n-1]:
        return rec(n-1, x-2-a[n-1]) + p[n-1] + 1
    elif 3 + a[n-1] == x:
        return 2*p[n-1] + 1

print(rec(N,X))

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def rec(n,x):
    if n == 0:
        return 0 if x <= 0 else 1
    #真ん中以下まで到達    
    elif x <= 1 + a[n-1]:
        #バンズが一枚増えているので,真ん中以下までしか到達してない場合はn-1からx-1食べるのと同じ
        return rec(n-1, x-1)
    #真ん中以降まで到達
    else:
        #バンズ+N-1バーガー+真ん中のパティ+N-1バーガーのうち[x-a[n-1]-2]分を食べる

        return p[n-1] + 1 + rec(n-1, x-a[n-1]-2)

print(rec(N,X))
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

e = [0] * (N+1)

for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j

def num(n):
    return len(list(filter(lambda x: x >= n-1, e)))

# num(3)-1はnum(25)で3以上のものを一個使っているので、一つ引いている。//2は、例えばa^4 * b^4 * c^2 と b^4 * a^4 * c^2がかぶって計上されるため。
print(num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)//2)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

e = [0] * (N+1)

for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j

def num(n):
    return len(list(filter(lambda x: x >= n-1, e)))

# num(3)-1はnum(25)で3以上のものを一個使っているので、一つ引いている。//2は、例えばa^4 * b^4 * c^2 と b^4 * a^4 * c^2がかぶって計上されるため。
print(num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)//2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

pref = [[] for _ in range(N)]

res = []

for i in range(M):
    p, y = map(int, input().split())
    pref[p-1].append(y)
    res.append((p-1, y))

for ar in pref:
    ar.sort()

for pre, year in res:
    p = str(pre + 1)
    p_zero = p.zfill(6)
    y = str(pref[pre].index(year) + 1)
    y_zero = y.zfill(6)
    print(p_zero + y_zero)

Fixed submission:
import bisect
N, M = map(int, input().split())

L = [[] for i in range(N)]
D = []

for i in range(M):
    p, y= map(int, input().split())
    L[p-1].append(y)
    D.append([p,y])

for i in range(N):
    L[i].sort()

for i in range(M):
    ans = str(D[i][0]).zfill(6)+ str(bisect.bisect_left(L[D[i][0]-1], D[i][1])+1).zfill(6)
    print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
ans = 0
extra = [0]*N
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)

Fixed submission:
N, K = map(int, input().split())
ans = 0
extra = [0]*K
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

ans = 0
extra = [0] * N
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)


Fixed submission:
N, K = map(int, input().split())
ans = 0
extra = [0]*K
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

ans = 0
extra = [0] * N
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] + extra[b] + extra[c]
print(ans)


Fixed submission:
N, K = map(int, input().split())
ans = 0
extra = [0]*K
for i in range(1, N+1): extra[i%K] += 1 #extra[X] = Kで割ってXあまる数がN以下に何個あるか

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K

    if (b + c) % K == 0:
        ans += extra[a] * extra[b] * extra[c]
print(ans)
Buggy python submission (verdict: Runtime Error):
S=input()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])

op = ["+","-"]

for i in op:
  for j in op:
    for k in op:
      if eval("A {} B {} C {} D".format(i, j, k)) == 7:
        print("{}{}{}{}{}{}{}{}{}".format(A, i, B, j, C, k, D))
        exit()

Fixed submission:
S=input()
A=int(S[0])
B=int(S[1])
C=int(S[2])
D=int(S[3])

op = ["+","-"]

for i in op:
  for j in op:
    for k in op:
      if eval("A {} B {} C {} D".format(i, j, k)) == 7:
        print("{}{}{}{}{}{}{}=7".format(A, i, B, j, C, k, D))
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

# 約数の個数
def divisible_count(n):
    divisors = 0
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors += 1
            if i != n // i:
                divisors += 1
    return divisors

res = 0
for i in range(1, n):
    num = n - i
    res += divisible_count(num)

print(res)


Fixed submission:
n = int(input())

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

div = num_divisors_table(n)

res = 0
for c in range(1, n):
    num = n - c
    res += div[num]

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce

n = int(input())
A = list(map(int, input().split()))
res = ['pairwise coprime', 'setwise coprime', 'not coprime']

# 素因数分解 O(n ** 0.5)
def prime_factor(n):
    factor = []
    for i in range(2, int(n ** 0.5) + 1):
        while (n % i == 0):
            factor.append(i)
            n //= i
    if n != 1:
        factor.append(n)
    return factor

prime_factors = []
for a in A:
    factor = prime_factor(a)
    factor_set = list(set(factor))
    prime_factors.extend(factor_set)

if len(prime_factors) == len(set(prime_factors)):
    print(res[0])
elif reduce(gcd, A) == 1:
    print(res[1])
else:
    print(res[2])

Fixed submission:
from math import gcd
from functools import reduce

n = int(input())
A = list(map(int, input().split()))
res = ['pairwise coprime', 'setwise coprime', 'not coprime']

MAX = 10 ** 6 + 1000
dp = [i for i in range(MAX)]
# dp[x]はxを割り切る最小の素数
for x in range(2, MAX):
    if dp[x] < x: continue
    for y in range(x + x, MAX, x):
        if dp[y] == y:
            dp[y] = x

def get_factor(n):
    factors = []
    while n > 1:
        factors.append(dp[n])
        n //= dp[n]
    return factors

prime_factors = []
for a in A:
    factor = get_factor(a)
    factor_set = list(set(factor))
    prime_factors.extend(factor_set)

if len(prime_factors) == len(set(prime_factors)):
    print(res[0])
elif reduce(gcd, A) == 1:
    print(res[1])
else:
    print(res[2])
Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
hw = []
cnt_h, cnt_w = [0] * H, [0] * W
for i in range(M):
    x, y = map(int, input().split())
    hw.append((x - 1, y - 1))
    cnt_h[x - 1] += 1
    cnt_w[y - 1] += 1

max_h, max_w = max(cnt_h), max(cnt_w)

h_list = [h for h in range(H) if cnt_h[h] == max_h]
w_list = [w for w in range(W) if cnt_w[w] == max_w]

from itertools import product

for h, w in product(h_list, w_list):
    if (h, w) not in set(hw):
        print(max_h + max_w)
        break
else:
    print(max_h + max_w - 1)
    

Fixed submission:
H, W, M = map(int, input().split())
hw = set()
cnt_h, cnt_w = [0] * H, [0] * W
for i in range(M):
    x, y = map(int, input().split())
    hw.add((x - 1, y - 1))
    cnt_h[x - 1] += 1
    cnt_w[y - 1] += 1

max_h, max_w = max(cnt_h), max(cnt_w)

h_list = [h for h in range(H) if cnt_h[h] == max_h]
w_list = [w for w in range(W) if cnt_w[w] == max_w]

res = max_h + max_w - 1
for h in h_list:
    for w in w_list:
        if (h, w) not in hw:
            print(res + 1)
            exit()
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
num = 7
i = 1
while True:
    if num % k == 0:
        print(i)
        exit()
    if i >= k:
        print('-1')
        exit()
    num *= 10
    num += 7
    i += 1


Fixed submission:
k = int(input())

if k % 2 == 0:
    print('-1')
    exit()

mod = [pow(10, i, k) for i in range(0, 1000000)]

num = 0
for i in range(0, 1000000):
    num += mod[i]
    if 7 * num % k == 0:
        print(i + 1)
        exit()

print('-1')
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list(map(int, input().split()))

prod = [1] * (n + 1)
prod[1] = A[0]
for i in range(2, n + 1):
    prod[i] = prod[i - 1] * A[i - 1]

pre_score = prod[k]

for i in range(k + 1, n + 1):
    score = prod[i] // prod[i - k]
    if score > pre_score:
        print('Yes')
    else:
        print('No')
    pre_score = score


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

for i in range(k, n):
    if A[i] > A[i - k]:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list(map(int, input().split()))

score = [1] * (n - k + 1)
for i in range(k):
    score[0] *= A[i]

for i in range(1, n - k + 1):
    score[i] = score[i - 1] // A[i - 1]
    # score[i] //= A[i]
    score[i] *= A[i + k - 1]
    
# print(score)


for i in range(1, len(score)):
    pre = score[i - 1]
    now = score[i]
    if now > pre:
        print('Yes')
    else:
        print('No')

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

for i in range(k, n):
    if A[i] > A[i - k]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

from operator import mul, xor
from functools import reduce

def grow(arr):
    return reduce(mul, arr)

res = grow(A)
print(res) if res <= 10 ** 18 else print(-1)

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

if 0 in A:
    print(0)
    exit()

dp = [1] * (n + 1)
for i in range(n):
    dp[i + 1] = dp[i] * A[i]
    if dp[i + 1] > 10 ** 18:
        print(-1)
        exit()

print(dp[n])