qyliang/CodeNanoFix huggingface dataset:
Buggy code:
H, W, M = map(int, input().split())
hws = [list(map(lambda x :int(x)-1, input().split())) for _ in range(M)]

booms = [set() for _ in range(H)]

yoko = [0 for _ in range(W)]
tate = [0 for _ in range(H)]

for hw in hws:
    tate[hw[0]] += 1
    yoko[hw[1]] += 1
    booms[hw[0]].add(hw[1])
    
max_tate = max(tate)
max_yoko = max(yoko)


tate_candidates = []
yoko_candidates = []

for i in range(H):
    if tate[i] == max_tate:
        tate_candidates.append(i)
        
for i in range(W):
    if yoko[i] == max_yoko:
        yoko_candidates.append(i)

exist = 0
for tate_candidate in tate_candidates:
    for yoko_candidate in yoko_candidates:
        if yoko_candidate not in booms[tate_candidate]:
            exist = 1
			break
print(max_tate + max_yoko + (exist-1))


Fixed code:
H, W, M = map(int, input().split())
hws = [list(map(lambda x :int(x)-1, input().split())) for _ in range(M)]

booms = [set() for _ in range(H)]

yoko = [0 for _ in range(W)]
tate = [0 for _ in range(H)]

for hw in hws:
    tate[hw[0]] += 1
    yoko[hw[1]] += 1
    booms[hw[0]].add(hw[1])
    
max_tate = max(tate)
max_yoko = max(yoko)


tate_candidates = []
yoko_candidates = []

for i in range(H):
    if tate[i] == max_tate:
        tate_candidates.append(i)
        
for i in range(W):
    if yoko[i] == max_yoko:
        yoko_candidates.append(i)

exist = 0
for tate_candidate in tate_candidates:
    for yoko_candidate in yoko_candidates:
        if yoko_candidate not in booms[tate_candidate]:
            exist = 1
            break
    else:
        continue
    break
print(max_tate + max_yoko + (exist-1))
Buggy code:

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

h_b_list = [0 for i in range(h)]
w_b_list = [0 for i in range(w)]

targets = set()
for i in range(m):
  bh, bw = map(int, input().split())
  targets.add(bh, bw)
  h_b_list[bh-1] += 1
  w_b_list[bw-1] += 1
  
h_max = max(h_b_list)
w_max = max(w_b_list)

h_cans = []
w_cans = []
for i in range(h):
  if h_b_list[i] == h_max:
    h_cans.append(i)
    
for i in range(w):
  if w_b_list[i] == w_max:
    w_cans.append(i)

for hi in h_cans:
  for wi in w_cans:
    if (hi+1, wi+1) not in targets:
      print(h_max+w_max)
      exit()
else:
  print(h_max+w_max-1)



Fixed code:

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

h_b_list = [0 for i in range(h)]
w_b_list = [0 for i in range(w)]

targets = set()
for i in range(m):
  bh, bw = map(int, input().split())
  targets.add((bh, bw))
  h_b_list[bh-1] += 1
  w_b_list[bw-1] += 1
  
h_max = max(h_b_list)
w_max = max(w_b_list)

h_cans = []
w_cans = []
for i in range(h):
  if h_b_list[i] == h_max:
    h_cans.append(i)
    
for i in range(w):
  if w_b_list[i] == w_max:
    w_cans.append(i)

for hi in h_cans:
  for wi in w_cans:
    if (hi+1, wi+1) not in targets:
      print(h_max+w_max)
      exit()
else:
  print(h_max+w_max-1)
Buggy code:
import collections

a = list(map(int,input().split()))
c = []
d = []
for i in range(a[2]):
    b = list(map(int,input().split()))
    c.append(b[0])
    d.append(b[1])

ans1 = 0
ans2 = 0

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

ans1 += gc
ans2 += hc

