Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02633 (python)

Fixed submission:
import numpy as np
import math

def main():
    X=int(input())

    res=0
    vec=np.array([1,0])
    rot=np.array([[math.cos(math.radians(X)),-1*math.sin(math.radians(X))],[math.sin(math.radians(X)),math.cos(math.radians(X))]])
    pos=np.array([0,0])

    pos=pos+vec
    vec=np.dot(rot,vec)
    res+=1
    while abs(pos[0])>=0.001 or abs(pos[1])>=0.001:
        pos=pos+vec
        vec=np.dot(rot,vec)
        res+=1
    print(res)

if __name__=="__main__":
    main()

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

def main():
    X=int(input())

    res=0
    vec=np.array([1,0])
    rot=np.array([[math.cos(math.radians(X)),-1*math.sin(math.radians(X))],[math.sin(math.radians(X)),math.cos(math.radians(X))]])
    pos=np.array([0,0])

    pos=pos+vec
    vec=np.dot(rot,vec)
    res+=1
    while abs(pos[0])>=0.001 or abs(pos[1])>=0.001:
        pos=pos+vec
        vec=np.dot(rot,vec)
        res+=1
    print(res)

if __name__=="__main__":
    main()
Problem p02762 (python)

Fixed submission:
def main():
    N,M,K=map(int,input().split())

    G=[[] for i in range(N)]

    for i in range(M):
        a,b=map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    B=[[] for i in range(N)]
    for i in range(K):
        c,d=map(int,input().split())
        B[c-1].append(d-1)
        B[d-1].append(c-1)
    trace=[-1 for i in range(N)]
    Group=[]

    for i in range(N):
        stack=[]
        if trace[i]==-1:
            trace[i]=0
            stack.append(i)
        Group_tmp=[]
        while len(stack)>0:
            index=stack.pop()
            Group_tmp.append(index)
            for j in G[index]:
                if trace[j]==-1:
                    trace[j]=0
                    stack.append(j)
        if len(Group_tmp)!=0:
            Group.append(Group_tmp)
    res=[0 for i in range(N)]
    GroupMarker=[-1 for i in range(N)]

    for i in range(len(Group)):
        for j in range(len(Group[i])):
            person=Group[i][j]
            GroupMarker[person]=i
            r=len(Group[i])-len(G[person])-1
            res[person]=r

    for i in range(len(B)):
        for j in range(len(B[i])):
            if GroupMarker[i]==GroupMarker[B[i][j]]:
                res[i]-=1
    res=list(map(str,res))
    print(" ".join(res))

if __name__=="__main__":
    main()

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

    G=[[] for i in range(N)]
    B = [[] for i in range(N)]

    for i in range(M):
        a,b=map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    C=[]
    D=[]
    for i in range(K):
        c,d=map(int,input().split())
        C.append(c-1)
        D.append(d-1)
    trace=[-1 for i in range(N)]
    Group=[]
    Group_tmp=[]
    def dfs(n):
        if trace[n]!=-1:
            return 0
        Group_tmp.append(n)
        trace[n]=0
        for dist in G[n]:
            dfs(dist)
        if len(G[n])==0:
            return 0

    for i in range(len(trace)):
        if trace[i]==-1:
            Group_tmp=[]
            dfs(i)
            Group.append(Group_tmp)

    res=[0 for i in range(N)]
    GroupMarker=[-1 for i in range(N)]

    for i in range(len(Group)):
        for j in range(len(Group[i])):
            person=Group[i][j]
            GroupMarker[person]=i
            r=len(Group[i])-len(G[person])-1
            res[person]=r
    for i in range(K):
        if D[i] in Group[GroupMarker[C[i]]]:
            res[D[i]]-=1
            res[C[i]]-=1

    res=list(map(str,res))
    print(" ".join(res))

if __name__=="__main__":
    main()
Problem p02598 (python)

Fixed submission:
# ABC174 E

n, k = map(int, input().split())
a_l = [int(x) for x in input().split()]

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        if a_l[i] % len == 0:
            ret += a_l[i] // len - 1
        else:
            ret += a_l[i] // len
    return ret


while (right - left) > 1:
    _q = (left + right) // 2
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

print(right)

Buggy submission (verdict: Runtime Error):
# ABC174 E

n, k = map(int, input().split())
a_l = [int(x) for x in input().split()]

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        if a_l[i] % len == 0:
            ret += a_l[i] // len - 1
        else:
            ret += a_l[i] // len
    return ret


