Buggy python submission (verdict: Time Limit Exceeded):
H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=[]
for _ in range(H):
    boms.append([False]*W)
for _ in range(M):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms[h-1][w-1]=True

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if not boms[i][j]:
            print(maxh + maxw)
            exit()
print(maxh + maxw - 1)


Fixed submission:
import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if (i,j) in boms:
            continue
        print(maxh + maxw)
        exit()
print(maxh + maxw - 1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())

squares = []
for i in range(H):
    arr = []
    for j in range(W):
        arr.append(0)
    squares.append(arr)

boms = []
for i in range(M):
    hi, wi = map(int, input().split())
    squares[hi-1][wi-1] = 1
    boms.append([hi-1, wi-1])

row_sums = []
for i in range(H):
    row_sums.append(sum(squares[i]))

col_sums = []
for j in range(W):
    sum = 0
    for i in range(H):
        sum += squares[i][j]
    col_sums.append(sum)

row_max = max(row_sums)
col_max = max(col_sums)

row_hits = 0
for i in range(H):
    if row_sums[i] == row_max:
        row_hits += 1

col_hits = 0
for j in range(W):
    if col_sums[j] == col_max:
        col_hits += 1

hits = 0
for bom in boms:
    if row_sums[bom[0]] == row_max and col_sums[bom[1]] == col_max:
        hits += 1

if hits == row_hits * col_hits:
    print(row_max + col_max - 1)
else:
    print(row_max + col_max)


Fixed submission:
import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if (i,j) in boms:
            continue
        print(maxh + maxw)
        exit()
print(maxh + maxw - 1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())

squares = []
for i in range(H):
    arr = []
    for j in range(W):
        arr.append(0)
    squares.append(arr)

boms = []
for i in range(M):
    hi, wi = map(int, input().split())
    squares[hi-1][wi-1] = 1
    boms.append([hi-1, wi-1])

row_sums = []
for i in range(H):
    row_sums.append(sum(squares[i]))

col_sums = []
for j in range(W):
    sum = 0
    for i in range(H):
        sum += squares[i][j]
    col_sums.append(sum)

row_max = max(row_sums)
col_max = max(col_sums)

row_indexes = []
for i in range(H):
    if row_sums[i] == row_max:
        row_indexes.append(i)

col_indexes = []
for j in range(W):
    if col_sums[j] == col_max:
        col_indexes.append(j)

hits = 0
for bom in boms:
    if bom[0] in row_indexes and bom[1] in col_indexes:
        hits += 1

if hits == len(row_indexes) * len(col_indexes):
    print(row_max + col_max - 1)
else:
    print(row_max + col_max)


Fixed submission:
import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if (i,j) in boms:
            continue
        print(maxh + maxw)
        exit()
print(maxh + maxw - 1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().split())

squares = []
for i in range(H):
    arr = []
    for j in range(W):
        arr.append(0)
    squares.append(arr)

for i in range(M):
    hi, wi = map(int, input().split())
    squares[hi-1][wi-1] = 1

row_sums = []
for i in range(H):
    row_sums.append(sum(squares[i]))

col_sums = []
for j in range(W):
    sum = 0
    for i in range(H):
        sum += squares[i][j]
    col_sums.append(sum)

row_max = max(row_sums)
col_max = max(col_sums)

row_indexes = []
for i in range(H):
    if row_sums[i] == row_max:
        row_indexes.append(i)

col_indexes = []
for j in range(W):
    if col_sums[j] == col_max:
        col_indexes.append(j)

for i in row_indexes:
    for j in col_indexes:
        if squares[i][j] == 0:
            print(row_max + col_max)
            exit()

print(row_max + col_max - 1)

Fixed submission:
import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if (i,j) in boms:
            continue
        print(maxh + maxw)
        exit()
print(maxh + maxw - 1)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int, input().strip().split())

squares = []
for i in range(H):
    arr = []
    for j in range(W):
        arr.append(0)
    squares.append(arr)

for i in range(M):
    hi, wi = map(int, input().strip().split())
    squares[hi-1][wi-1] = 1

row_sums = []
for i in range(H):
    row_sums.append(sum(squares[i]))

col_sums = []
for j in range(W):
    sum = 0
    for i in range(H):
        sum += squares[i][j]
    col_sums.append(sum)

max = 0
for i in range(H):
    for j in range(W):
        total = row_sums[i] + col_sums[j]
        if squares[i][j] == 1:
            total -= 1
        if total > max:
            max = total

print(max)


Fixed submission:
import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if (i,j) in boms:
            continue
        print(maxh + maxw)
        exit()
print(maxh + maxw - 1)