Buggy python submission (verdict: Time Limit Exceeded):
def main():
    def solve(strings_max, rows_max, mapa):
        summa = maxs + maxr - 1
        if summa == h + w - 1 or summa == m:
            return summa
        for h_item in strings_max:
            for w_item in rows_max:
                if w_item not in mapa.get(h_item, []):
                    return summa + 1
        return summa


    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    maxs = max(strings)
    maxr = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == maxs:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == maxr:
            rows_max.append(i)
    
    ans = solve(strings_max, rows_max, mapa)
    print(ans)

main()


Fixed submission:
def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    def solve(strings_max, rows_max, mapa):
        summa = maxs + maxr - 1
        if summa == h + w - 1:
            return summa
        for h_item in strings_max:
            for w_item in rows_max:
                if w_item not in mapa.get(h_item, []):
                    return summa + 1
        return summa


    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    maxs = max(strings)
    maxr = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == maxs:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == maxr:
            rows_max.append(i)
    
    ans = solve(strings_max, rows_max, mapa)
    print(ans)

main()


Fixed submission:
def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
mapa = {}
strings = [0]*h
rows = [0]*w
for i in range(m):
    h1, w1 = map(int, input().split())
    if not mapa.get(h1-1, 0):
        mapa[h1-1] = []
    mapa[h1-1].append(w1-1)
    strings[h1-1] += 1
    rows[w1-1] += 1
maxs = max(strings)
maxr = max(rows)
summa = maxs + maxr - 1
fl = True
for i in range(h):
    if fl and strings[i] == maxs:
        for j in range(w):
            if rows[j] == maxr:
                if j not in mapa.get(i, []):
                    summa = maxs + maxr
                    fl = False
                    break
print(summa)


Fixed submission:
def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()

Buggy python submission (verdict: Runtime Error):
h, w, m = map(int, input().split())
mapa = [[0]*w for i in range(h)]
strings = [0]*h
rows = [0]*w
for i in range(m):
    h1, w1 = map(int, input().split())
    mapa[h1-1][w1-1] = 1
    strings[h1-1] += 1
    rows[w1-1] += 1
maxs = max(strings)
maxr = max(rows)
summa = maxs + maxr - 1
fl = True
for i in range(h):
    if fl and strings[i] == maxs:
        for j in range(w):
            if rows[j] == maxr:
                if mapa[i][j] != 1:
                    summa = maxs + maxr
                    fl = False
                    break
print(summa)


Fixed submission:
def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()

Buggy python submission (verdict: Runtime Error):
h, w, m = map(int, input().split())
mapa = [[0]*w for i in range(h)]
strings = [[0, i] for i in range(h)]
rows = [[0, i] for i in range(w)]
maxs = 0
maxr = 0
for i in range(m):
    h1, w1 = map(int, input().split())
    mapa[h1-1][w1-1] = 1
    strings[h1-1][0] += 1
    rows[w1-1][0] += 1
    if strings[h1-1][0] > maxs:
        maxs = strings[h1-1][0]
    if rows[w1-1][0] > maxr:
        maxr = rows[h1-1][0]
summa = maxs + maxr - 1
for i in range(h):
    if strings[i][0] == maxs:
        for j in range(w):
            if rows[j][0] == maxr:
                x = maxs + maxr
                if mapa[strings[i][1]][rows[j][1]] == 1:
                    x -= 1
                if x > summa:
                    summa = x
                    print(summa)
                    exit()
print(summa)


Fixed submission:
def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

h, w, m = map(int, input().split())
mapa = [[0]*w for i in range(h)]
strings = [[0, i+1] for i in range(h)]
rows = [[0, i+1] for i in range(w)]
maxs = 0
maxr = 0
for i in range(m):
    h1, w1 = map(int, input().split())
    mapa[h1-1][w1-1] = 1
    strings[h1-1][0] += 1
    rows[w1-1][0] += 1
    if strings[h1-1][0] > maxs:
        maxs = strings[h1-1][0]
    if rows[w1-1][0] > maxr:
        maxr = rows[h1-1][0]
summa = maxs + maxr - 1
for i in range(h):
    if strings[i][0] == maxs:
        for j in range(w):
            if rows[j][0] == maxr:
                x = maxs + maxr
                if mapa[strings[i][1]-1][rows[j][1]-1] == 1:
                    x -= 1
                if x > summa:
                    summa = x
                    print(summa)
                    exit()
print(summa)


Fixed submission:
def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

h, w, m = map(int, input().split())
mapa = [[0]*w for i in range(h)]
strings = [[0, i+1] for i in range(h)]
rows = [[0, i+1] for i in range(w)]
maxs = 0
maxr = 0
for i in range(m):
    h1, w1 = map(int, input().split())
    mapa[h1-1][w1-1] = 1
    strings[h1-1][0] += 1
    rows[w1-1][0] += 1
    if strings[h1-1][0] > maxs:
        maxs = strings[h1-1][0]
    if rows[w1-1][0] > maxr:
        maxr = rows[h1-1][0]
summa = maxs + maxr - 1
for i in range(h):
    if strings[i][0] == maxs:
        for j in range(w):
            if rows[j][0] == maxr:
                x = maxs + maxr
                if mapa[i][j] == 1:
                    x -= 1
                if x > summa:
                    summa = x
                    print(summa)
                    exit()
print(summa)


Fixed submission:
def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
targets = []
strings = [[0, i+1] for i in range(h)]
rows = [[0, i+1] for i in range(w)]
for i in range(m):
    h1, w1 = map(int, input().split())
    targets.append([h1, w1])
    strings[h1-1][0] += 1
    rows[w1-1][0] += 1
rows.sort(reverse=True)
strings.sort(reverse=True)
maxs = strings[0][0]
maxr = rows[0][0]
summa = maxs + maxr - 1
for i in range(h):
    if strings[i][0] == maxs:
        for j in range(w):
            if rows[j][0] == maxr:
                x = maxs + maxr
                if [strings[i][1], rows[j][1]] in targets:
                    x -= 1
                if x > summa:
                    summa = x
                    print(summa)
                    exit()
            else:
                break
    else:
        break
print(summa)


Fixed submission:
def main():
    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    max_s = max(strings)
    max_r = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == max_s:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == max_r:
            rows_max.append(i)
    
    forbidden_positions = set(mapa[strings_max[0]])
    for item in strings_max[1:]:
        forbidden_positions.intersection_update(set(mapa[item]))

    answer_set = set(rows_max).difference(forbidden_positions)
    if answer_set:
        print(max_s + max_r)
    else:
        print(max_s + max_r - 1)

main()