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

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

H_count = collections.defaultdict(int)
W_count = collections.defaultdict(int)
points = set()
for m in range(M):
    h, w = map(int, input().split())
    H_count[h] += 1
    W_count[w] += 1
    points.add((h, w))

H_count_sort = sorted(H_count.items(), key=lambda x: x[1])
W_count_sort = sorted(W_count.items(), key=lambda x: x[1])

max_count = 0
for h_count in reversed(H_count_sort):
    for w_count in reversed(W_count_sort):
        count = h_count[1] + w_count[1]
        if (h_count[0], w_count[0]) in points:
            count -= 1

        if max_count > count:
            break
        max_count = max(max_count, count)

print(max_count)

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

cnt_h = [0] * (H + 1)
cnt_w = [0] * (W + 1)
points = set()
for m in range(M):
    h, w = map(int, input().split())
    cnt_h[h] += 1
    cnt_w[w] += 1
    points.add((h, w))

H_max = max(cnt_h)
W_max = max(cnt_w)

H_max_num = [i for i, cnt in enumerate(cnt_h) if cnt == H_max]
W_max_num = [i for i, cnt in enumerate(cnt_w) if cnt == W_max]

flag = 0
for h_num in H_max_num:
    for w_num in W_max_num:
        if (h_num, w_num) not in points:
            print(H_max + W_max)
            exit()

print(H_max + W_max -1)

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

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

H_count = collections.defaultdict(int)
W_count = collections.defaultdict(int)
points = set()
for m in range(M):
    h, w = map(int, input().split())
    H_count[h] += 1
    W_count[w] += 1
    points.add((h, w))

max_count = 0

for h, h_count in H_count.items():
    for w, w_count in W_count.items():
        count = h_count + w_count
        if (h, w) in points:
            count -= 1
        max_count = max(max_count, count)

print(max_count)

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

cnt_h = [0] * (H + 1)
cnt_w = [0] * (W + 1)
points = set()
for m in range(M):
    h, w = map(int, input().split())
    cnt_h[h] += 1
    cnt_w[w] += 1
    points.add((h, w))

H_max = max(cnt_h)
W_max = max(cnt_w)

H_max_num = [i for i, cnt in enumerate(cnt_h) if cnt == H_max]
W_max_num = [i for i, cnt in enumerate(cnt_w) if cnt == W_max]

flag = 0
for h_num in H_max_num:
    for w_num in W_max_num:
        if (h_num, w_num) not in points:
            print(H_max + W_max)
            exit()

print(H_max + W_max -1)

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

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

H_count = collections.defaultdict(int)
W_count = collections.defaultdict(int)
points = []
for m in range(M):
    h, w = map(int, input().split())
    H_count[h] += 1
    W_count[w] += 1
    points.append((h, w))

max_count = 0

for h, h_count in H_count.items():
    for w, w_count in W_count.items():
        count = h_count + w_count
        if (h, w) in points:
            count -= 1
        max_count = max(max_count, count)

print(max_count)

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

cnt_h = [0] * (H + 1)
cnt_w = [0] * (W + 1)
points = set()
for m in range(M):
    h, w = map(int, input().split())
    cnt_h[h] += 1
    cnt_w[w] += 1
    points.add((h, w))

H_max = max(cnt_h)
W_max = max(cnt_w)

H_max_num = [i for i, cnt in enumerate(cnt_h) if cnt == H_max]
W_max_num = [i for i, cnt in enumerate(cnt_w) if cnt == W_max]

flag = 0
for h_num in H_max_num:
    for w_num in W_max_num:
        if (h_num, w_num) not in points:
            print(H_max + W_max)
            exit()

print(H_max + W_max -1)

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

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

H_count = collections.defaultdict(set)
W_count = collections.defaultdict(set)
for m in range(M):
    h, w = map(int, input().split())
    H_count[h].add(w)
    W_count[w].add(h)

max_count = 0

for h, w_list in H_count.items():
    for w, h_list in W_count.items():
        count = len(w_list) + len(h_list)
        if w in w_list or h in h_list:
            count -= 1
        max_count = max(max_count, count)

print(max_count)

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

cnt_h = [0] * (H + 1)
cnt_w = [0] * (W + 1)
points = set()
for m in range(M):
    h, w = map(int, input().split())
    cnt_h[h] += 1
    cnt_w[w] += 1
    points.add((h, w))

H_max = max(cnt_h)
W_max = max(cnt_w)

H_max_num = [i for i, cnt in enumerate(cnt_h) if cnt == H_max]
W_max_num = [i for i, cnt in enumerate(cnt_w) if cnt == W_max]

flag = 0
for h_num in H_max_num:
    for w_num in W_max_num:
        if (h_num, w_num) not in points:
            print(H_max + W_max)
            exit()

print(H_max + W_max -1)