Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    for k in range(K+1):
        s = list(itertools.accumulate(dp[i-1]))
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)



Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    s = list(itertools.accumulate(dp[i - 1]))
    for k in range(K+1):
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)

Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
import numpy as np

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    for k in range(K+1):
        s = np.cumsum(dp[i-1])
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)



Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    s = list(itertools.accumulate(dp[i - 1]))
    for k in range(K+1):
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

N = int(input())
a = [[] for i in range(N)]
for i in range(N):
    a[i] = list(map(int, input().split()))

dp = [0 for i in range(1<<N)]
dp[0] = 1

for S in range(1,1<<N):
    i = popcount(S)
    for j in range(N):
        if bit(S,j) == 1 and a[i-1][j] == 1:
            dp[S] = (dp[S] + dp[S^(1<<j)]) % mod

print(dp[(1<<N)-1] % mod)

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

N = int(input())
a = [[] for i in range(N)]
for i in range(N):
    a[i] = list(map(int, input().split()))

dp = [0 for i in range(1<<N)]
dp[0] = 1

for S in range(1,1<<N):
    i = popcount(S)
    for j in range(N):
        if bit(S,j) == 1 and a[i-1][j] == 1:
            dp[S] = (dp[S] + dp[S^(1<<j)]) % mod

print(dp[(1<<N)-1] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

K = input()
D = int(input())

n = len(K)

dp = [[[0 for k in range(D)] for j in range(2)] for i in range(n+1)]
dp[0][0][0] = 1

for i in range(1,n+1):
    for k in range(D):
        for j in range(10):
            dp[i][1][k] += dp[i-1][1][(k-j) % D]
        for j in range(int(K[i-1])):
            dp[i][1][k] += dp[i-1][0][(k-j) % D]
        dp[i][0][k] += dp[i-1][0][(k-int(K[i-1])) % D]

print((dp[n][1][0] + dp[n][0][0] -1) % mod)


Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

K = input()
D = int(input())

n = len(K)

dp = [[[0 for k in range(D)] for j in range(2)] for i in range(n+1)]
dp[0][0][0] = 1

for i in range(1,n+1):
    for k in range(D):
        for j in range(10):
            dp[i][1][k] = (dp[i][1][k] + dp[i-1][1][(k-j) % D]) % mod
        for j in range(int(K[i-1])):
            dp[i][1][k] = (dp[i][1][k] + dp[i-1][0][(k-j) % D]) % mod
        dp[i][0][k] = (dp[i][0][k] + dp[i-1][0][(k-int(K[i-1])) % D]) % mod

print((dp[n][1][0] + dp[n][0][0] -1) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

N = int(input())
a = [[] for i in range(N)]
for i in range(N):
    a[i] = list(map(int, input().split()))

dp = [-INF for i in range(1<<N)]
dp[0] = 0

@functools.lru_cache(None)
def calc(S):
    dp[S] = 0
    for i in range(N):
        for j in range(i+1, N):
            if bit(S,i) and bit(S,j): dp[S] += a[i][j]

    T = S - 1
    T = T & S
    while T > 0:
        dp[S] = max(dp[S], calc(T) + calc(S^T))
        T = T - 1
        T = T & S

    return dp[S]

print(calc((1<<N)-1))




Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics
mod = 10**9+7

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

N = int(input())
a = [[] for i in range(N)]
for i in range(N):
    a[i] = list(map(int, input().split()))

dp = [-INF for i in range(1<<N)]
dp[0] = 0

for S in range(1<<N):
    dp[S] = 0
    for i in range(N):
        for j in range(i+1, N):
            if bit(S,i) and bit(S,j): dp[S] += a[i][j]

    T = S - 1
    T = T & S
    while T > 0:
        dp[S] = max(dp[S], dp[T] + dp[S^T])
        T = T - 1
        T = T & S

print(dp[(1<<N)-1])
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import numpy

N = int(input())
a = list(map(int, input().split()))

for i in range(N):
    a[i] = a[i] - i

def f(k):
    return sum(map(lambda x: abs(x-k), a))

c = numpy.median(a)
print(int(f(c)))




Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect
import statistics

N = int(input())
a = list(map(int, input().split()))

for i in range(N):
    a[i] = a[i] - i

def f(k):
    return sum(map(lambda x: abs(x-k), a))

c = statistics.median(a)
print(int(f(c)))
Buggy python submission (verdict: Runtime Error):
from sys import stdin

n = stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]

count = 0
b = a[0]
while True:
    if b % 2 == 1: break
    b = b//2
    count = count + 1
minc = count

for b in a[1:]:
    count = 0
    while True:
        if b % 2 == 1: break
        b = b//2
        count = count + 1

    minc = min([minc, count])

print(minc)

Fixed submission:
from sys import stdin

a = stdin.readline().rstrip()

count = 0

for b in a:
  if b == "1": count = count + 1

print(count)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

n = stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]

