Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())

h = [-1]
w = [-1]
hw = [[0 for _ in range(W + 1)]for _ in range(H + 1)]

for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw[hi][wi] = 1

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []

for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)

for i in h_max_idx:
    for j in w_max_idx:
        if hw[i][j] == 0:
            print(h_max + w_max)
            exit()

print(h_max + w_max - 1)


Fixed submission:
from collections import defaultdict


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)


# print(h_max_idx)
# print(w_max_idx)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
            ans = max(ans, tmp)
        else:
            ans = tmp
            break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())

h = [-1]
w = [-1]
hw = [[0 for _ in range(W + 1)]for _ in range(H + 1)]

for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw[hi][wi] = 1

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []

for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)

for i in h_max_idx:
    for j in w_max_idx:
        if hw[i][j] == 0:
            print(h_max + w_max)
            exit()

print(h_max + w_max - 1)


Fixed submission:
from collections import defaultdict


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)


# print(h_max_idx)
# print(w_max_idx)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
            ans = max(ans, tmp)
        else:
            ans = tmp
            break

print(ans)

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


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)

# print(h_max_idx)
# print(w_max_idx)

# if len(h_max_idx)>=10**2:
#     h_max_idx = h_max_idx[:10**2]
# if len(w_max_idx)>=10**2:
#     w_max_idx = w_max_idx[:10**2]

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
        ans = max(ans, tmp)
print(ans)


Fixed submission:
from collections import defaultdict


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)


# print(h_max_idx)
# print(w_max_idx)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
            ans = max(ans, tmp)
        else:
            ans = tmp
            break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int,input().split())

h = [-1]
w = [-1]
hw = []
for _ in range(M):
    hi,wi = map(int,input().split())
    h.append(hi)
    w.append(wi)
    hw.append([hi,wi])
# print(h)
# print(w)
# print(hw)
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
for i in range(1,M+1):
    h_cnt[h[i]]+=1
    w_cnt[w[i]]+=1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []

if len(h_max_idx)>=10**3:
    h_max_idx = h_max_idx[:10**3]
if len(w_max_idx)>=10**3:
    w_max_idx = w_max_idx[:10**3]

for i in range(1,H+1):
    if h_cnt[i]==h_max:
        h_max_idx.append(i)

for i in range(1,W+1):
    if w_cnt[i]==w_max:
        w_max_idx.append(i)

# print(h_max_idx)
# print(w_max_idx)

if len(h_max_idx)>=10**3:
    h_max_idx = h_max_idx[:10**3]
if len(w_max_idx)>=10**3:
    w_max_idx = w_max_idx[:10**3]

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp =  h_cnt[i]+w_cnt[j]
        if [i,j] in hw:
            tmp -=1
        ans = max(ans,tmp)
print(ans)


Fixed submission:
from collections import defaultdict


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)


# print(h_max_idx)
# print(w_max_idx)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
            ans = max(ans, tmp)
        else:
            ans = tmp
            break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int,input().split())

h = [-1]
w = [-1]
hw = []
for _ in range(M):
    hi,wi = map(int,input().split())
    h.append(hi)
    w.append(wi)
    hw.append([hi,wi])
# print(h)
# print(w)
# print(hw)
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
for i in range(1,M+1):
    h_cnt[h[i]]+=1
    w_cnt[w[i]]+=1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []

for i in range(1,H+1):
    if h_cnt[i]==h_max:
        h_max_idx.append(i)

for i in range(1,W+1):
    if w_cnt[i]==w_max:
        w_max_idx.append(i)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp =  h_cnt[i]+w_cnt[j]
        if [i,j] in hw:
            tmp -=1
        ans = max(ans,tmp)
print(ans)


Fixed submission:
from collections import defaultdict


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)


# print(h_max_idx)
# print(w_max_idx)

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
            ans = max(ans, tmp)
        else:
            ans = tmp
            break

print(ans)