while (right - left) > 1:
    _q = max((left + right) // 2, 1)
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)

Buggy submission (verdict: Runtime Error):
# ABC174 E

n, k = map(int, input().split())
a_l = [int(x) for x in input().split()]

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        if a_l[i] % len == 0:
            ret += a_l[i] // len - 1
        else:
            ret += a_l[i] // len
    return ret


while (right - left) > 1:
    _q = (left + right) // 2
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)

Buggy submission (verdict: Runtime Error):
# ABC174 E

import math

n, k = map(int, input().split())
a_l = [int(x) for x in input().split()]

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        ret += math.ceil(float(a_l[i] / len)) - 1
    return ret


while (right - left) > 1:
    _q = (left + right) // 2
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)

Buggy submission (verdict: Runtime Error):
# ABC174 E

import math

n, k = map(int, input().split())
a_l = [int(x) for x in input().split()]

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        ret += math.ceil(float(a_l[i] / len)) - 1
    return ret


while (right - left) > 1:
    _q = (left + right) // 2
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)

Buggy submission (verdict: Runtime Error):
# ABC174 E

import math

n, k = map(int, input().split())
a_l = [int(x) for x in input().split()]

left = 0
right = max(a_l)


def cut(len):
    ret = 0
    for i in range(n):
        ret += math.ceil(float(a_l[i] / len)) - 1
    return ret


while (right - left) > 1:
    _q = (left + right) // 2
    _ret = cut(_q)
    if k >= _ret:
        right = _q
    else:
        left = _q

_l = cut(left)
_r = cut(right)

if _l <= k:
    print(left)
else:
    print(right)
Problem p02623 (python)

Fixed submission:
# C

import itertools
import bisect

n, m, k = map(int, input().split())
a_l = [int(x) for x in input().split()]
b_l = [int(x) for x in input().split()]

cumsuma_l = list(itertools.accumulate(a_l)) 
cumsumb_l = list(itertools.accumulate(b_l))

_idx = bisect.bisect_left(cumsumb_l, k)
if _idx == m or cumsumb_l[_idx] != k:
    _idx -= 1
ans = _idx + 1
    
for i in range(n):
    _a = cumsuma_l[i]
    if _a > k:
        break
    _tmp = k - _a
    _idx = bisect.bisect_left(cumsumb_l, _tmp)
    if _idx == m or cumsumb_l[_idx] != _tmp:
        _idx -= 1
    ans = max(ans, i + _idx + 2)
        
print(ans)

Buggy submission (verdict: Runtime Error):
# C

import itertools
import bisect

n, m, k = map(int, input().split())
a_l = [int(x) for x in input().split()]
b_l = [int(x) for x in input().split()]

cumsuma_l = list(itertools.accumulate(a_l)) 
cumsumb_l = list(itertools.accumulate(b_l))

_idx = bisect.bisect_left(cumsumb_l, k)
if _idx == m or cumsumb_l[_idx] != _tmp:
    _idx -= 1
ans = _idx + 1
    
for i in range(n):
    _a = cumsuma_l[i]
    if _a > k:
        break
    _tmp = k - _a
    _idx = bisect.bisect_left(cumsumb_l, _tmp)
    if _idx == m or cumsumb_l[_idx] != _tmp:
        _idx -= 1
    ans = max(ans, i + _idx + 2)
        
print(ans)
Problem p02699 (python)

Fixed submission:
# A
# Sheep and Wolves

s, w = map(int, input().split())

if s <= w:
    print("unsafe")
else:
    print("safe")

Buggy submission (verdict: Runtime Error):
# D
# Multiple of 2019

s = input()

d = len(s)

ans = 0

if d < 5:
    if int(s)%2019 == 0:
        print("1")
    else:
        print("0")
else:
    for j in range(4,d,1):
        for i in range(j-3):
            _tmp = int(s[i:j+1])
            if _tmp % 2019 == 0:
                ans +=1

    print(ans)

Buggy submission (verdict: Runtime Error):
# A
# Sheep and Wolves

s w = map(int, input().split())

if s <= w:
    print("unsafe")
else:
    print("safe")
Problem p02862 (python)

Fixed submission:
# 73

MOD = 10**9 + 7
x, y = map(int, input().split())

a = 2*y - x
b = 2*x - y

fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)


