Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
nh = [0 for i in range(h)]
nw = [0 for j in range(w)]
bomb = [[] for i in range(h)]
for i in range(m):
    inp = list(map(int, input().split()))
    nh[inp[0] - 1] += 1
    nw[inp[1] - 1] += 1
    bomb[inp[0]-1].append(inp[1]-1)
maxh = max(nh)
maxw = max(nw)
counth = 0
countw = 0
hlis = []
wlis = []
for j in range(h):
    if nh[j] == maxh:
        counth += 1
        hlis.append(j)
for i in range(w):
    if nw[i] == maxw:
        countw += 1
        wlis.append(i)
if counth * countw > m:
    print(maxh + maxw)
    exit()
else:
    for j in hlis:
        for i in wlis:
            flag = False
            if i in bomb[j]:
                flag = True
            if not flag:
                print(maxh + maxw)
                exit()
    else:
        print(maxh + maxw - 1)

Fixed submission:
h, w, m = map(int, input().split())
nh = [0 for i in range(h)]
nw = [0 for j in range(w)]
bomb = [set() for i in range(h)]
for i in range(m):
    inp = list(map(int, input().split()))
    nh[inp[0] - 1] += 1
    nw[inp[1] - 1] += 1
    bomb[inp[0]-1].add(inp[1]-1)
maxh = max(nh)
maxw = max(nw)
counth = 0
countw = 0
hlis = []
wlis = []
for j in range(h):
    if nh[j] == maxh:
        counth += 1
        hlis.append(j)
for i in range(w):
    if nw[i] == maxw:
        countw += 1
        wlis.append(i)
if counth * countw > m:
    print(maxh + maxw)
    exit()
else:
    for j in hlis:
        for i in wlis:
            flag = False
            if i in bomb[j]:
                flag = True
            if not flag:
                print(maxh + maxw)
                exit()
    else:
        print(maxh + maxw - 1)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
nh = [0 for i in range(h)]
nw = [0 for j in range(w)]
bomb = []
for i in range(m):
    inp = list(map(int, input().split()))
    nh[inp[0] - 1] += 1
    nw[inp[1] - 1] += 1
    bomb.append([inp[0]-1, inp[1] - 1])
maxh = max(nh)
maxw = max(nw)
counth = 0
countw = 0
hlis = []
wlis = []
for j in range(h):
    if nh[j] == maxh:
        counth += 1
        hlis.append(j)
for i in range(w):
    if nw[i] == maxw:
        countw += 1
        wlis.append(i)
if counth * countw > m:
    print(maxh + maxw)
    exit()
else:
    for j in hlis:
        for i in wlis:
            flag = False
            for k in range(len(bomb)):
                if bomb[k] == [j, i]:
                    flag = True
            if not flag:
                print(maxh + maxw)
                exit()
    else:
        print(maxh + maxw - 1)

Fixed submission:
h, w, m = map(int, input().split())
nh = [0 for i in range(h)]
nw = [0 for j in range(w)]
bomb = [set() for i in range(h)]
for i in range(m):
    inp = list(map(int, input().split()))
    nh[inp[0] - 1] += 1
    nw[inp[1] - 1] += 1
    bomb[inp[0]-1].add(inp[1]-1)
maxh = max(nh)
maxw = max(nw)
counth = 0
countw = 0
hlis = []
wlis = []
for j in range(h):
    if nh[j] == maxh:
        counth += 1
        hlis.append(j)
for i in range(w):
    if nw[i] == maxw:
        countw += 1
        wlis.append(i)
if counth * countw > m:
    print(maxh + maxw)
    exit()
else:
    for j in hlis:
        for i in wlis:
            flag = False
            if i in bomb[j]:
                flag = True
            if not flag:
                print(maxh + maxw)
                exit()
    else:
        print(maxh + maxw - 1)