Buggy python submission (verdict: Time Limit Exceeded):
import itertools

h, w, m = map(int,input().split())

h_dict = dict()
w_dict = dict()

targets = [None] * (3 * 10 ** 5)

for i in range(m):
    temp_h, temp_w, = map(int,input().split())

    h_dict[temp_h] = h_dict.get(temp_h, default=0) + 1
    w_dict[temp_w] = w_dict.get(temp_w, default=0) + 1

    targets[i] = (temp_h, temp_w)

max_h = max(h_dict.values())
max_w = max(w_dict.values())

h_candidates = [k for k, v in h_dict.items() if v == max_h]
w_candidates = [k for k, v in w_dict.items() if v == max_w]

for temp_h, temp_w in itertools.product(h_candidates, w_candidates):
    if not ((temp_h, temp_w) in targets):
        print(h_dict[temp_h] + w_dict[temp_w])
        break
else:
    print(h_dict[temp_h] + w_dict[temp_w] - 1)

Fixed submission:
h, w, m = map(int,input().split())

h_dict = dict()
w_dict = dict()

targets = list()

for i in range(m):
    temp_h, temp_w, = map(int,input().split())

    h_dict[temp_h] = h_dict.get(temp_h, default=0) + 1
    w_dict[temp_w] = w_dict.get(temp_w, default=0) + 1

    targets.append((temp_h, temp_w))

h_dict_values = list(h_dict.values())
w_dict_values = list(w_dict.values())

max_h = max(h_dict_values)
max_w = max(w_dict_values)

nh = h_dict_values.count(max_h)
nw = w_dict_values.count(max_w)

x = 0

for i in range(m):
    temp_h, temp_w = targets[i]
    if h_dict[temp_h]==max_h and w_dict[temp_w]==max_w:
        x += 1

ans = max_h + max_w

if x == nh * nw:
    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

h, w, m = map(int,input().split())

h_dict = dict()
w_dict = dict()

targets = list()

for _ in range(m):
    temp_h, temp_w, = map(int,input().split())

    h_dict[temp_h] = h_dict.get(temp_h, default=0) + 1
    w_dict[temp_w] = w_dict.get(temp_w, default=0) + 1

    targets.append((temp_h, temp_w))

max_h = max(h_dict.values())
max_w = max(w_dict.values())

h_candidates = [k for k, v in h_dict.items() if v == max_h]
w_candidates = [k for k, v in w_dict.items() if v == max_w]

for temp_h, temp_w in itertools.product(h_candidates, w_candidates):
    if not ((temp_h, temp_w) in targets):
        print(h_dict[temp_h] + w_dict[temp_w])
        break
else:
    print(h_dict[temp_h] + w_dict[temp_w] - 1)

Fixed submission:
h, w, m = map(int,input().split())

h_dict = dict()
w_dict = dict()

targets = list()

for i in range(m):
    temp_h, temp_w, = map(int,input().split())

    h_dict[temp_h] = h_dict.get(temp_h, default=0) + 1
    w_dict[temp_w] = w_dict.get(temp_w, default=0) + 1

    targets.append((temp_h, temp_w))

h_dict_values = list(h_dict.values())
w_dict_values = list(w_dict.values())

max_h = max(h_dict_values)
max_w = max(w_dict_values)

nh = h_dict_values.count(max_h)
nw = w_dict_values.count(max_w)

x = 0

for i in range(m):
    temp_h, temp_w = targets[i]
    if h_dict[temp_h]==max_h and w_dict[temp_w]==max_w:
        x += 1

ans = max_h + max_w

if x == nh * nw:
    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections, itertools

h, w, m = map(int,input().split())

h_list = list()
w_list = list()

targets = list()

for _ in range(m):
    temp_h, temp_w, = map(int,input().split())

    h_list.append(temp_h)
    w_list.append(temp_w)

    targets.append((temp_h, temp_w))

num_dict_h = dict(collections.Counter(h_list))
num_dict_w = dict(collections.Counter(w_list))

h_candidates = [k for k, v in num_dict_h.items() if v == max(num_dict_h.values())]
w_candidates = [k for k, v in num_dict_w.items() if v == max(num_dict_w.values())]

for temp_h, temp_w in itertools.product(h_candidates, w_candidates):
    if not ((temp_h, temp_w) in targets):
        print(num_dict_h[temp_h] + num_dict_w[temp_w])
        break
else:
    print(num_dict_h[temp_h] + num_dict_w[temp_w] - 1)

Fixed submission:
h, w, m = map(int,input().split())

h_dict = dict()
w_dict = dict()

targets = list()

for i in range(m):
    temp_h, temp_w, = map(int,input().split())

    h_dict[temp_h] = h_dict.get(temp_h, default=0) + 1
    w_dict[temp_w] = w_dict.get(temp_w, default=0) + 1

    targets.append((temp_h, temp_w))

h_dict_values = list(h_dict.values())
w_dict_values = list(w_dict.values())

max_h = max(h_dict_values)
max_w = max(w_dict_values)

nh = h_dict_values.count(max_h)
nw = w_dict_values.count(max_w)

x = 0

for i in range(m):
    temp_h, temp_w = targets[i]
    if h_dict[temp_h]==max_h and w_dict[temp_w]==max_w:
        x += 1

ans = max_h + max_w

if x == nh * nw:
    ans -= 1

print(ans)