Problem p02580 (python)

Fixed submission:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    ay = [0]*h
    ax = [0]*w
    for x in s:
        ay[x[0]] += 1
        ax[x[1]] += 1

    my = max(ay)
    mx = max(ax)
    
    by = bx = 0
    for y in ay:
        if y == my:
            by += 1
    for x in ax:
        if x == mx:
            bx += 1
            
    ans = my + mx
    tmp = 0
    for x in s:
        if ay[x[0]]+ax[x[1]]==ans:
            tmp += 1
    if tmp == by*bx:
        ans -= 1
    print(ans)
    
if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    ay = [0]*h
    ax = [0]*w
    c = [[0]*w for i in range(h)]
    for x in s:
        ay[x[0]] += 1
        ax[x[1]] += 1
        c[x[0]][x[1]] = 1

    my = max(ay)
    mx = max(ax)
    
    by = bx = 0
    for y in ay:
        if y == my:
            by += 1
    for x in ax:
        if x == mx:
            bx += 1
            
    ans = my + mx
    tmp = 0
    for x in s:
        if ay[x[0]]+ax[x[1]]==ans:
            tmp += c[x[0]][x[1]]
    if tmp == by*bx:
        ans -= 1
    print(ans)
    
if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    ay = [0]*h
    ax = [0]*w
    c = [[0]*w for i in range(h)]
    for x in s:
        ay[x[0]] += 1
        ax[x[1]] += 1
        c[x[0]][x[1]] = 1

    my = max(ay)
    mx = max(ax)
    
    by = bx = 0
    for y in ay:
        if y == my:
            by += 1
    for x in ax:
        if x == mx:
            bx += 1
            
    ans = my + mx
    tmp = 0
    for x in s:
        if ay[x[0]]+ax[x[1]]==ans:
            tmp += c[x[0]][x[1]]
    if tmp == by*bx:
        ans -= 1
    print(ans)
    
if __name__ == '__main__':
    solve()

Buggy submission (verdict: Runtime Error):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    h, w, m = MAP()
    s = [LIST1() for i in range(m)]
    ay = [0]*h
    ax = [0]*w
    c = [[0]*w for i in range(h)]
    for x in s:
        ay[x[0]] += 1
        ax[x[1]] += 1
        c[x[0]][x[1]] = 1

    my = max(ay)
    mx = max(ax)
    by = [i for i, x in enumerate(ay) if x == my]
    bx = [i for i, x in enumerate(ax) if x == mx]

    ans = my + mx
    tmp = 1
    if len(by)*len(bx) > m:
        tmp = 0
    else:
        for y in by:
            for x in bx:
                if c[y][x] == 0:
                    tmp = 0
                    break
            else:
                continue
            break
    print(ans - tmp)

if __name__ == '__main__':
    solve()