Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

H, W, M = map(int, input().split())
h_count = [[i, 0] for i in range(H)]
w_count = [[i, 0] for i in range(W)]
exist = dict()
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    h_count[h][1] += 1
    w_count[w][1] += 1
    exist[(h, w)] = True

h_count.sort(key=itemgetter(1), reverse=True)
w_count.sort(key=itemgetter(1), reverse=True)
h_max = h_count[0][1]
w_max = w_count[0][1]
res = 0
is_dup = True
for h in h_count:
    if h[1] != h_max and is_dup:
        break
    for w in w_count:
        if w[1] != w_max and is_dup:
            break
        val = h[1] + w[1]
        if exist.get((h[0], w[0]), False):
            val -= 1
        else:
            is_dup = False
        res = max(res, val)
print(res)


Fixed submission:
from operator import itemgetter

H, W, M = map(int, input().split())
h_count = [[i, 0] for i in range(H)]
w_count = [[i, 0] for i in range(W)]
exist = dict()
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    h_count[h][1] += 1
    w_count[w][1] += 1
    exist[(h, w)] = True

h_count.sort(key=itemgetter(1), reverse=True)
w_count.sort(key=itemgetter(1), reverse=True)
h_max = h_count[0][1]
w_max = w_count[0][1]
res = 0
is_dup = True
for h in h_count:
    if h[1] != h_max or not is_dup:
        break
    for w in w_count:
        if w[1] != w_max or not is_dup:
            break
        val = h[1] + w[1]
        if exist.get((h[0], w[0]), False):
            val -= 1
        else:
            is_dup = False
        res = max(res, val)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

H, W, M = map(int, input().split())
h_count = [[i, 0] for i in range(H)]
w_count = [[i, 0] for i in range(W)]
exist = dict()
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    h_count[h][1] += 1
    w_count[w][1] += 1
    exist[(h, w)] = 1

h_count.sort(key=itemgetter(1), reverse=True)
w_count.sort(key=itemgetter(1), reverse=True)
h_max = h_count[0][1]
w_max = w_count[0][1]
res = 0
for h in h_count:
    if h[1] != h_max:
        break
    for w in w_count:
        if w[1] != w_max:
            break
        val = h[1] + w[1]
        if exist.get((h[0], w[0]), 0):
            val -= 1
        res = max(res, val)
print(res)


Fixed submission:
from operator import itemgetter

H, W, M = map(int, input().split())
h_count = [[i, 0] for i in range(H)]
w_count = [[i, 0] for i in range(W)]
exist = dict()
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    h_count[h][1] += 1
    w_count[w][1] += 1
    exist[(h, w)] = True

h_count.sort(key=itemgetter(1), reverse=True)
w_count.sort(key=itemgetter(1), reverse=True)
h_max = h_count[0][1]
w_max = w_count[0][1]
res = 0
is_dup = True
for h in h_count:
    if h[1] != h_max or not is_dup:
        break
    for w in w_count:
        if w[1] != w_max or not is_dup:
            break
        val = h[1] + w[1]
        if exist.get((h[0], w[0]), False):
            val -= 1
        else:
            is_dup = False
        res = max(res, val)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

H, W, M = map(int, input().split())
h_count = [[i, 0] for i in range(H)]
w_count = [[i, 0] for i in range(W)]
exist = dict()
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    h_count[h][1] += 1
    w_count[w][1] += 1
    exist[(h, w)] = 1

h_count.sort(key=itemgetter(1), reverse=True)
w_count.sort(key=itemgetter(1), reverse=True)
h_max = h_count[0][1]
w_max = w_count[0][1]
res = 0
for h in h_count:
    if h[1] != h_max:
        break
    for w in w_count:
        if w[1] != w_max:
            break
        val = h[1] + w[1]
        if exist.get((h[0], w[0]), 0):
            val -= 1
        res = max(res, val)
print(res)


Fixed submission:
from operator import itemgetter

H, W, M = map(int, input().split())
h_count = [[i, 0] for i in range(H)]
w_count = [[i, 0] for i in range(W)]
exist = dict()
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    h_count[h][1] += 1
    w_count[w][1] += 1
    exist[(h, w)] = True

h_count.sort(key=itemgetter(1), reverse=True)
w_count.sort(key=itemgetter(1), reverse=True)
h_max = h_count[0][1]
w_max = w_count[0][1]
res = 0
is_dup = True
for h in h_count:
    if h[1] != h_max or not is_dup:
        break
    for w in w_count:
        if w[1] != w_max or not is_dup:
            break
        val = h[1] + w[1]
        if exist.get((h[0], w[0]), False):
            val -= 1
        else:
            is_dup = False
        res = max(res, val)
print(res)