Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())

bomb = [[False for i in range(w)] for j in range(h)]
cnth = [0 for i in range(h)]
cntw = [0 for i in range(w)]
for i in range(m):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  cnth[x] += 1
  cntw[y] += 1
  bomb[x][y] = True
maxh = max(cnth)
maxw = max(cntw)

xx = []
yy = []
for i in range(h):
  if maxh == cnth[i]:
    xx.append(i)
for i in range(w):
  if maxw == cntw[i]:
    yy.append(i)


ans = maxh + maxw -1
for i in xx:
  for j in yy:
    if not bomb[i][j]:
      ans += 1
      print (ans)
      exit()
print (ans)


Fixed submission:
h, w, m = map(int, input().split())

bomb = []
cnth = [0 for i in range(h)]
cntw = [0 for i in range(w)]
bomh = [set() for i in range(h)]
bomw = [set() for i in range(w)]
for i in range(m):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  cnth[x] += 1
  cntw[y] += 1
  bomh[x].add(y)
  bomw[y].add(x)
  bomb.append([x,y])
maxh = max(cnth)
maxw = max(cntw)
ans = maxh + maxw - 1

xx = []
yy = []
for i in range(h):
  if maxh == cnth[i]:
    xx.append(i)
for i in range(w):
  if maxw == cntw[i]:
    yy.append(i)

for i in xx:
  for j in yy:
    if j not in bomh[i]:
      print (ans+1)
      exit()
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())

bomb = [[False for i in range(w)] for j in range(h)]
cnth = [0 for i in range(h)]
cntw = [0 for i in range(w)]
for i in range(m):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  cnth[x] += 1
  cntw[y] += 1
  bomb[x][y] = True

ans = 0
tmp = 0
for i in range(h):
  for j in range(w):
    tmp = cnth[i]+cntw[j]
    if bomb[i][j]:
      tmp -= 1
    ans = max(ans, tmp)
print (ans)

Fixed submission:
h, w, m = map(int, input().split())

bomb = []
cnth = [0 for i in range(h)]
cntw = [0 for i in range(w)]
bomh = [set() for i in range(h)]
bomw = [set() for i in range(w)]
for i in range(m):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  cnth[x] += 1
  cntw[y] += 1
  bomh[x].add(y)
  bomw[y].add(x)
  bomb.append([x,y])
maxh = max(cnth)
maxw = max(cntw)
ans = maxh + maxw - 1

xx = []
yy = []
for i in range(h):
  if maxh == cnth[i]:
    xx.append(i)
for i in range(w):
  if maxw == cntw[i]:
    yy.append(i)

for i in xx:
  for j in yy:
    if j not in bomh[i]:
      print (ans+1)
      exit()
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())

bomb = [[False for i in range(w)] for j in range(h)]
cnth = [0 for i in range(h)]
cntw = [0 for i in range(w)]
for i in range(m):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  cnth[x] += 1
  cntw[y] += 1
  bomb[x][y] = True

ans = 0
tmp = 0
for i in range(h):
  for j in range(w):
    tmp = cnth[i]+cntw[j]
    if bomb[i][j]:
      tmp -= 1
    ans = max(ans, tmp)
print (ans)

Fixed submission:
h, w, m = map(int, input().split())

bomb = []
cnth = [0 for i in range(h)]
cntw = [0 for i in range(w)]
bomh = [set() for i in range(h)]
bomw = [set() for i in range(w)]
for i in range(m):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  cnth[x] += 1
  cntw[y] += 1
  bomh[x].add(y)
  bomw[y].add(x)
  bomb.append([x,y])
maxh = max(cnth)
maxw = max(cntw)
ans = maxh + maxw - 1

xx = []
yy = []
for i in range(h):
  if maxh == cnth[i]:
    xx.append(i)
for i in range(w):
  if maxw == cntw[i]:
    yy.append(i)

for i in xx:
  for j in yy:
    if j not in bomh[i]:
      print (ans+1)
      exit()
print (ans)