Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import collections

H, W, M = map(int, input().split())
tate = []
yoko = []
S = []

for i in range(M):
    h, w = map(int, input().split())
    tate.append(h-1)
    yoko.append(w-1)
    S.append([h-1, w-1])

tate = collections.Counter(tate)
yoko = collections.Counter(yoko)
yoko_max = yoko.most_common()[0][1]
yoko_index = []
tate_max = tate.most_common()[0][1]
tate_index = []

for k, v in yoko.most_common():
    if v == yoko_max: yoko_index.append(k)
    else: break

for k, v in tate.most_common():
    if v == tate_max: tate_index.append(k)
    else: break

for i in range(len(yoko_index)):
    for j in range(len(tate_index)):
        if [tate_index[j], yoko_index[i]] in S:
            continue
        else:
            print(tate_max + yoko_max)
            exit()


print(tate_max + yoko_max - 1)


Fixed submission:
#!/usr/bin/env python3
import collections

H, W, M = map(int, input().split())
tate = []
yoko = []
S = set()

for i in range(M):
    h, w = map(int, input().split())
    tate.append(h-1)
    yoko.append(w-1)
    S.add((h-1, w-1))

tate = collections.Counter(tate)
yoko = collections.Counter(yoko)
yoko_max = yoko.most_common()[0][1]
yoko_index = []
tate_max = tate.most_common()[0][1]
tate_index = []

for k, v in yoko.most_common():
    if v == yoko_max: yoko_index.append(k)
    else: break

for k, v in tate.most_common():
    if v == tate_max: tate_index.append(k)
    else: break

for i in yoko_index:
    for j in tate_index:
        if (j, i) in S:
            continue
        else:
            print(tate_max + yoko_max)
            exit()


print(tate_max + yoko_max - 1)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

H, W, M = map(int, input().split())
tate = [0] * H
yoko = [0] * W
S = []

for i in range(M):
    h, w = map(int, input().split())
    tate[h-1] += 1
    yoko[w-1] += 1
    S.append([h-1, w-1])


yoko_max = max(yoko)
yoko_index = []
tate_max = max(tate)
tate_index = []

for i in range(len(yoko)):
    if yoko[i] == yoko_max: yoko_index.append(i)

for i in range(len(tate)):
    if tate[i] == tate_max: tate_index.append(i)

flag = True

for i in range(len(yoko_index)):
    for j in range(len(tate_index)):
        if [tate_index[j], yoko_index[i]] in S:
            continue
        else:
            print(tate_max + yoko_max)
            exit()


print(tate_max + yoko_max - 1)


Fixed submission:
#!/usr/bin/env python3
import collections

H, W, M = map(int, input().split())
tate = []
yoko = []
S = set()

for i in range(M):
    h, w = map(int, input().split())
    tate.append(h-1)
    yoko.append(w-1)
    S.add((h-1, w-1))

tate = collections.Counter(tate)
yoko = collections.Counter(yoko)
yoko_max = yoko.most_common()[0][1]
yoko_index = []
tate_max = tate.most_common()[0][1]
tate_index = []

for k, v in yoko.most_common():
    if v == yoko_max: yoko_index.append(k)
    else: break

for k, v in tate.most_common():
    if v == tate_max: tate_index.append(k)
    else: break

for i in yoko_index:
    for j in tate_index:
        if (j, i) in S:
            continue
        else:
            print(tate_max + yoko_max)
            exit()


print(tate_max + yoko_max - 1)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

H, W, M = map(int, input().split())
tate = [0] * H
yoko = [0] * W
S = []

for i in range(M):
    h, w = map(int, input().split())
    tate[h-1] += 1
    yoko[w-1] += 1
    S.append([h-1, w-1])


yoko_max = max(yoko)
yoko_index = []
tate_max = max(tate)
tate_index = []

for i in range(len(yoko)):
    if yoko[i] == yoko_max: yoko_index.append(i)

for i in range(len(tate)):
    if tate[i] == tate_max: tate_index.append(i)

flag = True

for i in range(len(yoko_index)):
    for j in range(len(tate_index)):
        if [tate_index[j], yoko_index[i]] in S:
            continue
        else:
            print(tate_max + yoko_max)
            exit()


print(tate_max + yoko_max - 1)


Fixed submission:
#!/usr/bin/env python3
import collections

H, W, M = map(int, input().split())
tate = []
yoko = []
S = set()

for i in range(M):
    h, w = map(int, input().split())
    tate.append(h-1)
    yoko.append(w-1)
    S.add((h-1, w-1))

tate = collections.Counter(tate)
yoko = collections.Counter(yoko)
yoko_max = yoko.most_common()[0][1]
yoko_index = []
tate_max = tate.most_common()[0][1]
tate_index = []

for k, v in yoko.most_common():
    if v == yoko_max: yoko_index.append(k)
    else: break

for k, v in tate.most_common():
    if v == tate_max: tate_index.append(k)
    else: break

for i in yoko_index:
    for j in tate_index:
        if (j, i) in S:
            continue
        else:
            print(tate_max + yoko_max)
            exit()


print(tate_max + yoko_max - 1)