def com_init():
    fac_l[1] = 1
    inv_l[0] = 1
    inv_l[1] = 1
    finv_l[0] = 1
    finv_l[1] = 1
    for i in range(2, a+b+1):
        fac_l[i] = (fac_l[i-1] * i) % MOD
        inv_l[i] = MOD - (inv_l[MOD % i] * int(MOD / i)) % MOD
        finv_l[i] = (finv_l[i-1] * inv_l[i]) % MOD

def ncr(n, r):
    return (fac_l[n] * (finv_l[r] * finv_l[n-r]) % MOD) % MOD


if a % 3 != 0 or b % 3 != 0 or a < 0 or b < 0:
    print("0")
else:
    a = int(a/3)
    b = int(b/3)

    com_init()
    print(ncr(a+b, a))

Buggy submission (verdict: Runtime Error):
# 73

MOD = 10**9 + 7
x, y = map(int, input().split())

a = 2*y - x
b = 2*x - y

fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)


def com_init():
    fac_l[1] = 1
    inv_l[0] = 1
    inv_l[1] = 1
    finv_l[0] = 1
    finv_l[1] = 1
    for i in range(2, a+b+1):
        fac_l[i] = (fac_l[i-1] * i) % MOD
        inv_l[i] = MOD - (inv_l[MOD % i] * int(MOD / i)) % MOD
        finv_l[i] = (finv_l[i-1] * inv_l[i]) % MOD

def ncr(n, r):
    return (fac_l[n] * (finv_l[r] * finv_l[n-r]) % MOD) % MOD


if a % 3 != 0 or b % 3 != 0:
    print("0")
else:
    a = int(a/3)
    b = int(b/3)

    com_init()
    print(ncr(a+b, a))

Buggy submission (verdict: Runtime Error):
# 73

MOD = 10**9 + 7
x, y = map(int, input().split())

a = 2*y - x
b = 2*x - y

fac_l = [0] * (int((a + b) / 3) + 1)
inv_l = [0] * (int((a + b) / 3) + 1)
finv_l = [0] * (int((a + b) / 3) + 1)


def com_init():
    fac_l[1] = 1
    inv_l[0] = 1
    inv_l[1] = 1
    finv_l[0] = 1
    finv_l[1] = 1
    for i in range(2, a+b+1):
        fac_l[i] = (fac_l[i-1] * i) % MOD
        inv_l[i] = MOD - (inv_l[MOD % i] * int(MOD / i)) % MOD
        finv_l[i] = finv_l[i-1] * inv_l[i] % MOD


def ncr(n, r):
    return (((fac_l[n] * finv_l[r]) % MOD) * finv_l[n-r]) % MOD


if a % 3 != 0 or b % 3 != 0:
    print("0")
else:
    a = int(a/3)
    b = int(b/3)

    com_init()
    print(ncr(a+b, a))
Problem p03013 (python)

Fixed submission:
# ABC129 C

MOD = 10**9 + 7
n, m = map(int, input().split())
a_l = [int(input()) for _ in range(m)]

dp = [0] * (n+1)
dp[0] = 1
k = 0
if m > 0 and a_l[0] == 1:
    k = min(k+1, m-1)
else:
    dp[1] = 1

for i in range(2, n+1):
    if m > 0 and i == a_l[k]:
        k = min(k+1, m-1)
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % MOD
    
print(dp[n])

Buggy submission (verdict: Runtime Error):
# ABC129 C

MOD = 10**9 + 7
n, m = map(int, input().split())
a_l = [int(input()) for _ in range(m)]

dp = [0] * (n+1)
dp[0] = 1
k = 0
if m > 0 and a_l[0] == 1:
    k += 1
else:
    dp[1] = 1

for i in range(2, n+1):
    if m > 0 and i == a_l[k]:
        k = min(k+1, m-1)
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % MOD
    
print(dp[n])

Buggy submission (verdict: Runtime Error):
# ABC129 C

MOD = 10**9 + 7
n, m = map(int, input().split())
a_l = [int(input()) for _ in range(m)]

dp = [0] * (n+1)
dp[0] = 1
k = 0
if a_l[0] == 1:
    k += 1
else:
    dp[1] = 1

for i in range(2, n+1):
    if i == a_l[k]:
        k = min(k+1, m-1)
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % MOD
    
print(dp[n])
Problem p03785 (python)

Fixed submission:
# AGC011 A Airport Bus
import bisect
from collections import deque

n, c, k = map(int, input().split())
t_list = [int(input()) for _ in range(n)]

t_list.sort()
t_list = deque(t_list)
ans = 0

