Buggy python submission (verdict: Time Limit Exceeded):
import itertools
def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_hw = [[] for _ in range(h+1)]

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_hw[h].append(w)

m_h = max(l_h)
m_w = max(l_w)

ans = m_h + m_w

l_h_2 = my_index_multi(l_h,m_h)
l_w_2 = my_index_multi(l_w,m_w)


for i,j in itertools.product(l_h_2,l_w_2):
    if j not in l_hw[i]:
        break
else:
    ans -= 1

print(ans)

Fixed submission:
import sys
import itertools

input = sys.stdin.readline

def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_b = set()

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_b.add((h,w))

m_h = max(l_h)
m_w = max(l_w)

l_h_2 = []
for i, x in enumerate(l_h):
    if x == m_h:
        l_h_2.append(i)

l_w_2 = []
for i, x in enumerate(l_w):
    if x == m_w:
        l_w_2.append(i)

ans = m_h + m_w

for i,j in itertools.product(l_h_2,l_w_2):
    if (i,j) not in l_b:
        break
else:
    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_hw = [[] for _ in range(h+1)]

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_hw[h].append(w)

m_h = max(l_h)
m_w = max(l_w)

ans = m_h + m_w

l_h_2 = my_index_multi(l_h,m_h)
l_w_2 = my_index_multi(l_w,m_w)

flag = False

for i in l_h_2:
    for j in l_w_2:
        if j not in l_hw[i]:
            flag = True
            break
    if flag:
        break
else:
    ans -= 1

print(ans)

Fixed submission:
import sys
import itertools

input = sys.stdin.readline

def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_b = set()

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_b.add((h,w))

m_h = max(l_h)
m_w = max(l_w)

l_h_2 = []
for i, x in enumerate(l_h):
    if x == m_h:
        l_h_2.append(i)

l_w_2 = []
for i, x in enumerate(l_w):
    if x == m_w:
        l_w_2.append(i)

ans = m_h + m_w

for i,j in itertools.product(l_h_2,l_w_2):
    if (i,j) not in l_b:
        break
else:
    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
a = min(h*w,3*10**5)
l_hw = [[0 for _ in range(a)] for __ in range(h+1)]

for x in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_hw[h][x] += w

m_h = max(l_h)
m_w = max(l_w)

ans = m_h + m_w

l_h_2 = my_index_multi(l_h,m_h)
l_w_2 = my_index_multi(l_w,m_w)

for i in l_h_2:
    flag = False
    for j in l_w_2:
        if j not in l_hw[i]:
            flag = True
            break
    if flag:
        break
else:
    ans -= 1

print(ans)

Fixed submission:
import sys
import itertools

input = sys.stdin.readline

def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_b = set()

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_b.add((h,w))

m_h = max(l_h)
m_w = max(l_w)

l_h_2 = []
for i, x in enumerate(l_h):
    if x == m_h:
        l_h_2.append(i)

l_w_2 = []
for i, x in enumerate(l_w):
    if x == m_w:
        l_w_2.append(i)

ans = m_h + m_w

for i,j in itertools.product(l_h_2,l_w_2):
    if (i,j) not in l_b:
        break
else:
    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_hw = [[] for _ in range(h+1)]

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_hw[h].append(w)

m_h = max(l_h)
m_w = max(l_w)

ans = m_h + m_w

l_h_2 = my_index_multi(l_h,m_h)
l_w_2 = my_index_multi(l_w,m_w)

for i in l_h_2:
    flag = False
    for j in l_w_2:
        if j not in l_hw[i]:
            flag = True
            break
    if flag:
        break
else:
    ans -= 1

print(ans)

Fixed submission:
import sys
import itertools

input = sys.stdin.readline

def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_b = set()

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_b.add((h,w))

m_h = max(l_h)
m_w = max(l_w)

l_h_2 = []
for i, x in enumerate(l_h):
    if x == m_h:
        l_h_2.append(i)

l_w_2 = []
for i, x in enumerate(l_w):
    if x == m_w:
        l_w_2.append(i)

ans = m_h + m_w

for i,j in itertools.product(l_h_2,l_w_2):
    if (i,j) not in l_b:
        break
else:
    ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_hw = [[] for _ in range(h+1)]

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_hw[h].append(w)

m_h = max(l_h)
m_w = max(l_w)

ans = m_h + m_w

l_h_2 = my_index_multi(l_h,m_h)
l_w_2 = my_index_multi(l_w,m_w)

for i in l_h_2:
    flag = False
    for j in l_w_2:
        if j not in l_hw[i]:
            flag = True
            break
    if flag:
        break
else:
    ans -= 1

print(ans)

Fixed submission:
import sys
import itertools

input = sys.stdin.readline

def my_index_multi(l, x):
    return [k for k, _x in enumerate(l) if _x == x]

h,w,m = map(int,input().split())
l_h = [0]*(h+1)
l_w = [0]*(w+1)
l_b = set()

for _ in range(m):
    h,w = map(int,input().split())
    l_h[h] += 1
    l_w[w] += 1
    l_b.add((h,w))

m_h = max(l_h)
m_w = max(l_w)

l_h_2 = []
for i, x in enumerate(l_h):
    if x == m_h:
        l_h_2.append(i)

l_w_2 = []
for i, x in enumerate(l_w):
    if x == m_w:
        l_w_2.append(i)

ans = m_h + m_w

for i,j in itertools.product(l_h_2,l_w_2):
    if (i,j) not in l_b:
        break
else:
    ans -= 1

print(ans)