Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
H,W,M = list(map(int,input().split()))

counterH = Counter()
counterW = Counter()
targets = set()
for i in range(M):
    h,w = list(map(int,input().split()))
    counterH[h] += 1
    counterW[w] += 1
    targets.add((h,w))

max_w = 0
max_h = 0
if M == 1:
    print(1)
else:
    ans = 2
    flg = False
    for count_H in counterH.most_common():
        max_h = max(max_h,count_H[1])
        if max_h != count_H[1]:
            break
        for count_W in counterW.most_common():
            max_w = max(max_w,count_W[1])
            if max_w != count_W[1]:
                break
            # print(count_H,count_W)
            if (count_H[0],count_W[0]) in targets:
                ans = max(ans,count_H[1]+count_W[1]-1)
            else:
                ans = max(ans,count_H[1]+count_W[1])
                flg = True
            if flg:
                break
        if flg:
            break
    print(ans)

Fixed submission:
def main():
    from collections import Counter
    H,W,M = list(map(int,input().split()))

    counterH = Counter()
    counterW = Counter()
    targets = set()
    for i in range(M):
        h,w = list(map(int,input().split()))
        counterH[h] += 1
        counterW[w] += 1
        targets.add((h,w))

    most_commonH = counterH.most_common()
    most_commonW = counterW.most_common()
    max_w = most_commonW[0][1]
    max_h = most_commonH[0][1]
    if M == 1:
        print(1)
    else:
        ans = 2
        flg = False
        for count_H in most_commonH:
            if max_h != count_H[1]:
                break
            for count_W in most_commonW:
                if max_w != count_W[1]:
                    break
                # print(count_H,count_W)
                if (count_H[0],count_W[0]) in targets:
                    ans = max(ans,count_H[1]+count_W[1]-1)
                else:
                    ans = max(ans,count_H[1]+count_W[1])
                    flg = True
                if flg:
                    break
            if flg:
                break
        print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
H,W,M = list(map(int,input().split()))

counterH = Counter()
counterW = Counter()
targets = set()
for i in range(M):
    h,w = list(map(int,input().split()))
    counterH[h] += 1
    counterW[w] += 1
    targets.add((h,w))

max_w = 0
if M == 1:
    print(1)
else:
    ans = 2
    flg = False
    for count_H in counterH.most_common():
        for count_W in counterW.most_common():
            max_w = max(max_w,count_W[1])
            if max_w != count_W[1]:
                break
            # print(count_H,count_W)
            if (count_H[0],count_W[0]) in targets:
                ans = max(ans,count_H[1]+count_W[1]-1)
            else:
                ans = max(ans,count_H[1]+count_W[1])
                flg = True
            if flg:
                break
        if flg:
            break
    print(ans)

Fixed submission:
def main():
    from collections import Counter
    H,W,M = list(map(int,input().split()))

    counterH = Counter()
    counterW = Counter()
    targets = set()
    for i in range(M):
        h,w = list(map(int,input().split()))
        counterH[h] += 1
        counterW[w] += 1
        targets.add((h,w))

    most_commonH = counterH.most_common()
    most_commonW = counterW.most_common()
    max_w = most_commonW[0][1]
    max_h = most_commonH[0][1]
    if M == 1:
        print(1)
    else:
        ans = 2
        flg = False
        for count_H in most_commonH:
            if max_h != count_H[1]:
                break
            for count_W in most_commonW:
                if max_w != count_W[1]:
                    break
                # print(count_H,count_W)
                if (count_H[0],count_W[0]) in targets:
                    ans = max(ans,count_H[1]+count_W[1]-1)
                else:
                    ans = max(ans,count_H[1]+count_W[1])
                    flg = True
                if flg:
                    break
            if flg:
                break
        print(ans)

if __name__ == "__main__":
    main()