Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = {}
for _ in range(m):
    h, w = map(int, input().split())
    inputs.setdefault(h, set([w]))
    inputs[h].add(w)

    if h_l[h] :
        h_l[h][1].add(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, set([w])]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].add(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, set([h])]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)

ans = max_h + max_w -1
flag = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if j not in inputs[i]:
            ans = max_h + max_w
            flag = 1
            break
        
print(ans)

Fixed submission:
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = {}
for _ in range(m):
    h, w = map(int, input().split())
    inputs.setdefault(h, set([w]))
    inputs[h].add(w)

    if h_l[h] :
        h_l[h][1].add(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, set([w])]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].add(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, set([h])]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)

ans = max_h + max_w -1
flag = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if j not in inputs[i]:
            ans = max_h + max_w
            flag = 1
            break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = []
for _ in range(m):
    h, w = map(int, input().split())
    inputs.append([h,w])
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)
 
flag = 0
ans = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if flag == 1:
            break
        if j in h_l[i][1]:
            ans = max_h + max_w - 1
        else:
            ans = max_h + max_w
            flag = 1
print(ans)

Fixed submission:
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = {}
for _ in range(m):
    h, w = map(int, input().split())
    inputs.setdefault(h, set([w]))
    inputs[h].add(w)

    if h_l[h] :
        h_l[h][1].add(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, set([w])]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].add(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, set([h])]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)

ans = max_h + max_w -1
flag = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if j not in inputs[i]:
            ans = max_h + max_w
            flag = 1
            break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = []
for _ in range(m):
    h, w = map(int, input().split())
    inputs.append([h,w])
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)
 
inputs.sort()
max_h_l.sort()

flag = 0
ans = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if flag == 1:
            break
        if [i,j] not in inputs:
            ans = max_h + max_w
            flag = 1
        else:
            ans = max_h + max_w - 1
print(ans)


Fixed submission:
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = {}
for _ in range(m):
    h, w = map(int, input().split())
    inputs.setdefault(h, set([w]))
    inputs[h].add(w)

    if h_l[h] :
        h_l[h][1].add(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, set([w])]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].add(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, set([h])]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)

ans = max_h + max_w -1
flag = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if j not in inputs[i]:
            ans = max_h + max_w
            flag = 1
            break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = []
for _ in range(m):
    h, w = map(int, input().split())
    inputs.append([h,w])
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    if h_l[h][0] == max_h:
        max_h_l.append(h)
            
 
        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    if w_l[w][0] == max_w:
        max_w_l.append(w)
 
inputs.sort()
max_h_l.sort()

flag = 0
ans = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if flag == 1:
            break
        if [i,j] not in inputs:
            ans = max_h + max_w
            flag = 1
        else:
            ans = max_h + max_w - 1
print(ans)


Fixed submission:
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = {}
for _ in range(m):
    h, w = map(int, input().split())
    inputs.setdefault(h, set([w]))
    inputs[h].add(w)

    if h_l[h] :
        h_l[h][1].add(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, set([w])]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].add(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, set([h])]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)

ans = max_h + max_w -1
flag = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if j not in inputs[i]:
            ans = max_h + max_w
            flag = 1
            break
        
print(ans)

Buggy python submission (verdict: Runtime Error):
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
for _ in range(m):
    h, w = map(int, input().split())
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    if h_l[h][0] == max_h:
        max_h_l.append(h)
            
 
        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    if w_l[w][0] == max_w:
        max_w_l.append(w)
 
 
flag = 0
ans = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if flag == 1:
            break
        if j in h_l[i][1]:
            ans = max_h + max_w - 1
        else:
            ans = max_h + max_w
            flag = 1
print(ans)
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
for _ in range(m):
    h, w = map(int, input().split())
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    if h_l[h][0] == max_h:
        max_h_l.append(h)
            

        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    if w_l[w][0] == max_w:
        max_w_l.append(w)


flag = 0
ans = 0
for i in set(max_h_l):
    if flag == 1:
        break
    for j in set(max_w_l):
        if flag == 1:
            break
        if j in h_l[i][1]:
            ans = max_h + max_w - 1
        else:
            ans = max_h + max_w
            flag = 1
print(ans)

Fixed submission:
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = {}
for _ in range(m):
    h, w = map(int, input().split())
    inputs.setdefault(h, set([w]))
    inputs[h].add(w)

    if h_l[h] :
        h_l[h][1].add(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, set([w])]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].add(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, set([h])]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)

ans = max_h + max_w -1
flag = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if j not in inputs[i]:
            ans = max_h + max_w
            flag = 1
            break
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
for _ in range(m):
    h, w = map(int, input().split())
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    if h_l[h][0] == max_h:
        max_h_l.append(h)
            

        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    if w_l[w][0] == max_w:
        max_w_l.append(w)


flag = 0
ans = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if flag == 1:
            break
        if j in h_l[i][1]:
            ans = max_h + max_w - 1
        else:
            ans = max_h + max_w
            flag = 1
print(ans)

Fixed submission:
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
inputs = {}
for _ in range(m):
    h, w = map(int, input().split())
    inputs.setdefault(h, set([w]))
    inputs[h].add(w)

    if h_l[h] :
        h_l[h][1].add(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, set([w])]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    elif h_l[h][0] == max_h:
        max_h_l.append(h)
 
        
    if w_l[w]:
        w_l[w][1].add(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, set([h])]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    elif w_l[w][0] == max_w:
        max_w_l.append(w)

ans = max_h + max_w -1
flag = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if j not in inputs[i]:
            ans = max_h + max_w
            flag = 1
            break
        
print(ans)