for i in range(a[0]):
    if g[i] == g:
        h[i] = -1
    if h[i] == h:
        g[i] = -1    

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

if g == '-1':
    g = e.most_common()[1][0]
    gc = e.most_common()[1][1]
if h == '-1':
    h = f.most_common()[1][0]
    hc = f.most_common()[1][1]

ans1 += gc
ans2 += hc

if ans1 > ans2:
    print(str(ans1))
else:
    print(str(ans2))

Fixed code:
import collections
import copy

a = list(map(int,input().split()))
c = []
d = []
for i in range(a[2]):
    b = list(map(int,input().split()))
    c.append(b[0])
    d.append(b[1])

ans1 = 0
ans2 = 0

cp = copy.copy(c)
dp = copy.copy(d)

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]
ans1 += gc
ans2 += hc
for i in range(a[2]):
    if cp[i] == g:
        d[i] = -1
    if dp[i] == h:
        c[i] = -1
e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

if g == -1:
    if gc == a[2]:
        gc = 0
    else:
        g = e.most_common()[1][0]
        gc = e.most_common()[1][1]
if h == -1:
    if hc == a[2]:
        hc = 0
    else:
        h = f.most_common()[1][0]
        hc = f.most_common()[1][1]

ans1 += hc
ans2 += gc
if ans1 > ans2:
    print(str(ans1))
else:
    print(str(ans2))
Buggy code:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
temp=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
  temp[i]=[s[i],t[i]]
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)
c=0
for i in range(len(maxs)):
  for j in range(len(maxt)):
    if (maxs[i]+1,maxt[j]+1) not in temp:
      print(ans)
      exit()
else:
  print(ans-1)

Fixed code:
h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
temp=set()
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
  temp.add((s[i],t[i]))
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)

if len(maxs)*len(maxt)>m:
  print(ans)
else:
  for i in range(len(maxs)):
    for j in range(len(maxt)):
      if (maxs[i]+1,maxt[j]+1) not in temp:
        print(ans)
        exit()
  else:
    print(ans-1)
Buggy code:
h, w, m = map(int, input().split(' '))
H = [0 for _ in range(h+1)]
W = [0 for _ in range(w+1)]
bomb = set()
for m in range(m):
  i, j = map(int, input().split(' '))
  bomb.add((i, j))
  H[i] += 1
  W[j] += 1
  
max_h = max(H)
max_w = max(W)
target_h = [i for i, v in enumerate(H) if v == max_h]
target_w = [i for i, v in enumerate(W) if v == max_w]

for m in target_h:
  for n in target_w:
    if (m, n) not in bomb:
      print(max_h + max_w)
      break
print(max_h + max_w - 1)

Fixed code:
import sys

h, w, m = map(int, input().split(' '))
H = [0 for _ in range(h+1)]
W = [0 for _ in range(w+1)]
bomb = set()
for m in range(m):
  i, j = map(int, input().split(' '))
  bomb.add((i, j))
  H[i] += 1
  W[j] += 1
  
max_h = max(H)
max_w = max(W)
target_h = [i for i, v in enumerate(H) if v == max_h]
target_w = [i for i, v in enumerate(W) if v == max_w]

for m in target_h:
  for n in target_w:
    if (m, n) not in bomb:
      print(max_h + max_w)
      sys.exit()
	
print(max_h + max_w - 1)
Buggy code:
from collections import defaultdict

H,W,M=map(int,input().split())
hw = defaultdict(int)
sum1=[0]*H
sum2=[0]*W
for i in range(M):
  h,w=map(int,input().split())
  hw[(h-1,w-1)] += 1
  sum1[h-1] += 1
  sum2[w-1] += 1

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

max1,max2=set(sum1[0]),set(sum2[0])
for i in range(1,H):
  if sum1[i][1]<sum1[0][1]:
    break
  else:
    max1.add(sum1[i])
    
for i in range(1,W):
  if sum2[i][1]<sum2[0][1]:
    break
  else:
    max2.add(sum2[i])

