Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_value = [0]*(H+1)
w_value = [0]*(W+1)
exist = [ [0 for _ in range(W+1)] for _ in range(H+1)]
for coordinate in hw:
    h_value[coordinate[0]] += 1
    w_value[coordinate[1]] += 1
    exist[coordinate[0]][coordinate[1]] = 1

h_max = max(h_value)
w_max = max(w_value)

h_max_ind = list()
w_max_ind = list()
h_max_ind_exist = [0]*(H+1)
w_max_ind_exist = [0]*(W+1)

for i in range(H+1):
    if h_value[i] == h_max:
        h_max_ind.append(i)
        h_max_ind_exist[i] = 1


for i in range(W+1):
    if w_value[i] == w_max:
        w_max_ind.append(i)
        w_max_ind_exist[i] = 1

# print("put", h_max_ind, w_max_ind)
flag = False
if len(h_max_ind)*len(w_max_ind) > M:
    flag = True
else:
    for h in h_max_ind:
        for w in w_max_ind:
            if exist[h][w] == 0:
                flag = True

if flag:
    print(h_max + w_max)
else:
    print(h_max + w_max - 1)



Fixed submission:
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]
hw_set = set()
for bomb in hw:
    hw_set.add((bomb[0], bomb[1]))
h_value = [0]*(H+1)
w_value = [0]*(W+1)
# exist = [ [0 for _ in range(W+1)] for _ in range(H+1)]

for coordinate in hw:
    h_value[coordinate[0]] += 1
    w_value[coordinate[1]] += 1
    

h_max = max(h_value)
w_max = max(w_value)

h_max_ind = list()
w_max_ind = list()
h_max_ind_num = 0
w_max_ind_num = 0

for i in range(H+1):
    if h_value[i] == h_max:
        h_max_ind.append(i)
        h_max_ind_num += 1


for i in range(W+1):
    if w_value[i] == w_max:
        w_max_ind.append(i)
        w_max_ind_num += 1

# print("put", h_max_ind, w_max_ind)
flag = False
if (h_max_ind_num * w_max_ind_num) > M:
    flag = True
else:
    for h in h_max_ind:
        for w in w_max_ind:
            if not (h, w) in hw_set:
                flag = True
                break

if flag:
    print(h_max + w_max)
else:
    print(h_max + w_max - 1)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_value = [0]*(H+1)
w_value = [0]*(W+1)
exist = [ [0 for _ in range(W+1)] for _ in range(H+1)]
for coordinate in hw:
    h_value[coordinate[0]] += 1
    w_value[coordinate[1]] += 1
    exist[coordinate[0]][coordinate[1]] = 1

h_max = max(h_value)
w_max = max(w_value)

h_max_ind = list()
w_max_ind = list()

for i in range(H+1):
    if h_value[i] == h_max:
        h_max_ind.append(i)


for i in range(W+1):
    if w_value[i] == w_max:
        w_max_ind.append(i)

flag = False
for h in h_max_ind:
    for w in w_max_ind:
        if exist[h][w] == 0:
            flag = True

if flag:
    print(h_max + w_max)
else:
    print(h_max + w_max - 1)



Fixed submission:
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]
hw_set = set()
for bomb in hw:
    hw_set.add((bomb[0], bomb[1]))
h_value = [0]*(H+1)
w_value = [0]*(W+1)
# exist = [ [0 for _ in range(W+1)] for _ in range(H+1)]

for coordinate in hw:
    h_value[coordinate[0]] += 1
    w_value[coordinate[1]] += 1
    

h_max = max(h_value)
w_max = max(w_value)

h_max_ind = list()
w_max_ind = list()
h_max_ind_num = 0
w_max_ind_num = 0

for i in range(H+1):
    if h_value[i] == h_max:
        h_max_ind.append(i)
        h_max_ind_num += 1


for i in range(W+1):
    if w_value[i] == w_max:
        w_max_ind.append(i)
        w_max_ind_num += 1

# print("put", h_max_ind, w_max_ind)
flag = False
if (h_max_ind_num * w_max_ind_num) > M:
    flag = True
else:
    for h in h_max_ind:
        for w in w_max_ind:
            if not (h, w) in hw_set:
                flag = True
                break

if flag:
    print(h_max + w_max)
else:
    print(h_max + w_max - 1)