count = 0
b = a[0]
while True:
    if b % 2 == 1: break
    b = b//2
    count = count + 1
minc = count

for b in a[1:]:
  	count = 0
    while True:
        if b % 2 == 1: break
        b = b//2
        count = count + 1

    minc = min([minc, count])

print(minc)

Fixed submission:
from sys import stdin

n = stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]

minc = 10**9

for b in a:
    count = 0
    while True:
        if b % 2 == 1: break
        b = b//2
        count = count + 1

    minc = min([minc, count])

print(minc)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy

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

road = [[] for i in range(n+1)]
rail = [[] for i in range(n+1)]

for i in range(k):
    p, q = list(map(int, input().split()))
    road[p].append(q)
    road[q].append(p)

for i in range(l):
    r, s = list(map(int, input().split()))
    rail[r].append(s)
    rail[s].append(r)

seen = [0 for i in range(n+1)]

def dfs_stack(u, al):
    stack = deque([u])
    seen[u] = 1
    visited = []

    while len(stack) > 0:
        v = stack.pop()
        ###
        visited.append(v)
        ###

        for w in al[v]:
            if seen[w] == 0:
                stack.append(w)
                seen[w] = 1

        if stack == []: break

    return visited

road_c = []
rail_c = []
for i in range(1,n+1):
    if seen[i] == 0:
        road_c.append(dfs_stack(i, road))

seen = [0 for i in range(n+1)]

for i in range(1,n+1):
    if seen[i] == 0:
        rail_c.append(dfs_stack(i, rail))

ans = [0 for i in range(n+1)]
for a in road_c:
    for b in rail_c:
        intersection = set(a) & set(b)
        for i in intersection:
            ans[i] = str(len(intersection))

print(' '.join(ans[1:]))


Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy

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

road = [[] for i in range(n+1)]
rail = [[] for i in range(n+1)]

for i in range(k):
    p, q = list(map(int, input().split()))
    road[p].append(q)
    road[q].append(p)

for i in range(l):
    r, s = list(map(int, input().split()))
    rail[r].append(s)
    rail[s].append(r)

seen = [0 for i in range(n+1)]

def dfs_stack(u, al, al_c, d):
    stack = deque([u])
    seen[u] = 1

    while len(stack) > 0:
        v = stack.pop()
        ###
        al_c[v] = d
        ###

        for w in al[v]:
            if seen[w] == 0:
                stack.append(w)
                seen[w] = 1

        if stack == []: break


road_c = [-1 for i in range(n+1)]
rail_c = [-1 for i in range(n+1)]

d = 0
for i in range(1,n+1):
    if seen[i] == 0:
        dfs_stack(i, road, road_c, d)
        d += 1

seen = [0 for i in range(n+1)]

d = 0
for i in range(1,n+1):
    if seen[i] == 0:
        dfs_stack(i, rail, rail_c, d)
        d += 1

dict = {}

for i in range(1, n+1):
    if (road_c[i], rail_c[i]) not in dict:
        dict[(road_c[i], rail_c[i])] = [i]
    else:
        dict[(road_c[i], rail_c[i])].append(i)

ans = [0 for i in range(n+1)]

for dd in dict.items():
    for j in dd[1]:
        ans[j] = str(len(dd[1]))

print(' '.join(ans[1:]))
Buggy python submission (verdict: Runtime Error):
import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


N, K = map(int, input().split())
leng = list(map(int, input().split()))

d_min = 0
d_max = max(leng)
d = d_max / 2