ans = sum1[0][1]+sum2[0][1]
for k in hw.keys():
  h,w=k
  if h in max1 and w in max2:
    ans -= 1
    break
print(ans)

Fixed code:
from collections import defaultdict

H,W,M=map(int,input().split())
hw = defaultdict(int)
sum1=[0]*H
sum2=[0]*W
for i in range(M):
  h,w=map(int,input().split())
  hw[(h-1,w-1)] += 1
  sum1[h-1] += 1
  sum2[w-1] += 1

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

max1,max2=set([sum1[0][0]]),set([sum2[0][0]])
for i in range(1,H):
  if sum1[i][1]<sum1[0][1]:
    break
  else:
    max1.add(sum1[i][0])
    
for i in range(1,W):
  if sum2[i][1]<sum2[0][1]:
    break
  else:
    max2.add(sum2[i][0])

ans = sum1[0][1]+sum2[0][1]
count=0
for k in hw.keys():
  h,w=k
  if h in max1 and w in max2:
    count += 1
    
if count < len(max1)*len(max2):
  print(ans)
else:
  print(ans-1)
Buggy code:
H,W,N=[int(s) for s in input().split()]
hls=[0 for _ in range(H+1)]
wls=[0 for _ in range(W+1)]
bombs=[set() for _ in range(H+1)]
for _ in range(N):
  h,w=[int(s) for s in input().split()]
  hls[h]+=1
  wls[w]+=1
  bombs[h].add(w)
hmax=max(hls)
wmax=max(wls)
hmaxls=[i for i in range(H+1) if hls[i]==hmax]
wmaxls=[i for i in range(W+1) if wls[i]==wmax]
for h,w in zip(hmaxls,wmaxls):
  if not(w in bombs[h]):
    print(hmax+wmax)
    exit()
else:
  print(hmax+wmax-1)

Fixed code:
import itertools
H,W,N=[int(s) for s in input().split()]
hls=[0 for _ in range(H+1)]
wls=[0 for _ in range(W+1)]
bombs=[set() for _ in range(H+1)]
for _ in range(N):
  h,w=[int(s) for s in input().split()]
  hls[h]+=1
  wls[w]+=1
  bombs[h].add(w)
hmax=max(hls)
wmax=max(wls)
hmaxls=[i for i in range(H+1) if hls[i]==hmax]
wmaxls=[i for i in range(W+1) if wls[i]==wmax]
for h,w in itertools.product(hmaxls,wmaxls):
  if not(w in bombs[h]):
    print(hmax+wmax)
    exit()
else:
  print(hmax+wmax-1)
Buggy code:
H,W,M = map(int,input().split())
hs = [0]*H
ws = [0]*W
s = [[0 for i in range(W)] for j in range(H)]
for i in range(M):
    h,w = map(int,input().split())
    hs[h-1] += 1
    ws[w-1] += 1
    s[h-1][w-1] = 1

mh = 0; mw = 0
for i in range(H):
    mh = max(mh,hs[i])
for i in range(W):
    mw = max(mw,ws[i])

Is = []; Js = []
for i in range(H):
    if mh ==  hs[i]:
        Is.append(i)
for i in range(W):
    if mw == ws[i]:
        Js.append(i)
ans = mh + mw

for i in range(H):
    for j in range(W):
        if s[i][j] == 1:
            continue
        print(ans)
        exit()
print(ans-1)

Fixed code:
H,W,M = map(int,input().split())
hs = [0]*H
ws = [0]*W
s = set()
for i in range(M):
    h,w = map(int,input().split())
    hs[h-1] += 1
    ws[w-1] += 1
    s.add((h-1,w-1))

mh = 0; mw = 0
for i in range(H):
    mh = max(mh,hs[i])
for i in range(W):
    mw = max(mw,ws[i])

