Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

tmp = 0
for i in range(M):
    if (DST[0][i] in Hbomb) and (DST[1][i] in Wbomb):
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)


Fixed submission:
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

Hchk = [False]*H
Wchk = [False]*W
for i in Hbomb:
    Hchk[i] = True
for i in Wbomb:
    Wchk[i] = True

tmp = 0
for i in range(M):
    if Hchk[DST[0][i]] and Wchk[DST[1][i]]:
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * 2 for i in range(M)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[i] = [hi-1, wi-1]

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

tmp = M
for i in range(M):
    if (DST[i][0] not in Hbomb) or (DST[i][1] not in Wbomb):
        tmp -= 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)


Fixed submission:
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

Hchk = [False]*H
Wchk = [False]*W
for i in Hbomb:
    Hchk[i] = True
for i in Wbomb:
    Wchk[i] = True

tmp = 0
for i in range(M):
    if Hchk[DST[0][i]] and Wchk[DST[1][i]]:
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * 2 for i in range(M)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[i] = [hi-1, wi-1]

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

tmp = M
for i in range(M):
    if (DST[i][0] not in Hbomb) or (DST[i][1] not in Wbomb):
        tmp -= 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)


Fixed submission:
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

Hchk = [False]*H
Wchk = [False]*W
for i in Hbomb:
    Hchk[i] = True
for i in Wbomb:
    Wchk[i] = True

tmp = 0
for i in range(M):
    if Hchk[DST[0][i]] and Wchk[DST[1][i]]:
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * 2 for i in range(M)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[i] = [hi-1, wi-1]

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

ans = Hdstmax + Wdstmax - 1
for i in Hbomb:
    for j in Wbomb:
        if [i, j] not in DST:
            ans = Hdstmax + Wdstmax
            break
    if ans == Hdstmax + Wdstmax:
        break

print(ans)

Fixed submission:
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

Hchk = [False]*H
Wchk = [False]*W
for i in Hbomb:
    Hchk[i] = True
for i in Wbomb:
    Wchk[i] = True

tmp = 0
for i in range(M):
    if Hchk[DST[0][i]] and Wchk[DST[1][i]]:
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * 2 for i in range(M)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[i] = [hi-1, wi-1]

Hbomb = [i for i, x in enumerate(Hdst) if x == max(Hdst)]
Wbomb = [i for i, x in enumerate(Wdst) if x == max(Wdst)]

ans = 0
for i in Hbomb:
    for j in Wbomb:
        tmp = Hdst[i] + Wdst[j]
        if [i, j] in DST:
            tmp -= 1
        if tmp > ans:
            ans = tmp

print(ans)

Fixed submission:
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

Hchk = [False]*H
Wchk = [False]*W
for i in Hbomb:
    Hchk[i] = True
for i in Wbomb:
    Wchk[i] = True

tmp = 0
for i in range(M):
    if Hchk[DST[0][i]] and Wchk[DST[1][i]]:
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)

Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * W for i in range(H)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[hi-1][wi-1] = 1

Hbomb = [i for i, x in enumerate(Hdst) if x == max(Hdst)]
Wbomb = [i for i, x in enumerate(Wdst) if x == max(Wdst)]

ans = 0
for i in Hbomb:
    for j in Wbomb:
        if Hdst[i] + Wdst[j] - DST[i][j] > ans:
            ans = Hdst[i] + Wdst[j] - DST[i][j]

print(ans)

Fixed submission:
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

Hchk = [False]*H
Wchk = [False]*W
for i in Hbomb:
    Hchk[i] = True
for i in Wbomb:
    Wchk[i] = True

tmp = 0
for i in range(M):
    if Hchk[DST[0][i]] and Wchk[DST[1][i]]:
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)