while d_max - d_min >= 1:
    if check(d):
        d_max = d
    else:
        d_min = d
    d = (d_max + d_min) / 2
    # print(d, d_max, d_min)

if check(math.ceil(d_min)):
    print(math.ceil(d_min))
else:
    print(math.ceil(d_min)+1)


Fixed submission:
import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


N, K = map(int, input().split())
leng = list(map(int, input().split()))

d_min = 0
d_max = max(leng)
d = math.ceil(d_max / 2)

while d_max - d_min > 1:
    if check(d):
        d_max = d
        d = math.ceil((d_max + d_min) / 2)
    else:
        d_min = d
        d = int((d_max + d_min) / 2)
    # print(d, d_max, d_min)

print(d_max)

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

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


N, K = map(int, input().split())
leng = list(map(int, input().split()))
d = max(leng)

d_min = 0
d_max = d

while d_max - d_min >= 1:
    if check(d):
        d_max = d
    else:
        d_min = d
    d = (d_max + d_min) / 2
    # print(d, d_max, d_min)

if check(math.ceil(d_min)):
    print(math.ceil(d_min))
else:
    print(math.ceil(d_min)+1)


Fixed submission:
import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


N, K = map(int, input().split())
leng = list(map(int, input().split()))

d_min = 0
d_max = max(leng)
d = math.ceil(d_max / 2)

while d_max - d_min > 1:
    if check(d):
        d_max = d
        d = math.ceil((d_max + d_min) / 2)
    else:
        d_min = d
        d = int((d_max + d_min) / 2)
    # print(d, d_max, d_min)

print(d_max)

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

N, K = map(int, input().split())
leng = list(map(int, input().split()))
leng.sort()
cut = [0] * N
# A = [maruta(a, 0) for a in A_tmp]
for a in range(K):
    new_cut = cut.pop() + 1
    new_leng = leng.pop() * (new_cut / (new_cut + 1))
    idx = bisect.bisect_left(leng, new_leng)
    leng.insert(idx, new_leng)
    cut.insert(idx, new_cut)
    # print(new_leng, new_cut)
print(math.ceil(leng[-1]))


Fixed submission:
import math

def check(d):
    cut_num = 0
    for i in leng:
        cut_num += math.ceil(i / d) - 1
    if cut_num <= K:
        return True
    return False


N, K = map(int, input().split())
leng = list(map(int, input().split()))

d_min = 0
d_max = max(leng)
d = math.ceil(d_max / 2)

while d_max - d_min > 1:
    if check(d):
        d_max = d
        d = math.ceil((d_max + d_min) / 2)
    else:
        d_min = d
        d = int((d_max + d_min) / 2)
    # print(d, d_max, d_min)

print(d_max)
Buggy python submission (verdict: Runtime Error):
class edge:
    def __init__(self, u, v):
        self.u = u
        self.v = v
    def min(self):
        return min(self.u, self.v)
    def max(self):
        return max(self.u, self.v)

N = int(input())
 
edge_list = []
for i in range(N - 1):
    u, v = map(int, input().split())
    edge_list.append(edge(u - 1, v - 1))
 
ver_num = int(N * (N + 1) * (N + 2) / 6)
 
edge_num = 0
for e in edge_list:
    edge_num += (N + 1 - (e.max() + 1)) * (e.min() + 1)
    
print(ver_num - edge_num)

Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - N % 1000)
Buggy python submission (verdict: Runtime Error):
from collections import deque

N, K = map(int, input().split())
table = list(map(int, input().split()))
jnum = K - sum(1 for i in table if i >= 0)
q_plus = deque(sorted([i for i in table if i >= 0], reverse=True))
q_mins = deque(sorted([-i for i in table if i < 0], reverse=True))
s_plus = []
s_mins = []
total = 1