Is = []; Js = []
for i in range(H):
    if mh ==  hs[i]:
        Is.append(i)
for i in range(W):
    if mw == ws[i]:
        Js.append(i)
ans = mh + mw
flag = 0
for i in Is:
    for j in Js:
        if (i,j) in s:
            continue
        print(ans)
        exit()
print(ans-1)
Buggy code:
import sys
HK,WK,M = map(int, input().split())
W = [0] * WK
H = [0] * HK
HW = [[0 for i in range(WK+1)] for _ in range(HK+1)]
# 3*10^5

for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[h][w] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if HW[h][w] == 0:
            print(answer)
            sys.exit(0)
print(answer-1)

Fixed code:
import sys
HK,WK,M = map(int, input().split())
W = [0] * (WK + 1)
H = [0] * (HK + 1)
HW = {}
# 3*10^5

for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[(h,w)] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if not (h,w) in HW:
            print(answer)
            sys.exit(0)
print(answer-1)
Buggy code:
H, W, M = map(int, input().split())

h = [0] * H
w = [0] * W
boms = set()

for _ in range(M):
    x, y = map(int, input().split())
    h[x - 1] += 1
    w[y - 1] += 1
    boms.add((x, y))

h_max = max(h)
w_max = max(w)

h_idx = [x + 1 for x, y in enumerate(h) if y == h_max]
w_idx = [x + 1 for x, y in enumerate(w) if y == w_max]

minus = -1
for x in h_idx:
    for y in w_idx:
        if not (x, y) in boms:
            minus = 0
            break

print(h_max + w_idx + minus)

Fixed code:
H, W, M = map(int, input().split())

h = [0] * H
w = [0] * W
boms = set()

for _ in range(M):
    x, y = map(int, input().split())
    h[x - 1] += 1
    w[y - 1] += 1
    boms.add((x, y))

h_max = max(h)
w_max = max(w)

h_idx = [x + 1 for x, y in enumerate(h) if y == h_max]
w_idx = [x + 1 for x, y in enumerate(w) if y == w_max]

minus = -1
for x in h_idx:
    for y in w_idx:
        if not (x, y) in boms:
            minus = 0
            break

print(h_max + w_max + minus)
Buggy code:
import sys

h, w, m = map(int, input().split())
row = [0]*h
col = [0]*w
bomb = set()
for x in sys.stdin.readlines():
    H, W = map(int, input().split())
    bomb.add((H-1, W-1))
    row[H-1] += 1
    col[W-1] += 1

maxrow = max(row)
maxcol = max(col)
ans = maxcol + maxrow - 1
p, q = [], []
for i in range(h):
    if row[i] == maxrow:
        p.append(i)
for i in range(w):
    if col[i] == maxcol:
        q.append(i)

for i in p:
    for j in q:
        if (i, j) not in bomb:
            print(ans + 1)
            exit()
print(ans)


Fixed code:
import sys


def main():
    h, w, m = map(int, input().split())
    row = [0]*h
    col = [0]*w
    bomb = set()
    for x in sys.stdin.readlines():
        H, W = map(int, x.split())
        bomb.add((H-1, W-1))
        row[H-1] += 1
        col[W-1] += 1

    maxrow = max(row)
    maxcol = max(col)
    ans = maxcol + maxrow - 1
    p, q = [], []
    for i in range(h):
        if row[i] == maxrow:
            p.append(i)
    for i in range(w):
        if col[i] == maxcol:
            q.append(i)

    for i in p:
        for j in q:
            if (i, j) not in bomb:
                print(ans + 1)
                exit()
    print(ans)


if __name__ == "__main__":
    main()
Buggy code:
import sys
from sys import flags

h, w, m = map(int, input().split())
row = [0]*h
col = [0]*w
bomb = set()
for x in sys.stdin.readlines():
    H, W = map(int, input().split())
    bomb.add((H-1, W-1))
    row[H-1] += 1
    col[W-1] += 1

