Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

H, W, M = map(int, input().split())
h = [] * M
w = [] * M
dic_combi = defaultdict(int)

for _ in range(M):
    h_, w_ = map(int, input().split())
    h.append(h_)
    w.append(w_)
    dic_combi[h_ * (10**6) +  w_]=1

dic_h = Counter(h)
dic_w = Counter(w)
# print(dic_h, dic_w)
max_h_key = max(dic_h.items(), key=lambda x:x[1])[0]
max_w_key = max(dic_w.items(), key=lambda x:x[1])[0]

max_h = dic_h[max_h_key]
max_w = dic_w[max_w_key]

keys_h = [k for k, v in dic_h.items() if v == max_h]
keys_w = [k for k, v in dic_w.items() if v == max_w]


def get_num(ind_h, ind_w):
    ret = 0
    for i in range(M):
        if h[i] == ind_h or w[i] == ind_w:
           ret += 1
    return ret


ans = 0
for ind_h in keys_h:
    for ind_w in keys_w:
        # ret = get_num(ind_h, ind_w)
        ret = max_h + max_w
        if dic_combi[ind_h*(10**6) + ind_w] == 1:
            ret -= 1
        ans = max(ans, ret)

print(ans)






Fixed submission:
# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

H, W, M = map(int, input().split())
h = [] * M
w = [] * M
dic_combi = defaultdict(int)

for _ in range(M):
    h_, w_ = map(int, input().split())
    h.append(h_)
    w.append(w_)
    dic_combi[h_ * (10**6) +  w_]=1

dic_h = Counter(h)
dic_w = Counter(w)
# print(dic_h, dic_w)
max_h_key = max(dic_h.items(), key=lambda x:x[1])[0]
max_w_key = max(dic_w.items(), key=lambda x:x[1])[0]

max_h = dic_h[max_h_key]
max_w = dic_w[max_w_key]

keys_h = [k for k, v in dic_h.items() if v == max_h]
keys_w = [k for k, v in dic_w.items() if v == max_w]


ans = 0
for ind_h in keys_h:
    for ind_w in keys_w:
        ret = max_h + max_w
        if dic_combi[ind_h*(10**6) + ind_w] == 1:
            ret -= 1
        else:
            print(ret)
            sys.exit()
        ans = max(ans, ret)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

H, W, M = map(int, input().split())
h = [] * M
w = [] * M

for _ in range(M):
    h_, w_ = map(int, input().split())
    h.append(h_)
    w.append(w_)

dic_h = Counter(h)
dic_w = Counter(w)

# print(dic_h, dic_w)
max_h_key = max(dic_h.items(), key=lambda x:x[1])[0]
max_w_key = max(dic_w.items(), key=lambda x:x[1])[0]

max_h = dic_h[max_h_key]
max_w = dic_w[max_w_key]
# print(max_h_key, max_w_key, max_h, max_w)

def get_num(ind_h, ind_w):
    ret = 0
    for i in range(M):
        if h[i] == ind_h or w[i] == ind_w:
           ret += 1
    return ret


ans = 0
for ind_h in dic_h.keys():
    if dic_h[ind_h] < max_h:
        continue
    for ind_w in dic_w.keys():
        if dic_w[ind_w] < max_w:
            continue
        ret = get_num(ind_h, ind_w)
        ans = max(ans, ret)

print(ans)






Fixed submission:
# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

H, W, M = map(int, input().split())
h = [] * M
w = [] * M
dic_combi = defaultdict(int)

for _ in range(M):
    h_, w_ = map(int, input().split())
    h.append(h_)
    w.append(w_)
    dic_combi[h_ * (10**6) +  w_]=1

dic_h = Counter(h)
dic_w = Counter(w)
# print(dic_h, dic_w)
max_h_key = max(dic_h.items(), key=lambda x:x[1])[0]
max_w_key = max(dic_w.items(), key=lambda x:x[1])[0]

max_h = dic_h[max_h_key]
max_w = dic_w[max_w_key]

keys_h = [k for k, v in dic_h.items() if v == max_h]
keys_w = [k for k, v in dic_w.items() if v == max_w]


ans = 0
for ind_h in keys_h:
    for ind_w in keys_w:
        ret = max_h + max_w
        if dic_combi[ind_h*(10**6) + ind_w] == 1:
            ret -= 1
        else:
            print(ret)
            sys.exit()
        ans = max(ans, ret)

print(ans)