Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
my_input = sys.stdin.readline

H, W, M = map(int, my_input().split())
targets = set()
h_targets = []
w_targets = []

for m in range(M):
    h, w = map(int, my_input().split())
    h, w = h - 1, w - 1
    targets.add((h, w))
    h_targets.append(h)
    w_targets.append(w)

h_counter = Counter(h_targets).most_common()
w_counter = Counter(w_targets).most_common()

h_keys = [k for k, v in h_counter]
w_keys = [k for k, v in w_counter]

ans = 0
highest = h_counter[0][1] + w_counter[0][1]
for hk, hv in h_counter:
    for wk, wv in w_counter:
        if hv + wv < highest:
            break
        ret = highest - ((hk, wk) in targets)
        ans = max(ans, ret)
print(ans)


Fixed submission:
import sys
from collections import Counter
from random import shuffle
my_input = sys.stdin.readline

H, W, M = map(int, my_input().split())
targets = set()
h_targets = []
w_targets = []

for m in range(M):
    h, w = map(int, my_input().split())
    h, w = h - 1, w - 1
    targets.add((h, w))
    h_targets.append(h)
    w_targets.append(w)

h_counter = Counter(h_targets).most_common()
w_counter = Counter(w_targets).most_common()

h_high = h_counter[0][1]
w_high = w_counter[0][1]

h_counter = [[k, v] for k, v in h_counter if v == h_high]
w_counter = [[k, v] for k, v in w_counter if v == w_high]
shuffle(h_counter)
shuffle(w_counter)

highest = h_high + w_high
for hk, hv in h_counter:
    for wk, wv in w_counter:
        if hv + wv < highest:
            break
        if ((hk, wk) not in targets):
            print(highest)
            exit()
print(highest - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
my_input = sys.stdin.readline

H, W, M = map(int, my_input().split())
targets = set()
h_targets = []
w_targets = []

for m in range(M):
    h, w = map(int, my_input().split())
    h, w = h - 1, w - 1
    targets.add((h, w))
    h_targets.append(h)
    w_targets.append(w)

h_counter = Counter(h_targets).most_common()
w_counter = Counter(w_targets).most_common()

h_keys = [k for k, v in h_counter]
w_keys = [k for k, v in w_counter]

ans = 0
highest = h_counter[0][1] + w_counter[0][1]
for hk, hv in h_counter:
    for wk, wv in w_counter:
        if hv + wv < highest:
            break
        ret = highest - ((hk, wk) in targets)
        ans = max(ans, ret)
print(ans)


Fixed submission:
import sys
from collections import Counter
from random import shuffle
my_input = sys.stdin.readline

H, W, M = map(int, my_input().split())
targets = set()
h_targets = []
w_targets = []

for m in range(M):
    h, w = map(int, my_input().split())
    h, w = h - 1, w - 1
    targets.add((h, w))
    h_targets.append(h)
    w_targets.append(w)

h_counter = Counter(h_targets).most_common()
w_counter = Counter(w_targets).most_common()

h_high = h_counter[0][1]
w_high = w_counter[0][1]

h_counter = [[k, v] for k, v in h_counter if v == h_high]
w_counter = [[k, v] for k, v in w_counter if v == w_high]
shuffle(h_counter)
shuffle(w_counter)

highest = h_high + w_high
for hk, hv in h_counter:
    for wk, wv in w_counter:
        if hv + wv < highest:
            break
        if ((hk, wk) not in targets):
            print(highest)
            exit()
print(highest - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
my_input = sys.stdin.readline

H, W, M = map(int, my_input().split())
targets = set()
h_targets = defaultdict(int)
w_targets = defaultdict(int)

for m in range(M):
    h, w = map(int, my_input().split())
    h, w = h - 1, w - 1
    targets.add((h, w))
    h_targets[h] += 1
    w_targets[w] += 1


ans = 0
for h in h_targets.keys():
    for w in w_targets.keys():
        ret = h_targets[h] + w_targets[w] - ((h, w) in targets)
        ans = max(ans, ret)
print(ans)


Fixed submission:
import sys
from collections import Counter
from random import shuffle
my_input = sys.stdin.readline

H, W, M = map(int, my_input().split())
targets = set()
h_targets = []
w_targets = []

for m in range(M):
    h, w = map(int, my_input().split())
    h, w = h - 1, w - 1
    targets.add((h, w))
    h_targets.append(h)
    w_targets.append(w)

h_counter = Counter(h_targets).most_common()
w_counter = Counter(w_targets).most_common()

h_high = h_counter[0][1]
w_high = w_counter[0][1]

h_counter = [[k, v] for k, v in h_counter if v == h_high]
w_counter = [[k, v] for k, v in w_counter if v == w_high]
shuffle(h_counter)
shuffle(w_counter)

highest = h_high + w_high
for hk, hv in h_counter:
    for wk, wv in w_counter:
        if hv + wv < highest:
            break
        if ((hk, wk) not in targets):
            print(highest)
            exit()
print(highest - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
my_input = sys.stdin.readline

H, W, M = map(int, my_input().split())
targets = defaultdict(int)
h_targets = defaultdict(int)
w_targets = defaultdict(int)

for m in range(M):
    h, w = map(int, my_input().split())
    h, w = h - 1, w - 1
    targets[(h, w)] += 1
    h_targets[h] += 1
    w_targets[w] += 1


ans = 0
for h in range(H):
    for w in range(W):
        ret = h_targets[h] + w_targets[w] - targets[(h, w)]
        ans = max(ans, ret)
print(ans)


Fixed submission:
import sys
from collections import Counter
from random import shuffle
my_input = sys.stdin.readline

H, W, M = map(int, my_input().split())
targets = set()
h_targets = []
w_targets = []

for m in range(M):
    h, w = map(int, my_input().split())
    h, w = h - 1, w - 1
    targets.add((h, w))
    h_targets.append(h)
    w_targets.append(w)

h_counter = Counter(h_targets).most_common()
w_counter = Counter(w_targets).most_common()

h_high = h_counter[0][1]
w_high = w_counter[0][1]

h_counter = [[k, v] for k, v in h_counter if v == h_high]
w_counter = [[k, v] for k, v in w_counter if v == w_high]
shuffle(h_counter)
shuffle(w_counter)

highest = h_high + w_high
for hk, hv in h_counter:
    for wk, wv in w_counter:
        if hv + wv < highest:
            break
        if ((hk, wk) not in targets):
            print(highest)
            exit()
print(highest - 1)