Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

H, W, m = map(int, input().split())

hor = [0] * H
ver = [0] * W
f = [[0 for _ in range(W)] for _ in range(H)]
for _ in range(m):
    h, w = map(int, input().split())
    hor[h - 1] += 1
    ver[w - 1] += 1
    f[h - 1][w - 1] = 1

hs = []
hmax = max(hor)
for i, v in enumerate(hor):
    if hmax == v:
        hs.append(i)
vs = []
vmax = max(ver)
for i, v in enumerate(ver):
    if vmax == v:
        vs.append(i)

ans = hmax + vmax

if len(hs) * len(vs) > m:
    print(ans)
    exit()

for k1 in hs:
    for k2 in vs:
        if f[k1][k2] == 0:
            print(ans)
            exit()
print(ans - 1)


Fixed submission:
import sys
from collections import defaultdict

input = sys.stdin.readline

H, W, m = map(int, input().split())

hor = [0] * H
ver = [0] * W
f = defaultdict(int)
for _ in range(m):
    h, w = map(int, input().split())
    hor[h - 1] += 1
    ver[w - 1] += 1
    f[str(h - 1) + '|' + str(w - 1)] = 1

hmax = max(hor)
hs = [i for i, v in enumerate(hor) if v == hmax]
vmax = max(ver)
vs = [i for i, v in enumerate(ver) if v == vmax]


ans = hmax + vmax

if len(hs) * len(vs) > m:
    print(ans)
    exit()

for k1 in hs:
    for k2 in vs:
        if f[str(k1) + '|' + str(k2)] == 0:
            print(ans)
            exit()
print(ans - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

H, W, m = map(int, input().split())

hor = [0] * H
ver = [0] * W
f = [[0 for _ in range(W)] for _ in range(H)]
for _ in range(m):
    h, w = map(int, input().split())
    hor[h - 1] += 1
    ver[w - 1] += 1
    f[h - 1][w - 1] = 1

hs = []
hmax = max(hor)
for i, v in enumerate(hor):
    if hmax == v:
        hs.append(i)
vs = []
vmax = max(ver)
for i, v in enumerate(ver):
    if vmax == v:
        vs.append(i)

ans = hmax + vmax
for k1 in hs:
    for k2 in vs:
        if f[k1][k2] == 0:
            print(ans)
            exit()
print(ans - 1)


Fixed submission:
import sys
from collections import defaultdict

input = sys.stdin.readline

H, W, m = map(int, input().split())

hor = [0] * H
ver = [0] * W
f = defaultdict(int)
for _ in range(m):
    h, w = map(int, input().split())
    hor[h - 1] += 1
    ver[w - 1] += 1
    f[str(h - 1) + '|' + str(w - 1)] = 1

hmax = max(hor)
hs = [i for i, v in enumerate(hor) if v == hmax]
vmax = max(ver)
vs = [i for i, v in enumerate(ver) if v == vmax]


ans = hmax + vmax

if len(hs) * len(vs) > m:
    print(ans)
    exit()

for k1 in hs:
    for k2 in vs:
        if f[str(k1) + '|' + str(k2)] == 0:
            print(ans)
            exit()
print(ans - 1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
input = sys.stdin.readline

H, W, m = map(int, input().split())

hor = defaultdict(int)
ver = defaultdict(int)
f = [[0 for _ in range(W)] for _ in range(H)]
for _ in range(m):
    h, w = map(int, input().split())
    hor[h - 1] += 1
    ver[w - 1] += 1
    f[h - 1][w - 1] = 1

hs = []
hmax = max(hor.values())
for k, v in hor.items():
    if hmax == v:
        hs.append(k)
vs = []
vmax = max(ver.values())
for k, v in ver.items():
    if vmax == v:
        vs.append(k)

ans = hmax + vmax
i = 0
for k1 in hs:
    for k2 in vs:
        if f[k1][k2] == 0:
            print(ans)
            exit()
print(ans - 1)


Fixed submission:
import sys
from collections import defaultdict

input = sys.stdin.readline

H, W, m = map(int, input().split())

hor = [0] * H
ver = [0] * W
f = defaultdict(int)
for _ in range(m):
    h, w = map(int, input().split())
    hor[h - 1] += 1
    ver[w - 1] += 1
    f[str(h - 1) + '|' + str(w - 1)] = 1

hmax = max(hor)
hs = [i for i, v in enumerate(hor) if v == hmax]
vmax = max(ver)
vs = [i for i, v in enumerate(ver) if v == vmax]


ans = hmax + vmax

if len(hs) * len(vs) > m:
    print(ans)
    exit()

for k1 in hs:
    for k2 in vs:
        if f[str(k1) + '|' + str(k2)] == 0:
            print(ans)
            exit()
print(ans - 1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

H, W, m = map(int, input().split())

hor = defaultdict(int)
ver = defaultdict(int)
f = [[0 for _ in range(W)] for _ in range(H)]
for _ in range(m):
    h, w = map(int, input().split())
    hor[h - 1] += 1
    ver[w - 1] += 1
    f[h - 1][w - 1] = 1

hor = sorted(hor.items(), key=lambda x:-x[1])
ver = sorted(ver.items(), key=lambda x:-x[1])

ans = hor[0][1] + ver[0][1]
i = 0
while i < len(hor) and hor[i][1] == hor[0][1]:
    j = 0
    while j < len(ver) and ver[j][1] == ver[0][1]:
        if f[hor[i][0]][ver[j][0]] == 0:
            print(ans)
            exit()
        j += 1
    i += 1
print(ans - 1)


Fixed submission:
import sys
from collections import defaultdict

input = sys.stdin.readline

H, W, m = map(int, input().split())

hor = [0] * H
ver = [0] * W
f = defaultdict(int)
for _ in range(m):
    h, w = map(int, input().split())
    hor[h - 1] += 1
    ver[w - 1] += 1
    f[str(h - 1) + '|' + str(w - 1)] = 1

hmax = max(hor)
hs = [i for i, v in enumerate(hor) if v == hmax]
vmax = max(ver)
vs = [i for i, v in enumerate(ver) if v == vmax]


ans = hmax + vmax

if len(hs) * len(vs) > m:
    print(ans)
    exit()

for k1 in hs:
    for k2 in vs:
        if f[str(k1) + '|' + str(k2)] == 0:
            print(ans)
            exit()
print(ans - 1)