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


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = [i for i, v in enumerate(Mh) if v == nh]
    lw = [i for i, v in enumerate(Mw) if v == nw]

    for h in lh:
        for w in lw:
            if (h, w) not in B:
                print(nh + nw)
                return

    print(nh + nw - 1)


main()


Fixed submission:
import sys
from collections import Counter


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = Counter(Mh)[nh]
    lw = Counter(Mw)[nw]

    out = 0
    for (h, w) in B:
        if Mh[h] == nh and Mw[w] == nw:
            out += 1

    if out == lh * lw:
        print(nh + nw - 1)
    else:
        print(nh + nw)


main()

Buggy python submission (verdict: Runtime Error):
import sys


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = [i for i, v in enumerate(lh) if v == nh]
    lw = [i for i, v in enumerate(lw) if v == nw]

    for h in lh:
        for w in lw:
            if (h, w) not in B:
                print(nh + nw)
                return

    print(nh + nw - 1)


main()


Fixed submission:
import sys
from collections import Counter


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = Counter(Mh)[nh]
    lw = Counter(Mw)[nw]

    out = 0
    for (h, w) in B:
        if Mh[h] == nh and Mw[w] == nw:
            out += 1

    if out == lh * lw:
        print(nh + nw - 1)
    else:
        print(nh + nw)


main()

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


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = []
    lw = []
    while nh in Mh:
        ih = Mh.index(nh)
        lh.append(ih)
        Mh[ih] = 0
    while nw in Mw:
        iw = Mw.index(nw)
        lw.append(iw)
        Mw[iw] = 0

    for h in lh:
        for w in lw:
            if (h, w) not in B:
                print(nh + nw)
                return

    print(nh + nw - 1)


main()


Fixed submission:
import sys
from collections import Counter


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = Counter(Mh)[nh]
    lw = Counter(Mw)[nw]

    out = 0
    for (h, w) in B:
        if Mh[h] == nh and Mw[w] == nw:
            out += 1

    if out == lh * lw:
        print(nh + nw - 1)
    else:
        print(nh + nw)


main()