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

h,w,m = map(int, sys.stdin.readline().split())
targets = [list(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h = max(num_in_h.values())
max_w = max(num_in_w.values())
max_h_list = [kv for kv in num_in_h.items() if kv[1] == max_h]
max_w_list = [kv for kv in num_in_w.items() if kv[1] == max_w]
ans = max_h + max_w

#print([max_h[0], max_w[0]] in targets)
flag = False
for h in max_h_list:
    for w in max_w_list:
        if [h[0], w[0]] not in targets:
            flag = True
            break

print(ans if flag == True else ans-1)


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)

Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict

h,w,m = map(int, sys.stdin.readline().split())
targets = [list(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h = num_in_h.values()
max_w = num_in_w.values()
max_h_list = [kv for kv in num_in_h.items() if kv[1] == max_h]
max_w_list = [kv for kv in num_in_w.items() if kv[1] == max_w]
ans = max_h + max_w

#print([max_h[0], max_w[0]] in targets)
flag = False
for h in max_h_list:
    for w in max_w_list:
        if [h[0], w[0]] not in targets:
            flag = True
            break

print(ans if flag == True else ans-1)


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)

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

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h_set = set([i for i, v in enumerate(num_in_h) if v == max(num_in_h)])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max(num_in_w)])
ans = max(num_in_h) + max(num_in_w) -1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)

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

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = []
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.append((t_h, t_w))
targets = set(targets)

max_h_set = set([i for i, v in enumerate(num_in_h) if v == max(num_in_h)])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max(num_in_w)])
ans = max(num_in_h) + max(num_in_w) -1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)    


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)

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

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = []
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.append((t_h, t_w))

max_h_set = set([i for i, v in enumerate(num_in_h) if v == max(num_in_h)])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max(num_in_w)])
ans = max(num_in_h) + max(num_in_w)

point = 0
comb = len(max_h_set) * len(max_w_set)
targets = set(targets)
for t in targets:
    if t[0] in max_h_set and t[1] in max_w_set:
        point += 1 # 爆破地点に爆破対象あり

print(ans if comb != point else ans-1)


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)

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

h,w,m = map(int, sys.stdin.readline().split())
targets = [tuple(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h_set = set(kv[0] for kv in num_in_h.items() if kv[1] == max(num_in_h.values()))
max_w_set = set(kv[0] for kv in num_in_w.items() if kv[1] == max(num_in_w.values()))
ans = max(num_in_h.values()) + max(num_in_w.values())

point = 0
comb = len(max_h_set) * len(max_w_set)
targets = set(targets)
for t in targets:
    if t[0] in max_h_set and t[1] in max_w_set:
        point += 1 # 爆破地点に爆破対象あり

print(ans if comb != point else ans-1)


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)

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

h,w,m = map(int, sys.stdin.readline().split())
targets = [tuple(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h_list = [kv[0] for kv in num_in_h.items() if kv[1] == max(num_in_h.values())]
max_w_list = [kv[0] for kv in num_in_w.items() if kv[1] == max(num_in_w.values())]
ans = max(num_in_h.values()) + max(num_in_w.values())

point = 0
comb = len(max_h_list) * len(max_w_list)
targets = set(targets)
for t in targets:
    if t[0] in max_h_list and t[1] in max_w_list:
        point += 1 # 爆破地点に爆破対象あり

print(ans if comb != point else ans-1)


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)

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

h,w,m = map(int, sys.stdin.readline().split())
targets = [list(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h_list = [kv[0] for kv in num_in_h.items() if kv[1] == max(num_in_h.values())]
max_w_list = [kv[0] for kv in num_in_w.items() if kv[1] == max(num_in_w.values())]
ans = max(num_in_h.values()) + max(num_in_w.values())

#print(max_h_list, max_w_list)
point = 0
comb = len(max_h_list) * len(max_w_list)
for t in targets:
    if t[0] in max_h_list and t[1] in max_w_list:
        point += 1 # 爆破地点に爆破対象あり

print(ans if comb != point else ans-1)


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)

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

h,w,m = map(int, sys.stdin.readline().split())
targets = [list(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h_list = [kv for kv in num_in_h.items() if kv[1] == max(num_in_h.values())]
max_w_list = [kv for kv in num_in_w.items() if kv[1] == max(num_in_w.values())]
ans = max(num_in_h.values()) + max(num_in_w.values())

#print([max_h[0], max_w[0]] in targets)
flag = False
for h in max_h_list:
    for w in max_w_list:
        if [h[0], w[0]] not in targets:
            flag = True
            break

print(ans if flag == True else ans-1)


Fixed submission:
import sys

h,w,m = map(int, sys.stdin.readline().split())
num_in_h = [0] * h
num_in_w = [0] * w
targets = set()
for _ in range(m):
    t_h, t_w = map(lambda x: int(x)-1, sys.stdin.readline().split())
    num_in_h[t_h] += 1
    num_in_w[t_w] += 1
    targets.add((t_h, t_w))

max_h = max(num_in_h)
max_w = max(num_in_w)
max_h_set = set([i for i, v in enumerate(num_in_h) if v == max_h])
max_w_set = set([i for i, v in enumerate(num_in_w) if v == max_w])
ans = max_h + max_w - 1

flag = False
for i in max_h_set:
    for j in max_w_set:
        if (i, j) not in targets:
            flag = True
            break
    if flag: break

print(ans+1 if flag else ans)