maxrow = max(row)
maxcol = max(col)
ans = maxcol + maxrow - 1

p, q = [], []
for i in range(m):
    if bomb[i][0] == maxrow:
        p.append(i)
    if bomb[i][1] == maxcol:
        q.append(i)

for i in p:
    for j in q:
        if (i, j) not in bomb:
            print(ans + 1)
            exit()
print(ans)


Fixed code:
import sys

h, w, m = map(int, input().split())
row = [0]*h
col = [0]*w
bomb = set()
for x in range(m):
    H, W = map(int, input().split())
    bomb.add((H-1, W-1))
    row[H-1] += 1
    col[W-1] += 1

maxrow = max(row)
maxcol = max(col)
ans = maxcol + maxrow - 1
p, q = [], []
for i in range(h):
    if row[i] == maxrow:
        p.append(i)
for i in range(w):
    if col[i] == maxcol:
        q.append(i)

for i in p:
    for j in q:
        if (i, j) not in bomb:
            print(ans + 1)
            exit()
print(ans)
Buggy code:
from collections import defaultdict
a,b,m=map(int,input().split())
r=defaultdict(int)
c=defaultdict(int)
d=defaultdict(int)
for i in range(m):
  x,y=map(int,input().split())
  d[(x,y)]=1
  r[x]+=1
  c[y]+=1
z=list()
zz=list()
x=max(r,key=r.get)
y=max(c,key=c.get)
for i in r.keys():
  if r[i]==r[x]:
    z.append(r[i])
for i in c.keys():
  if c[i]==c[y]:
    zz.append(c[i])
flag=False
for i in z:
  for j in zz:
    if d[(i,j)]==0:
      flag=True
      break
if flag==False:
  print(r[x]+c[y]-1)
else:
  print(r[x]+c[y])
  
  


Fixed code:
from collections import defaultdict
a,b,m=map(int,input().split())
r=defaultdict(int)
c=defaultdict(int)
d=defaultdict(int)
for i in range(m):
  x,y=map(int,input().split())
  d[(x,y)]=1
  r[x]+=1
  c[y]+=1
z=list()
zz=list()
x=max(r,key=r.get)
y=max(c,key=c.get)
for i in r.keys():
  if r[i]==r[x]:
    z.append(i)
for i in c.keys():
  if c[i]==c[y]:
    zz.append(i)
flag=False
for i in z:
  for j in zz:
    if d[(i,j)]==0:
      flag=True
      break
if flag==False:
  print(r[x]+c[y]-1)
else:
  print(r[x]+c[y])
Buggy code:
from collections import defaultdict
n,m,k=map(int,input().split())
points=set()
row=defaultdict(int)
col=defaultdict(int)
for i in range(k):
    a,b=map(int,input().split())
    points.add((a,b))
    row[a]+=1
    col[b]+=1
m1=max(row.values())
m2=max(col.values())
l1=[]
l2=[]
for i in row:
    if row[i]==m1:
        l1.append(i)
for i in col:
    if col[i]==m2:
        l2.append(i)
ans=m2+m1-1
for i in l1:
    for j in l2:
        if (i,j) not in points:
            print(i,j)
            ans+=1
            print(ans)
            quit()
print(ans)




Fixed code:
from collections import defaultdict
n,m,k=map(int,input().split())
points=set()
row=defaultdict(int)
col=defaultdict(int)
for i in range(k):
    a,b=map(int,input().split())
    points.add((a,b))
    row[a]+=1
    col[b]+=1
m1=max(row.values())
m2=max(col.values())
l1=[]
l2=[]
for i in row:
    if row[i]==m1:
        l1.append(i)
for i in col:
    if col[i]==m2:
        l2.append(i)
ans=m2+m1-1
for i in l1:
    for j in l2:
        if (i,j) not in points:
           
            ans+=1
            print(ans)
            quit()
