Language: C

#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)



def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def solve(H: int, W: int, M: int, _h: "List[int]", _w: "List[int]"):
    H_count = [0] * (H+1)
    W_count = [0] * (W+1)
    G = set()
    seenH = set()
    seenW = set()
    for i in range(M):
        h,w=_h[i],_w[i]
        H_count[h] += 1
        W_count[w] += 1
 
        seenH.add(h)
        seenW.add(w)
        G.add((h,w))
    
    Hs = []
    Ws = []
    for i in range(max(H,W)+1):
        if i < len(H_count):
            count = H_count[i]
            if count > 0:
                Hs.append((count,i))
 
        if i < len(W_count):
            count = W_count[i]
            if count > 0:
                Ws.append((count,i))
 
 
    Hs.sort(reverse=True)
    Ws.sort(reverse=True)
 
    # print(Hs)
    # print(Ws)
 
    h_count,h = Hs[0]
    w_count,w = Ws[0]
 
    original = h_count + w_count
    ans = original
    if (h,w) in G:
        # print("a")
        ans -= 1
 
        i = 1
        sameH = []
        while i < len(Hs) and Hs[i][0] == h_count:
            # print("h")
            h = Hs[i][1]
            i += 1
            sameH.append(h)
        
        i = 1
        sameW = []    
        while i < len(Ws) and Ws[i][0] == w_count:
            w = Ws[i][1]
            i += 1
            sameW.append(w)
           
        max_mass = (len(sameH)+1) * (len(sameW)+1)
 
        # print(max_mass)
        on_bom_count = 0
        for h,w in G:
            count = H_count[h] + W_count[w]
            if count == original:
                on_bom_count += 1
        
        if max_mass - on_bom_count > 0:
            ans += 1
 
                
    print(ans)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    h = [int()] * (M)  # type: "List[int]"
    w = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        h[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(H, W, M, h, w)



if __name__ == "__main__":
    main()


Compiler output:
main.c:1:2: error: invalid preprocessing directive #!
    1 | #! /usr/bin/env python3
      |  ^
main.c:2:1: error: unknown type name 'import'
    2 | import sys
      | ^~~~~~
main.c:3:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sys'
    3 | sys.setrecursionlimit(10**9)
      | ^~~
main.c:45:7: error: invalid preprocessing directive #print
   45 |     # print(Hs)
      |       ^~~~~
main.c:46:7: error: invalid preprocessing directive #print
   46 |     # print(Ws)
      |       ^~~~~
main.c:54:11: error: invalid preprocessing directive #print
   54 |         # print("a")
      |           ^~~~~
main.c:60:15: error: invalid preprocessing directive #print
   60 |             # print("h")
      |               ^~~~~
main.c:74:11: error: invalid preprocessing directive #print
   74 |         # print(max_mass)
      |           ^~~~~
main.c:94:28: error: stray '#' in program
   94 |     H = int(next(tokens))  # type: int
      |                            ^
main.c:95:28: error: stray '#' in program
   95 |     W = int(next(tokens))  # type: int
      |                            ^
main.c:96:28: error: stray '#' in program
   96 |     M = int(next(tokens))  # type: int
      |                            ^
main.c:97:24: error: stray '#' in program
   97 |     h = [int()] * (M)  # type: "List[int]"
      |                        ^
main.c:98:24: error: stray '#' in program
   98 |     w = [int()] * (M)  # type: "List[int]"
      |                        ^