while len(t_list) > 0:
    _tmp = t_list.popleft() + k
    _idx = bisect.bisect_right(t_list, _tmp)
    if c-1 <= _idx:
        for _ in range(c-1):
            t_list.popleft()
    else:
        for _ in range(_idx):
            t_list.popleft()
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
# AGC011 A Airport Bus
import bisect
from collections import deque

n, c, k = map(int, input().split())
t_list = [int(input()) for _ in range(n)]

t_list.sort()
t_list = deque(t_list)
ans = 0

while len(t_list) > 0:
    _tmp = t_list.popleft() + k
    _idx = bisect.bisect_right(t_list, _tmp)
    if c <= _idx + 1:
        for _ in range(c):
            t_list.popleft()
    else:
        for _ in range(_idx):
            t_list.popleft()
    ans += 1

print(ans)
Problem p02598 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def judge(x):
    cnt = 0
    
    for Ai in A:
        cnt += (Ai+x-1)//x-1
    
    return cnt<=K

def binary_search():
    l, r = 1, 10**9+100
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

N, K = map(int, input().split())
A = list(map(int, input().split()))
print(binary_search())

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def judge(x):
    cnt = 0
    
    for Ai in A:
        cnt += (Ai+x-1)//x-1
    
    return cnt<=K

def binary_search():
    l, r = 0, 10**9+100
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

N, K = map(int, input().split())
A = list(map(int, input().split()))
print(binary_search())
Problem p02679 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import *

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

N = int(input())
zero1 = 0
zero2 = 0
zero3 = 0
cnt = defaultdict(int)
MOD = 10**9+7

for _ in range(N):
    A, B = map(int, input().split())
    
    if A==0 and B==0:
        zero1 += 1
    elif A>0 and B>0:
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(A, B)] += 1
    elif A>0 and B<0:
        B *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(-A, B)] += 1
    elif A<0 and B>0:
        A *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(-A, B)] += 1
    elif A<0 and B<0:
        A *= -1
        B *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(A, B)] += 1
    elif A==0:
        zero2 += 1
    elif B==0:
        zero3 += 1

s = set()
ans = 1

for k in cnt.keys():
    if k in s:
        continue
    
    k2 = (-k[1], k[0])
    
    if k2[0]<0 and k2[1]<0:
        k2 = (-k2[0], -k2[1])
        
    a = cnt[k]
    
    if k2 not in cnt:
        ans *= pow(2, a, MOD)
        ans %= MOD
    else:
        b = cnt[k2]
        ans *= pow(2, a, MOD)+pow(2, b, MOD)-1
        ans %= MOD
        s.add(k2)

ans *= pow(2, zero2, MOD)+pow(2, zero3, MOD)-1
ans += zero1
ans %= MOD
ans -= 1
ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import *
from math import gcd

N = int(input())
cnt = defaultdict(int)
abzero = 0
azero = 0
bzero = 0

for _ in range(N):
    A, B = map(int, input().split())
    
    if A==0 and B==0:
        abzero += 1
    elif A==0:
        azero += 1
    elif B==0:
        bzero += 1
        
    G = gcd(abs(A), abs(B))
    A //= G
    B //= G
    
    if (A<0 and B>0) or (A<0 and B<0):
        A *= -1
        B *= -1
    
    cnt[(A, B)] += 1

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import *
from math import gcd

N = int(input())
cnt = defaultdict(int)
abzero = 0
azero = 0
bzero = 0

for _ in range(N):
    A, B = map(int, input().split())
    
    if A==0 and B==0:
        abzero += 1
    elif A==0:
        azero += 1
    elif B==0:
        bzero += 1
        
    G = gcd(abs(A), abs(B))
    A //= G
    B //= G
    
    if (A<0 and B>0) or (A<0 and B<0):
        A *= -1
        B *= -1
    
    cnt[(A, B)] += 1

ans = 1
MOD = 10**9+7
visited = set()

for k in cnt.keys():
    if k in visited:
        continue
    
    if k[0]>0 and k[1]>0:
        k2 = (k[1], -k[0])
    else:
        k2 = (-k[1], k[0])
    
    if k2 not in cnt:
        ans *= pow(2, cnt[k], MOD)
    else:
        ans *= pow(2, cnt[k], MOD)+pow(2, cnt[k2], MOD)-1
        visited.add(k2)