print(ans)
Buggy code:
import numpy as np

h,w,m = map(int,input().split())
t = list(list(map(int,input().split())) for _ in range(m))

H = [0] * h
W = [0] * w
for x,y in t:
    H[x-1] += 1
    W[y-1] += 1
H_max = max(H)
W_max = max(W)

H_index = [h for h,i in enumerate(H) if i == H_max]
W_index = [w for w,j in enumerate(W) if j == W_max]

ans = H_max + W_max

for r in H_index:
    for c in W_index:
        if (r, c) not in t:
            print(ans)
            exit()
print(ans - 1)

Fixed code:
import numpy as np

h,w,m = map(int,input().split())
t = list(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(m))

H = [0] * h
W = [0] * w
for x,y in t:
    H[x] += 1
    W[y] += 1
H_max = max(H)
W_max = max(W)

H_index = [x for x,i in enumerate(H) if i == H_max]
W_index = [y for y,j in enumerate(W) if j == W_max]

ans = H_max + W_max

t = set(t)
for r in H_index:
    for c in W_index:
        if (r, c) not in t:
            print(ans)
            exit()
print(ans - 1)
Buggy code:
import numpy as np
H,W,M=map(int, input().split())
hl=np.array([0 for i in range(H+1)])
wl=np.array([0 for i in range(W+1)])
ms=[]
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.append([h,w])
a=max(hl)
b=max(wl)
hmax=[]
wmax=[]
for i in range(len(hl))l:
    if hl[i]==a:
        hmax.append(i)
for i in range(len(wl))l:
    if wl[i]==a:
        wmax.append(i)
# hmax=np.where(hl == hl.max())[0]
# wmax=np.where(wl == wl.max())[0]
bl=False
if len(hmax)*len(wmax)>M:
    bl=True
else:
    for x in hmax:
        for y in wmax:
            if [x,y] not in ms:
                bl=True
                break
        if bl:
            break
if bl:
    print(a+b)
else:
    print(a+b-1)

Fixed code:
import numpy as np
H,W,M=map(int, input().split())
hl=np.array([0 for i in range(H+1)])
wl=np.array([0 for i in range(W+1)])
ms=set()
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.add((h,w))
a=max(hl)
b=max(wl)
hmax=[]
wmax=[]
for i in range(len(hl)):
    if hl[i]==a:
        hmax.append(i)
for i in range(len(wl)):
    if wl[i]==b:
        wmax.append(i)
a=max(hl)
b=max(wl)
bl=False
if len(hmax)*len(wmax)>M:
    bl=True
else:
    for x in hmax:
        for y in wmax:
            if (x,y) not in ms:
                bl=True
                break
        if bl:
            break
if bl:
    print(a+b)
else:
    print(a+b-1)
Buggy code:
H, W, M = map(int, input().split())
h_dic, w_dic = {}, {}
m = set()
for i in range(M):
    h_i, w_i = map(int, input().split())
    m.add((h_i, w_i))
    if h_i in h_dic:
        h_dic[h_i] += 1
    else:
        h_dic[h_i] = 1
    if w_i in w_dic:
        w_dic[w_i] += 1
    else:
        w_dic[w_i] = 1
        
max_h_items = [[0,0]]
max_w_items = [[0,0]]

for key, value in h_dic.items():
    if value > max_h_items[0][1]:
        max_h_items = [[key, value]]
    elif value == max_h_items[0][1]:
        max_h_items.append([key, value])
for key, value in w_dic.items():
    if value > max_w_items[0][1]:
        max_w_items = [[key, value]]
    elif value == max_w_items[0][1]:
        max_w_items.append([key, value])
s = max_h_items[0][1] + max_w_items[0][1]
for mh in max_h_items:
    for mw in max_w_items:
        if (mh[0], mw[0]) in m:
            s = mh[1]+mw[1]-1
print(s)

