Buggy python submission (verdict: Time Limit Exceeded):
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
ans = -1
for c in ci:
  for r in ri:
    if c not in set(rn[r]):
      ans = max(ans,cm+rm)
      print(ans)
      exit()
ans = cm+rm-1
print(ans)

Fixed submission:
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
for r in ri:
  rs = set(rn[r])
  for c in ci:
    if c not in rs:
      ans = cm+rm
      print(ans)
      exit()
ans = cm+rm-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
ans = -1
for c in ci:
  for r in ri:
    if c not in set(rn[r]):
      ans = max(ans,cm+rm)
      print(ans)
      exit()
ans = cm+rm-1
print(ans)

Fixed submission:
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
for r in ri:
  rs = set(rn[r])
  for c in ci:
    if c not in rs:
      ans = cm+rm
      print(ans)
      exit()
ans = cm+rm-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
ans = -1
for c in ci:
  for r in ri:
    if c not in rn[r]:
      ans = max(ans,cm+rm)
      print(ans)
      exit()
    else:
      ans = max(ans,cm+rm-1)
print(ans)

Fixed submission:
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
for r in ri:
  rs = set(rn[r])
  for c in ci:
    if c not in rs:
      ans = cm+rm
      print(ans)
      exit()
ans = cm+rm-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
ans = -1
for c in ci:
  for r in ri:
    if c not in rn[r]:
      ans = max(ans,cm+rm)
    else:
      ans = max(ans,cm+rm-1)
print(ans)

Fixed submission:
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
for r in ri:
  rs = set(rn[r])
  for c in ci:
    if c not in rs:
      ans = cm+rm
      print(ans)
      exit()
ans = cm+rm-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

ri = row.index(max(row))
rr = rn[ri]
cm = max(col)
rm = max(row)
ans = -1
for x,y in enumerate(row):
  if y!=rm:  continue
  rr = rn[x]
  for i,j in enumerate(col):
    if j==cm:
      if i in rr:
        ans = max(ans,cm+rm-1)
      else:
        ans = max(ans,cm+rm)
print(ans)

Fixed submission:
h,w,m = map(int, input().split())
row = [0]*(h+1)
rn = [[] for _ in range(h+1)]
col = [0]*(w+1)
cn = [[] for _ in range(w+1)]
data = []
for _ in range(m):
  hd,wd = map(int, input().split())
  row[hd] += 1
  rn[hd].append(wd)
  col[wd] += 1
  cn[wd].append(hd)

cm = max(col)
rm = max(row)
ri = [x for x,y in enumerate(row) if y == rm]
ci = [x for x,y in enumerate(col) if y == cm]
for r in ri:
  rs = set(rn[r])
  for c in ci:
    if c not in rs:
      ans = cm+rm
      print(ans)
      exit()
ans = cm+rm-1
print(ans)