Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())
mx=[0] * W
my=[0] * H
bs =[[] for i in range(H)]
mxx = 0
myy = 0
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1] += 1
    my[y-1] += 1
    mxx = max(mx[x-1], mxx)
    myy = max(my[y-1], myy)
    bs[y-1].append(x-1)

vx = []
vy = []
for i,x in enumerate(mx):
    if x == mxx:
        vx.append(i)
for i,y in enumerate(my):
    if y == myy:
        vy.append(i)

a = 1

for i in vx:
    for j in vy:
        if i not in bs[j]:
            a = 0
            break
    else:
        continue
    break

ans = mxx + myy - a
print(ans)


Fixed submission:
H,W,M = map(int, input().split())
mx=[0] * W
my=[0] * H
bs ={}
mxx = 0
myy = 0
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1] += 1
    my[y-1] += 1
    mxx = max(mx[x-1], mxx)
    myy = max(my[y-1], myy)
    if y-1 in bs:
        bs[y-1].add(x-1)
    else:
        bs[y-1] = set([x-1])

vx = []
vy = []
for i,x in enumerate(mx):
    if x == mxx:
        vx.append(i)
for i,y in enumerate(my):
    if y == myy:
        vy.append(i)

a = 1

for i in vx:
    for j in vy:
        if i not in bs[j]:
            a = 0
            break
    else:
        continue
    break

ans = mxx + myy - a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())
mx=[0] * W
my=[0] * H
bs =[[] for i in range(H)]
mxx = 0
myy = 0
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1] += 1
    my[y-1] += 1
    mxx = max(mx[x-1], mxx)
    myy = max(my[y-1], myy)
    bs[y-1].append(x-1)

vx = []
vy = []
for i,x in enumerate(mx):
    if x == mxx:
        vx.append(i)
for i,y in enumerate(my):
    if y == myy:
        vy.append(i)

a = 1
for i in vx:
    for j in vy:
        if i not in bs[j]:
            a = 0
            break
ans = mxx + myy - a
print(ans)


Fixed submission:
H,W,M = map(int, input().split())
mx=[0] * W
my=[0] * H
bs ={}
mxx = 0
myy = 0
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1] += 1
    my[y-1] += 1
    mxx = max(mx[x-1], mxx)
    myy = max(my[y-1], myy)
    if y-1 in bs:
        bs[y-1].add(x-1)
    else:
        bs[y-1] = set([x-1])

vx = []
vy = []
for i,x in enumerate(mx):
    if x == mxx:
        vx.append(i)
for i,y in enumerate(my):
    if y == myy:
        vy.append(i)

a = 1

for i in vx:
    for j in vy:
        if i not in bs[j]:
            a = 0
            break
    else:
        continue
    break

ans = mxx + myy - a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())
mx=[0] * W
my=[0] * H
bs =[]
mxx = 0
myy = 0
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1] += 1
    my[y-1] += 1
    mxx = max(mx[x-1], mxx)
    myy = max(my[y-1], myy)
    bs.append((x-1,y-1))

vx = []
vy = []
for i,x in enumerate(mx):
    if x == mxx:
        vx.append((i,x))
for i,y in enumerate(my):
    if y == myy:
        vy.append((i,y))

a = 1
for i in vx:
    for j in vy:
        if (i[0],j[0]) not in bs:
            a = 0
            break
ans = vx[0][1]+vy[0][1]-a
print(ans)


Fixed submission:
H,W,M = map(int, input().split())
mx=[0] * W
my=[0] * H
bs ={}
mxx = 0
myy = 0
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1] += 1
    my[y-1] += 1
    mxx = max(mx[x-1], mxx)
    myy = max(my[y-1], myy)
    if y-1 in bs:
        bs[y-1].add(x-1)
    else:
        bs[y-1] = set([x-1])

vx = []
vy = []
for i,x in enumerate(mx):
    if x == mxx:
        vx.append(i)
for i,y in enumerate(my):
    if y == myy:
        vy.append(i)

a = 1

for i in vx:
    for j in vy:
        if i not in bs[j]:
            a = 0
            break
    else:
        continue
    break

ans = mxx + myy - a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())
mx=[[0,i] for i in range(W)]
my=[[0,i] for i in range(H)]
bs =[]
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1][0] += 1
    my[y-1][0] += 1
    bs.append((x-1,y-1))

mx.sort(reverse=True)
my.sort(reverse=True)

ans = 0
mxx = 0
myy = 0
for x in mx:
    mxx = max(mxx, x[0])
    if x[0] + 1 < mxx:
        break
    for y in my:
        myy = max(myy, y[0])
        if y[0] + 1 < myy:
            break
        s = x[0] + y[0]
        if (x[1],y[1]) in bs:
            s -= 1
        ans = max(ans, s)
print(ans)


Fixed submission:
H,W,M = map(int, input().split())
mx=[0] * W
my=[0] * H
bs ={}
mxx = 0
myy = 0
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1] += 1
    my[y-1] += 1
    mxx = max(mx[x-1], mxx)
    myy = max(my[y-1], myy)
    if y-1 in bs:
        bs[y-1].add(x-1)
    else:
        bs[y-1] = set([x-1])

vx = []
vy = []
for i,x in enumerate(mx):
    if x == mxx:
        vx.append(i)
for i,y in enumerate(my):
    if y == myy:
        vy.append(i)

a = 1

for i in vx:
    for j in vy:
        if i not in bs[j]:
            a = 0
            break
    else:
        continue
    break

ans = mxx + myy - a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())
mx=[[0,i] for i in range(W)]
my=[[0,i] for i in range(H)]
bs =[]
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1][0] += 1
    my[y-1][0] += 1
    bs.append((x-1,y-1))

mx.sort(reverse=True)
my.sort(reverse=True)

ans = 0
mxx = 0
myy = 0
for x in mx:
    mxx = max(mxx, x[0])
    if x[0] + 1 < mxx:
        break
    for y in my:
        myy = max(myy, y[0])
        if y[0] + 1 < myy:
            break
        s = x[0] + y[0]
        if (x[1],y[1]) in bs:
            s -= 1
        ans = max(ans, s)
print(ans)


Fixed submission:
H,W,M = map(int, input().split())
mx=[0] * W
my=[0] * H
bs ={}
mxx = 0
myy = 0
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1] += 1
    my[y-1] += 1
    mxx = max(mx[x-1], mxx)
    myy = max(my[y-1], myy)
    if y-1 in bs:
        bs[y-1].add(x-1)
    else:
        bs[y-1] = set([x-1])

vx = []
vy = []
for i,x in enumerate(mx):
    if x == mxx:
        vx.append(i)
for i,y in enumerate(my):
    if y == myy:
        vy.append(i)

a = 1

for i in vx:
    for j in vy:
        if i not in bs[j]:
            a = 0
            break
    else:
        continue
    break

ans = mxx + myy - a
print(ans)