Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
def main():
    import sys
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = [[False] * w for _ in range(h)]
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[y][x] = 1
        
    kouho_h = []
    kouho_w = []
    max_h = max(cnt_h)
    max_w = max(cnt_w)
    for i in range(h):
        if cnt_h[i] == max_h:
            kouho_h.append(i)
    for i in range(w):
        if cnt_w[i] == max_w:
            kouho_w.append(i)
    
    for i in kouho_h:
        for j in kouho_w:
            if bomb[i][j] == False:
                print(max_h + max_w)
                exit()
    print(max_h + max_w - 1)



if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = defaultdict(lambda : 0)
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[(y, x)] = 1
        
    kouho_h = []
    kouho_w = []
    max_h = max(cnt_h)
    max_w = max(cnt_w)
    for i in range(h):
        if cnt_h[i] == max_h:
            kouho_h.append(i)
    for i in range(w):
        if cnt_w[i] == max_w:
            kouho_w.append(i)
    
    for i in kouho_h:
        for j in kouho_w:
            if bomb[(i, j)] == False:
                print(max_h + max_w)
                exit()
    print(max_h + max_w - 1)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
def main():
    import sys
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = [[False] * w for _ in range(h)]
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[y][x] = True
        
    kouho_h = []
    max_h = max(cnt_h)
    max_w = max(cnt_w)
    for i in range(h):
        if cnt_h[i] == max_h:
            kouho_h.append(i)
    kouho_w = []
    for i in range(w):
        if cnt_w[i] == max_w:
            kouho_w.append(i)
    
    flag = False
    for i in kouho_h:
        for j in kouho_w:
            if bomb[i][j] == False:
                flag = True
                break
        else:
            continue
        break
    
    if flag:
        print(max_h + max_w)
    else:
        print(max_h + max_w - 1)



if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = defaultdict(lambda : 0)
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[(y, x)] = 1
        
    kouho_h = []
    kouho_w = []
    max_h = max(cnt_h)
    max_w = max(cnt_w)
    for i in range(h):
        if cnt_h[i] == max_h:
            kouho_h.append(i)
    for i in range(w):
        if cnt_w[i] == max_w:
            kouho_w.append(i)
    
    for i in kouho_h:
        for j in kouho_w:
            if bomb[(i, j)] == False:
                print(max_h + max_w)
                exit()
    print(max_h + max_w - 1)



if __name__ == '__main__':
    main()

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

def main():
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = [[False] * w for _ in range(h)]
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[y][x] = True
        
    kouho_h = []
    max_h = max(cnt_h)
    max_w = max(cnt_w)
    for i in range(h):
        if cnt_h[i] == max_h:
            kouho_h.append(i)
    kouho_w = []
    for i in range(w):
        if cnt_w[i] == max_w:
            kouho_w.append(i)
    
    flag = False
    for i in kouho_h:
        for j in kouho_w:
            if bomb[i][j] == False:
                flag = True
                break
    if flag:
        print(max_h + max_w)
    else:
        print(max_h + max_w - 1)



if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = defaultdict(lambda : 0)
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[(y, x)] = 1
        
    kouho_h = []
    kouho_w = []
    max_h = max(cnt_h)
    max_w = max(cnt_w)
    for i in range(h):
        if cnt_h[i] == max_h:
            kouho_h.append(i)
    for i in range(w):
        if cnt_w[i] == max_w:
            kouho_w.append(i)
    
    for i in kouho_h:
        for j in kouho_w:
            if bomb[(i, j)] == False:
                print(max_h + max_w)
                exit()
    print(max_h + max_w - 1)



if __name__ == '__main__':
    main()

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

def main():
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = [[False] * w for _ in range(h)]
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[y][x] = True
        
    kouho_h = []
    for i in range(h):
        if cnt_h[i] == max(cnt_h):
            kouho_h.append(i)
    kouho_w = []
    for i in range(w):
        if cnt_w[i] == max(cnt_w):
            kouho_w.append(i)
    
    flag = False
    for i in kouho_h:
        for j in kouho_w:
            if bomb[i][j] == False:
                flag = True
                break
    if flag:
        print(max(cnt_h) + max(cnt_w))
    else:
        print(max(cnt_h) + max(cnt_w) - 1)



if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = defaultdict(lambda : 0)
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[(y, x)] = 1
        
    kouho_h = []
    kouho_w = []
    max_h = max(cnt_h)
    max_w = max(cnt_w)
    for i in range(h):
        if cnt_h[i] == max_h:
            kouho_h.append(i)
    for i in range(w):
        if cnt_w[i] == max_w:
            kouho_w.append(i)
    
    for i in kouho_h:
        for j in kouho_w:
            if bomb[(i, j)] == False:
                print(max_h + max_w)
                exit()
    print(max_h + max_w - 1)



if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
cnt_h = [0] * h
cnt_w = [0] * w
bomb = [[False] * w for _ in range(h)]
for _ in range(m):
    y, x = map(int, input().split())
    cnt_h[y - 1] += 1
    cnt_w[x - 1] += 1
    bomb[y - 1][x - 1] = True
    
kouho_h = []
for i in range(h):
    if cnt_h[i] == max(cnt_h):
        kouho_h.append(i)
kouho_w = []
for i in range(w):
    if cnt_w[i] == max(cnt_w):
        kouho_w.append(i)

flag = False
for i in kouho_h:
    for j in kouho_w:
        if bomb[i][j] == False:
            flag = True
if flag:
    print(max(cnt_h) + max(cnt_w))
else:
    print(max(cnt_h) + max(cnt_w) - 1)

Fixed submission:
#!/usr/bin/env python3
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline
    h, w, m = map(int, input().split())
    cnt_h = [0] * h
    cnt_w = [0] * w
    bomb = defaultdict(lambda : 0)
    for _ in range(m):
        y, x = map(lambda x:int(x) - 1, input().split())
        cnt_h[y] += 1
        cnt_w[x] += 1
        bomb[(y, x)] = 1
        
    kouho_h = []
    kouho_w = []
    max_h = max(cnt_h)
    max_w = max(cnt_w)
    for i in range(h):
        if cnt_h[i] == max_h:
            kouho_h.append(i)
    for i in range(w):
        if cnt_w[i] == max_w:
            kouho_w.append(i)
    
    for i in kouho_h:
        for j in kouho_w:
            if bomb[(i, j)] == False:
                print(max_h + max_w)
                exit()
    print(max_h + max_w - 1)



if __name__ == '__main__':
    main()