Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
HW_L = [[int(x)-1 for x in input().split()] for y in range(M)]

w_l = [0] * W
h_l = [0] * H

for _hi, _wi in HW_L:
    w_l[_wi] += 1
    h_l[_hi] += 1

max_h = max(h_l)
max_w = max(w_l)

h_idx = [i for i, x in enumerate(h_l) if x == max_h]
w_idx = [i for i, x in enumerate(w_l) if x == max_w]

ans = max_h + max_w - 1

for hi in h_idx:
    for wj in w_idx:
        if [hi, wj] not in HW_L:
            ans = max_h + max_w
            break
    else:
        continue
    break

print(ans)


Fixed submission:
H, W, M = map(int, input().split())
HW_L = set(tuple(int(x)-1 for x in input().split()) for y in range(M))

w_l = [0] * W
h_l = [0] * H

for _hi, _wi in HW_L:
    w_l[_wi] += 1
    h_l[_hi] += 1

max_h = max(h_l)
max_w = max(w_l)

h_idx = [i for i, x in enumerate(h_l) if x == max_h]
w_idx = [i for i, x in enumerate(w_l) if x == max_w]

ans = max_h + max_w - 1

for hi in h_idx:
    for wj in w_idx:
        if (hi, wj) not in HW_L:
            ans = max_h + max_w
            break
    else:
        continue
    break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
HW_L = [[int(x)-1 for x in input().split()] for y in range(M)]

w_l = [0] * W
h_l = [0] * H

for _hi, _wi in HW_L:
    w_l[_wi] += 1
    h_l[_hi] += 1

h_idx = [i for i, x in enumerate(h_l) if x == max(h_l)]
w_idx = [i for i, x in enumerate(w_l) if x == max(w_l)]

for hi in h_idx:
    for wj in w_idx:
        if [hi, wj] in HW_L:
            continue
        else:
            print(max(h_l) + max(w_l))
            exit(0)

print(max(h_l) + max(w_l)-1)


Fixed submission:
H, W, M = map(int, input().split())
HW_L = set(tuple(int(x)-1 for x in input().split()) for y in range(M))

w_l = [0] * W
h_l = [0] * H

for _hi, _wi in HW_L:
    w_l[_wi] += 1
    h_l[_hi] += 1

max_h = max(h_l)
max_w = max(w_l)

h_idx = [i for i, x in enumerate(h_l) if x == max_h]
w_idx = [i for i, x in enumerate(w_l) if x == max_w]

ans = max_h + max_w - 1

for hi in h_idx:
    for wj in w_idx:
        if (hi, wj) not in HW_L:
            ans = max_h + max_w
            break
    else:
        continue
    break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
HW_L = [[int(x)-1 for x in input().split()] for y in range(M)]

w_l = [0] * W
h_l = [0] * H

for _hi, _wi in HW_L:
    w_l[_wi] += 1
    h_l[_hi] += 1

h_idx = [i for i, x in enumerate(h_l) if x == max(h_l)]
w_idx = [i for i, x in enumerate(w_l) if x == max(w_l)]

for hi in h_idx:
    for wj in w_idx:
        if [hi, wj] in HW_L:
            continue
        else:
            print(max(h_l) + max(w_l))
            exit(0)

print(max(h_l) + max(w_l)-1)


Fixed submission:
H, W, M = map(int, input().split())
HW_L = set(tuple(int(x)-1 for x in input().split()) for y in range(M))

w_l = [0] * W
h_l = [0] * H

for _hi, _wi in HW_L:
    w_l[_wi] += 1
    h_l[_hi] += 1

max_h = max(h_l)
max_w = max(w_l)

h_idx = [i for i, x in enumerate(h_l) if x == max_h]
w_idx = [i for i, x in enumerate(w_l) if x == max_w]

ans = max_h + max_w - 1

for hi in h_idx:
    for wj in w_idx:
        if (hi, wj) not in HW_L:
            ans = max_h + max_w
            break
    else:
        continue
    break

print(ans)