Fixed code:
H, W, M = map(int, input().split())
h_dic, w_dic = {}, {}
m = set()
for i in range(M):
    h_i, w_i = map(int, input().split())
    m.add((h_i, w_i))
    if h_i in h_dic:
        h_dic[h_i] += 1
    else:
        h_dic[h_i] = 1
    if w_i in w_dic:
        w_dic[w_i] += 1
    else:
        w_dic[w_i] = 1
        
max_h_items = [[0,0]]
max_w_items = [[0,0]]

for key, value in h_dic.items():
    if value > max_h_items[0][1]:
        max_h_items = [[key, value]]
    elif value == max_h_items[0][1]:
        max_h_items.append([key, value])
for key, value in w_dic.items():
    if value > max_w_items[0][1]:
        max_w_items = [[key, value]]
    elif value == max_w_items[0][1]:
        max_w_items.append([key, value])
s = max_h_items[0][1] + max_w_items[0][1] - 1
for mh in max_h_items:
    for mw in max_w_items:
        if (mh[0], mw[0]) not in m:
            s = mh[1]+mw[1]
            print(s)
            break
    if s == max_h_items[0][1] + max_w_items[0][1]:
        break
if s == max_h_items[0][1] + max_w_items[0][1] - 1:
    print(s)
Buggy code:
h,w,m=map(int,input().split())
a=dict()
b=dict()
points=set()
for i in range (m):
    x,y=map(int,input().split())
    points.add((x,y))
    if x in a:
        a[x]+=1
    else:
        a[x]=1
    if y in b:
        b[y]+=1
    else:
        b[y]=1
m1=max(a.values())
m2=max(b.values())
s1=set()
s2=set()
for i in a:
    if a[i]==m1:
        s1.add(i)
for i in b:
    if b[i]==m2:
        s2.add(i)
r=set()
for i in points:
    if i[0] in s1 and i[1] in s2:
        r.add(i)
if len(r)==len(s1)*len(s2):
    print(m1*m2-1)
else:
    print(m1*m2)

Fixed code:
h,w,m=map(int,input().split())
a=dict()
b=dict()
points=set()
for i in range (m):
    x,y=map(int,input().split())
    points.add((x,y))
    if x in a:
        a[x]+=1
    else:
        a[x]=1
    if y in b:
        b[y]+=1
    else:
        b[y]=1
m1=max(a.values())
m2=max(b.values())
s1=set()
s2=set()
for i in a:
    if a[i]==m1:
        s1.add(i)
for i in b:
    if b[i]==m2:
        s2.add(i)
r=set()
for i in points:
    if i[0] in s1 and i[1] in s2:
        r.add(i)
if len(r)==len(s1)*len(s2):
    print(m1+m2-1)
else:
    print(m1+m2)
Buggy code:
h,w,m=map(int,input().split())
H=[0 for i in range(h)]
W=[0 for i in range(w)]
s=set()
for i in range(m):
    a,b=map(int,input().split())
    H[a-1]+=1
    W[b-1]+=1
    s.add((a,b))
hma=max(H)
wma=max(W)
h_index=[x for x, v in enumerate(H) if v==hma]
w_index=[y for y, v in enumerate(W) if v==wma]
val=0
for p in h_index:
    for q in w_index:
        if (p+1,q+1) in s:
            val=-1
print(hma+wma+val)

Fixed code:
h,w,m=map(int,input().split())
H=[0 for i in range(h)]
W=[0 for i in range(w)]
s=set()
for i in range(m):
    a,b=map(int,input().split())
    H[a-1]+=1
    W[b-1]+=1
    s.add((a,b))
hma=max(H)
wma=max(W)
h_index=[x for x, v in enumerate(H) if v==hma]
w_index=[y for y, v in enumerate(W) if v==wma]
val=-1
for p in h_index:
    for q in w_index:
        if not (p+1,q+1) in s:
            val=0
            break
print(hma+wma+val)