if jnum < 0 or jnum % 2 == 0:
    for i in range(K):
        if not q_plus:
            s_mins.append(q_mins.pop())
        elif not q_mins:
            s_plus.append(q_plus.pop())
        elif q_plus[0] > q_mins[0]:
            s_plus.append(q_plus.pop())
        else:
            s_mins.append(q_mins.pop())
    if len(s_mins) % 2 == 1:
        if not q_plus:
            s_plus[-1] = q_mins[0]
        elif not q_mins:
            s_mins[-1] = q_plus[0]
        elif q_mins[0] * s_mins[-1] > q_plus[0] * s_plus[-1]:
            s_plus[-1] = q_mins[0]
        else:
            s_mins[-1] = q_plus[0]
    s_plus.extend(s_mins)
    for j in s_plus:
        total = total * j % (10 ** 9 + 7)

else:
    for i in range(K):
        if not q_plus:
            total = total * q_mins.pop() * -1 % (10 ** 9 + 7)
        elif not q_mins:
            total = total * q_plus.pop() * -1 % (10 ** 9 + 7)
        elif q_plus[-1] > q_mins[-1]:
            total = total * q_mins.pop() * -1 % (10 ** 9 + 7)
        else:
            total = total * q_plus.pop() * -1 % (10 ** 9 + 7)

print(total)

Fixed submission:
from collections import deque

N, K = map(int, input().split())
table = list(map(int, input().split()))
jnum = K - sum(1 for i in table if i >= 0)
num_mins = sum(1 for i in table if i < 0)
q_plus = deque(sorted([i for i in table if i >= 0], reverse=True))
q_mins = deque(sorted([-i for i in table if i < 0], reverse=True))
s_plus = []
s_mins = []
total = 1


# if jnum < 0 or jnum % 2 == 0:
if (K % 2 == 1 and N == num_mins) or (N == K and num_mins % 2 == 1):
    for i in range(K):
        if not q_plus:
            total = -total * q_mins.pop() % (10 ** 9 + 7)
        elif not q_mins:
            total = total * q_plus.pop() % (10 ** 9 + 7)
        elif q_plus[-1] > q_mins[-1]:
            total = -total * q_mins.pop() % (10 ** 9 + 7)
        else:
            total = total * q_plus.pop() % (10 ** 9 + 7)
    total = total % (10 ** 9 + 7)
else:
    for i in range(K):
        if not q_plus:
            s_mins.append(q_mins.popleft())
        elif not q_mins:
            s_plus.append(q_plus.popleft())
        elif q_plus[0] > q_mins[0]:
            s_plus.append(q_plus.popleft())
        else:
            s_mins.append(q_mins.popleft())
    if len(s_mins) % 2 == 1:
        if not q_plus:
            s_plus[-1] = q_mins[0]
        elif not q_mins or not s_plus:
            s_mins[-1] = q_plus[0]
        elif q_mins[0] * s_mins[-1] > q_plus[0] * s_plus[-1]:
            s_plus[-1] = q_mins[0]
        else:
            s_mins[-1] = q_plus[0]
    s_plus.extend(s_mins)
    for j in s_plus:
        total = total * j % (10 ** 9 + 7)


print(total)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ssum = 0
start = time.time()
for k in range(1, N + 1):
    X = int(N / k)
    ssum += k * X * (X + 1) / 2
print(int(ssum))

Fixed submission:
# import time
N = int(input())
ssum = 0
# start = time.time()
for k in range(1, N + 1):
    X = int(N / k)
    ssum += k * X * (X + 1) / 2
print(int(ssum))
# elapsed_time = time.time() - start
# print("elapsed_time:{0}".format(elapsed_time) + "[sec]")
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    H, W, M = map(int, input().split())
    mm = []
    l = np.zeros((H, W))
    for i in range(M):
        a, b = map(int, input().split())
        mm.append([a, b])
        l[a-1][b-1] = 1
    row_max = 0
    row_num = 0
    col_max = 0
    col_num = 0

    r = np.count_nonzero(l == 1, axis=1)
    row_max = max(r)
    row_num = np.argmax(r)

    c = np.count_nonzero(l == 1, axis=0)
    col_max = max(c)
    col_num = np.argmax(c)

    a = np.count_nonzero(c == col_max)
    if [row_num+1, col_num+1] in mm:
        print(row_max + col_max - 1)
    else:
        print(row_max + col_max)
        
if __name__ == '__main__':
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0] * H
    ws = [0] * W
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                exit()
    print(ans-1)


if __name__ == '__main__':
    main()