ans *= pow(2, azero, MOD)+pow(2, bzero, MOD)-1
ans %= MOD
ans += abzero-1
ans %= MOD
print(ans)
Problem p03055 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import *

def bfs(s):
    dist = [-1]*N
    dist[s] = 0
    q = deque([s])
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist

N = int(input())
G = [[] for _ in range(N)]

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

dist = bfs(0)
M = -1

for i in range(N):
    if dist[i]>M:
        M = dist[i]
        s = i

d = max(bfs(s))+1
dp = [False]*(d+1)
dp[1] = True

for i in range(3, d+1):
    dp[i] |= not dp[i-1]
    dp[i] |= not dp[i-2]

if dp[d]:
    print('First')
else:
    print('Second')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import *

def bfs(s):
    dist = [-1]*N
    dist[s] = 0
    q = deque([s])
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist

N = int(input())
G = [[] for _ in range(N)]

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

dist = bfs(0)
M = 0

for i in range(N):
    if dist[i]>M:
        M = dist[i]
        s = i

d = max(bfs(s))+1
dp = [False]*(d+1)
dp[1] = True

for i in range(3, d+1):
    dp[i] |= not dp[i-1]
    dp[i] |= not dp[i-2]

if dp[d]:
    print('First')
else:
    print('Second')
Problem p03805 (python)

Fixed submission:
from itertools import *

N, M = map(int, input().split())
G = [set() for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].add(b-1)
    G[b-1].add(a-1)

ans = 0

for p in permutations(range(N)):
    if p[0]!=0:
        continue
    
    flag = True
    
    for i in range(N-1):
        if p[i+1] not in G[p[i]]:
            flag = False
    
    if flag:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import *

N, M = map(int, input().split())
G = [set() for _ in range(M)]

for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].add(b-1)
    G[b-1].add(a-1)

ans = 0

for p in permutations(range(N)):
    if p[0]!=1:
        continue
    
    flag = True
    
    for i in range(N-1):
        if p[i+1] not in G[p[i]]:
            flag = False
    
    if flag:
        ans += 1

print(ans)
Problem p02557 (python)

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    A = LI()
    B = LI()

    c = collections.Counter()
    for x in A:
        c[x] += 1
    for x in B:
        c[x] += 1
        if c[x] > N:
            print('No')
            return

    s = 0
    for i in range(N):
        if A[i] == B[i]:

            p = bisect.bisect_left(B,B[i]+1,i+1)
            if p > N-1:
                p = s
                s += 1
                while B[i] == B[s]:
                    s+=1

            B[i],B[p] = B[p],B[i]
    print('Yes')
    print(*B,sep=' ')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    A = LI()
    B = LI()
    mb = B[-1]
    s = 0
    for i in range(N):
        if A[i] == B[i]:
            if B[i] < mb:
                p = bisect.bisect_left(B,B[i]+1,i+1)
            else:
                p = s
                s += 1

            B[i],B[p] = B[p],B[i]
            if A[i] == B[i]:
                print('No')
                return
    print('Yes')
    print(*B,sep=' ')

if __name__ == '__main__':
    main()
Problem p02580 (python)

Fixed submission:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    H,W,M = LI()
    t = [LI() for _ in range(M)]

    hmax = [0] * (H+1)
    wmax = [0] * (W+1)

    for x,y in t:
        hmax[x] += 1
        wmax[y] += 1

    ans = 0

    hm = max(hmax)
    wm = max(wmax)

    xcnt = 0
    ycnt = 0
    for x in range(H+1):
        if hmax[x] == hm:
            xcnt += 1
    for y in range(W+1):
        if wmax[y] == wm:
            ycnt += 1

    cnt = 0
    for x,y in t:
        if hmax[x] == hm and wmax[y] == wm:
            cnt += 1
    if xcnt *  ycnt - cnt:
        print(hm + wm)
    else:
        print(hm+wm-1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    H,W,M = LI()
    t = [LI() for _ in range(M)]

    hmax = [0] * (M+1)
    wmax = [0] * (M+1)

    for x,y in t:
        hmax[x] += 1
        wmax[y] += 1

    ans = 0
    for x,y in t:
        ans = max(ans,hmax[x] + wmax[y] - 1)

    hm = max(hmax)
    wm = max(wmax)

    for i in range(H):
        if hmax[i] == hm:
            for j in range(W):
                if wmax[j] == wm:
                    if [i,j] not in t:
                        print(hm+wm)
                        return
    print(hm+wm-1)


if __name__ == '__main__':
    main()