TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
h,w,m=map(int,input().split())
r=dict()
c=dict()
pos=[]
rmax=0
cmax=0
for i in range(m):
    row,col=map(int,input().split())
    if(row in r):
        r[row]+=1
        rmax=max(r[row],rmax)
    else:
        r[row]=1
        rmax=max(r[row],rmax)
    if(col in c):
        c[col]+=1
        cmax=max(c[col],cmax)
    else:
        c[col]=1
        cmax=max(c[col],cmax)
    pos.append(str(row)+str(col))
    
sorted(r.items(),key=lambda x:x[1])
sorted(c.items(),key=lambda x:x[1])
ans=-100
for i in r.keys():
    if(i<rmax):
        continue
    for j in c.keys():
        if(j<cmax):
            continue
        tmp=r[i]+c[j]
        if((str(i)+str(j)) in pos):
            tmp-=1
        ans=max(ans,tmp)
        
print(ans)

h,w,m=map(int,input().split())
row=[0 for i in range(h)]
col=[0 for i in range(w)]
a=[]
for i in range(m):
    r,c=map(lambda x:int(x)-1,input().split())
    a.append([r,c])
    row[r]+=1
    col[c]+=1
rmax=max(row)
cmax=max(col)
ans=rmax+cmax
flag=row.count(rmax)*col.count(cmax)
for i,j in a:
    if(row[i]==rmax and col[j]==cmax):
        flag-=1
if(flag==0):
    ans-=1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import heapq
def main():
    H, W, M = map(int, input().split())

    bn_h = {}
    bn_v = {}

    for i in range(M):
        h, w = map(int, input().split())
        bn_h.setdefault(h, set())
        bn_h[h].add(w)
        bn_v.setdefault(w, set())
        bn_v[w].add(h)

    b1 = sorted(bn_h.items(), key = lambda x:len(x[1]), reverse=True)
    b2 = sorted(bn_v.items(), key = lambda x:len(x[1]), reverse=True)

    m1 = len(b1[0][1])
    m2 = len(b2[0][1])

    max_result = 0
    for i in b1:
        h, sh = i
        if len(sh) < m1:
            break
        for j in b2:
            v, sv = j
            if len(sv) < m2:
                break
            result = len(sh) + len(sv) - 1
            if h not in sv:
                result += 1
            flag = True
            max_result = max(max_result, result)
            if flag = True:
                break
        if flag = True:
            break
    print(max_result)

if __name__ == '__main__':
    main()

import heapq
def main():
    H, W, M = map(int, input().split())

    bn_h = {}
    bn_v = {}

    for i in range(M):
        h, w = map(int, input().split())
        bn_h.setdefault(h, set())
        bn_h[h].add(w)
        bn_v.setdefault(w, set())
        bn_v[w].add(h)

    b1 = sorted(bn_h.items(), key = lambda x:len(x[1]), reverse=True)
    b2 = sorted(bn_v.items(), key = lambda x:len(x[1]), reverse=True)

    m1 = len(b1[0][1])
    m2 = len(b2[0][1])

    flag = False
    max_result = 0
    for i in b1:
        h, sh = i
        if len(sh) < m1:
            break
        for j in b2:
            v, sv = j
            if len(sv) < m2:
                break
            result = len(sh) + len(sv) - 1
            if h not in sv:
                result += 1
                flag = True
            max_result = max(max_result, result)
            if flag == True:
                break
        if flag == True:
            break
    print(max_result)

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
for p in P:
    p[0] -= 1 
    p[1] -= 1
cnth = [0]*H
cntw = [0]*W
ans = 0
for p in P:
    cnth[p[0]] += 1
for p in P:
    cntw[p[1]] += 1
mxh = max(cnth)
mxw = max(cntw)
f = False
for p in P:
    if cnth[p[0]] == mxh:
        if cntw[p[1]] == mxw:
            f = True
if f:
    ans = mxh + mxw -1
else:
    ans = mxh + mxw
print(ans)

H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
for p in P:
    p[0] -= 1 
    p[1] -= 1
cnth = [0]*H
cntw = [0]*W
ans = 0
for p in P:
    cnth[p[0]] += 1
for p in P:
    cntw[p[1]] += 1 
mxh = max(cnth)
mxw = max(cntw)
f = False
for p in P:
    if cnth[p[0]] == mxh and cntw[p[1]] == mxw:
        f = True
if f:
    ans = mxh + mxw -1
else:
    ans = mxh + mxw
print(ans)

H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
for p in P:
    p[0] -= 1
    p[1] -= 1
cnth = [0]*H
cntw = [0]*W
ans = 0
for p in P:
    cnth[p[0]] += 1
for p in P:
    cntw[p[1]] += 1
mxh = max(cnth)
mxw = max(cntw)
cntx = 0
for p in P:
    if cnth[p[0]] == mxh and cntw[p[1]] == mxw:
        cntx += 1
if cntx == cnth.count(mxh) * cntw.count(mxw):
    ans = mxh + mxw -1
else:
    ans = mxh + mxw
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import numpy as np

H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = np.zeros((H+10, W+10))

for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP[hh - 1][ww - 1] = 1

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0


print(hhh + www - (1 - check))


H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = set()
for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP.add((hh - 1, ww - 1))

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

for i in hhhh:
    for j in wwww:
        if (i, j) not in DP:
            print(hhh + www)
            exit()
print(hhh + www - 1)


Verdicts: Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
h,w,m = map(int, input().split())
h_t = []
w_t = []
s = []
for i1 in range(h):
  h_t.append(0)
for i2 in range(w):
  w_t.append(0)
for i in range(h):
  s.append([])
  for j in range(w):
    s[i].append(0)
for i3 in range(m):
  hi,wi = map(int, input().split())
  h_t[hi-1] += 1
  w_t[wi-1] += 1
  s[hi-1][wi-1] = 1
hmax = max(h_t)
wmax = max(w_t)
hmaxi = h_t.index(max(h_t))
wmaxi = w_t.index(max(w_t))
if s[hmaxi][wmaxi] == 1:
  print(hmax + wmax-1)
else:
  print(hmax + wmax)


import sys
h,w,m = map(int, input().split())
h_t = [0 for _ in range(h)]
w_t = [0 for _ in range(w)]
t = []
for _ in range(m):
  hi,wi = map(int, input().split())
  h_t[hi-1] += 1
  w_t[wi-1] += 1
  t.append([hi-1,wi-1])
hmax = max(h_t)
wmax = max(w_t)
hmaxi = [i1 for i1 in range(h) if h_t[i1] == hmax]
wmaxi = [i2 for i2 in range(w) if w_t[i2] == wmax]
c = len(hmaxi)*len(wmaxi)
d = 0
for ht,wt in t:
  if h_t[ht] == hmax:
    if w_t[wt] == wmax:
      d += 1
if c ==d:
  print(hmax + wmax-1)
else:
  print(hmax + wmax)

Verdicts: Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
H,W,M = [int(x) for x in input().split()]
hw = []
hNum = [0]*H
wNum = [0]*W

for i in range(M):
    h,w = [int(x) for x in input().split()]
    hw.append([h,w])
    hNum[h-1]+=1
    wNum[w-1]+=1

hmax = max(hNum)
hMaxList = []
wmax = max(wNum)
wMaxList = []

for i in range(H):
    if(hmax == hNum[i]):
        hMaxList.append(i)
for i in range(W):
    if(wmax == wNum[i]):
        wMaxList.append(i)

ans = wmax + hmax -1
if((M <= H and hmax ==  1) or (M <= W and wmax ==  1 )):
    ans += 1
flag = False
for i in hMaxList:
    if(not i in wMaxList):
        flag = True
        

if(flag):
    print(ans)
else:
    print(ans-1)


H,W,M = [int(x) for x in input().split()]
hw = []
hNum = [0]*H
wNum = [0]*W

for i in range(M):
    h,w = [int(x) for x in input().split()]
    hw.append([h,w])
    hNum[h-1]+=1
    wNum[w-1]+=1

hmax = max(hNum)
hMaxList = []
wmax = max(wNum)
wMaxList = []

for i in range(H):
    if(hmax == hNum[i]):
        hMaxList.append(i)
for i in range(W):
    if(wmax == wNum[i]):
        wMaxList.append(i)

ans = wmax + hmax
count = 0
for i in hw:
    if(hNum[i[0]-1] == hmax and wNum[i[1]-1] == wmax):
        count += 1
# if(hNum.count(hmax) * wNum.count(wmax) == count):
if(len(hMaxList) * len(wMaxList) == count):
    ans -= 1
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
H,W,M=map(int,input().split())
l = [ list(map(int,input().split(" "))) for i in range(M)]
h=[0]*H
w=[0]*W
for i in range(M):
  h[l[i][0]-1]=h[l[i][0]-1]+1
  w[l[i][1]-1]=w[l[i][1]-1]+1
maxh=max(h)
maxw=max(w)
max_h=[i for i,k in enumerate(h) if k==maxh]
max_w=[i for i,k in enumerate(w) if k==maxw]
flag=0
for i in max_h:
  for j in max_w:
    c=0
    for k in range(M):
      if i==l[k][0]-1 or j==l[k][1]-1:
        c=1
    if c==0:
      flag=1
      print(maxh+maxw)
      
    if flag==1:
      break
  if flag==1:
    break
if flag==0:
  print(maxh+maxw-1)
    
      
      


H,W,M=map(int,input().split())
l = [ list(map(int,input().split(" "))) for i in range(M)]
h=[0]*H
w=[0]*W
for i in range(M):
  h[l[i][0]-1]=h[l[i][0]-1]+1
  w[l[i][1]-1]=w[l[i][1]-1]+1
maxh=max(h)
maxw=max(w)
max_h=[i for i,k in enumerate(h) if k==maxh]
max_w=[i for i,k in enumerate(w) if k==maxw]
flag=0
for i in max_h:
  for j in max_w:
    c=0
    for k in range(M):
      if i==l[k][0]-1 or j==l[k][1]-1:
        c=1
    if c==0:
      flag=1
      print(maxh+maxw)
      
    if flag==1:
      break
  if flag==1:
    break
if flag==0:
  print(maxh+maxw-1)
    
      
      


H,W,M=map(int,input().split())
l = [ list(map(int,input().split(" "))) for i in range(M)]
h=[0]*H
w=[0]*W
for i in range(M):
    h[l[i][0]-1]+=1
    w[l[i][1]-1]+=1
maxh=max(h)
maxw=max(w)
hlist=[]
wlist=[]
for i in range(H):
    if h[i]==maxh:
        hlist.append(i)
for i in range(W):
    if w[i]==maxw:
        wlist.append(i)
c=0
for i in range(M):
  if h[l[i][0]-1]==maxh and w[l[i][1]-1]==maxw:
    c+=1
if len(hlist)*len(wlist)==c:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
h,w,m=list(map(int,input().split()))

bom=[[0 for i in range(w+1)] for i in range(h+1)]

for i in range(m):
  h,w=list(map(int,input().split()))
  bom[h][w]=1


from itertools import accumulate
for i in range(h+2):
  bom[i]=list(accumulate(bom[i]))


for i in range(1,h+2):
  for j in range(w+1):
    bom[i][j]=bom[i][j]+bom[i-1][j]

ans=0  
for i in range(1,h+2):
  for j in range(1,w+1):
    ans=max(ans,bom[h][w]-(bom[i-1][j-1]+bom[i-1][w]-bom[i-1][j]+bom[h][j-1]-bom[i][j-1]+bom[h][w]-bom[i][w]-bom[h][j]+bom[i][j]))
print(ans)


  

h,w,m=map(int,input().split())
h=[]
w=[]
for i in range(m):
  h_,w_=map(int,input().split())
  h.append(h_)
  w.append(w_)
from collections import Counter
dic_h=Counter(h)
dic_w=Counter(w)
max_h=max(dic_h.values())
max_w=max(dic_w.values())

h_set=set()
w_set=set()
for i in dic_h:
  if dic_h[i]==max_h:
    h_set.add(i)
for j in dic_w:
  if dic_w[j]==max_w:
    w_set.add(j)

cnt=0
for i in range(m):
  if h[i] in h_set and w[i] in w_set:
    cnt+=1
if len(h_set)*len(w_set)>cnt:
  print(max_h+max_w)
else:
  print(max_h+max_w-1)
  
  


Verdicts: Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
R, C, T = map(int, input().split())
RC = []
for _ in range(T):
    RC.append(list(map(int, input().split())))
TR = [0] * (R + 1)
TC = [0] * (C + 1)
for r, c in RC:
    TR[r] += 1
    TC[c] += 1
mxr = max(TR)
mxc = max(TC)
ct = TR.count(mxr) * TC.count(mxc) - len([0 for r, c in RC if TR[r] == mxr and TC[c] == mxc])
print("Answer: ", mxc + mxr - (ct == 0))

R, C, T = map(int, input().split())
RC = []
for _ in range(T):
    RC.append(list(map(int, input().split())))
TR = [0] * (R + 1)
TC = [0] * (C + 1)
mxr=0
mxc=0
for r, c in RC:
    TR[r] += 1
    TC[c] += 1
    if(TR[r]>mxr):
      mxr=TR[r]
    if(TC[c]>mxc):
      mxc=TC[c]
ct = TR.count(mxr) * TC.count(mxc) - len([0 for r, c in RC if TR[r] == mxr and TC[c] == mxc])
print(mxc + mxr - (ct == 0))

Verdicts: Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import collections
import numpy as np

h, w, m = map(int, input().split())
lst_ = []
for i in range(m):
    h, m = map(int, input().split())
    lst_.append([h, m])

lst = np.array(lst_)
h_lst = collections.Counter(lst[:,0])
w_lst = collections.Counter(lst[:,1])

h_most = h_lst.most_common()[0]
w_most = w_lst.most_common()[0]

print("bomber :", h_most[0], w_most[0])
ans = h_most[1] + w_most[1]
if [h_most[0], w_most[0]] in lst_:
    ans -= 1
print(ans)



import collections
import numpy as np

h, w, m = map(int, input().split())
lst_ = []
h_lst = [0]*h
w_lst = [0]*w
for i in range(m):
    h_, w_ = map(int, input().split())
    lst_.append([h_, w_])
    h_lst[h_-1] += 1
    w_lst[w_-1] += 1

h_count = max(h_lst)
w_count = max(w_lst)
h_cand = set([i+1 for i, h_ in enumerate(h_lst) if h_ == h_count])
w_cand = set([i+1 for i, w_ in enumerate(w_lst) if w_ == w_count])
#print(h_cand, w_cand)

count = 0
for bomb in lst_:
    if bomb[0] in h_cand and bomb[1] in w_cand:
        count += 1

ans = max(h_lst) + max(w_lst)
if count < len(h_cand)*len(w_cand):
    print(ans)
else:
    print(ans-1)





Verdicts: Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=map(int, input().split())
    h.append(hi)
    w.append(wi)
    B.append((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)

import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B = [[0 for i in range(W)] for j in range(H)] 

for i in range(M):
    hi,wi=map(int, input().split())
    h.append(hi)
    w.append(wi)
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
    B[hi-1][wi-1]=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if B[h_max[ii]][w_max[ii]]==0:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)
'''for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        h_cand=[k for k, v in enumerate(h) if v == h_max[ii]+1]
        w_cand=[l for l, v in enumerate(w) if v == w_max[jj]+1]
        h_set = set(h_cand)
        w_set = set(w_cand)
        matched_list = list(h_set & w_set)
        #print(h_cand,w_cand)
        #print(matched_list)
        if len(matched_list)==0:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)
'''

import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=map(int, input().split())
    #h.append(hi)
    #w.append(wi)
    B.add((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
Hcountmax=max(Hcount)
Wcountmax=max(Wcount)
h_max=[i for i, v in enumerate(Hcount) if v == Hcountmax]
w_max=[i for i, v in enumerate(Wcount) if v == Wcountmax]
#print(h_max,w_max)
for ii in h_max:
    for jj in w_max:
        if (ii+1,jj+1) not in B:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import numpy as np
from numba import jit

@jit
def main():
    H, W, M = map(int, input().split())
    row = np.zeros(W)
    col = np.zeros(H)
    memo = []
    for _ in range(M):
        h, w = map(int, input().split())
        h -=1
        w -=1
        row[w] += 1
        col[h] += 1
        memo.append((h, w))

    col_max = col.max()
    row_max = row.max()

    max_col_indexs = np.where(col == col_max)[0]
    max_row_indexs = np.where(row == row_max)[0]

    ans = col_max + row_max -1
    for c in max_col_indexs:
        for r in max_row_indexs:
            if (c, r) not in memo:
                ans = ans = col_max + row_max
                break

    print(int(ans))

if __name__ == "__main__":
    main()

import numpy as np
from numba import njit, b1, i4, i8, f8

@njit((i8, i8, i8[:]), cache=True)
def main():
    H, W, M = map(int, input().split())
    row = np.zeros(W)
    col = np.zeros(H)
    memo = []
    for _ in range(M):
        h, w = map(int, input().split())
        h -=1
        w -=1
        row[w] += 1
        col[h] += 1
        memo.append((h, w))

    col_max = col.max()
    row_max = row.max()

    max_col_indexs = np.where(col == col_max)[0]
    max_row_indexs = np.where(row == row_max)[0]

    ans = col_max + row_max -1
    for c in max_col_indexs:
        for r in max_row_indexs:
            if (c, r) not in memo:
                ans = ans = col_max + row_max
                break

    print(int(ans))

if __name__ == "__main__":
    main()

import numpy as np

H, W, M = map(int, input().split())
row = np.zeros(W)
col = np.zeros(H)
memo = []
for _ in range(M):
    h, w = map(int, input().split())
    h -=1
    w -=1
    row[w] += 1
    col[h] += 1
    memo.append((h, w))

col_max = col.max()
row_max = row.max()

max_col_indexes = np.where(col == col_max)[0]
max_row_indexes = np.where(row == row_max)[0]

ans = col_max + row_max -1
memo = set(memo)
for c in max_col_indexes:
    for r in max_row_indexes:
        if (c, r) not in memo:
            ans = ans = col_max + row_max
            print(int(ans))
            exit()

print(int(ans))

Verdicts: Time Limit Exceeded

Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import numpy as np
import itertools


def pd(s):
    #print(s)
    pass


# input
H, W, M = map(int, input().split())
ms = [
    [int(i) for i in input().split()]
    for m in range(M)
]
pd(f"{H=} {W=} {M=}")
pd(f"{ms=}")

rows = [0]*(H+1)
cols = [0]*(W+1)
bombs = np.zeros((H+1,W+1))
for h,w in ms:
    rows[h] += 1
    cols[w] += 1
    bombs[m[0]][m[1]] += 1

rmax = max(rows)
cmax = max(cols)
rmax_hs = [i for i, v in enumerate(rows) if v == rmax]
cmax_wh = [i for i, v in enumerate(cols) if v == cmax]

for h,w in itertools.product(rmax_hs, cmax_wh):
    if bombs[h][w] == 0:
        print(rmax + cmax)
        exit()
print(rmax + cmax - 1)


import numpy as np


def pd(s):
    #print(s)
    pass


# input
H, W, M = map(int, input().split())
ms = [
    [int(i) for i in input().split()]
    for m in range(M)
]
pd(f"{H=} {W=} {M=}")
pd(f"{ms=}")

rows = [0]*(H+1)
cols = [0]*(W+1)

for m in ms:
    pd(f"{m=}")
    rows[m[0]] += 1
    cols[m[1]] += 1

row = np.argmax(rows)
col = np.argmax(cols)

pd(f"{row=} {col=}")
total = 0
for m in ms:
    if (m[0] == row) or (m[1] == col):
        total += 1
        pd(f"o:{m[0]=} {m[1]=}")
    else:
        pd(f"x:{m[0]=} {m[1]=}")
    

print(total)

import numpy as np
import itertools


def pd(s):
    # print(s)
    pass


# input
H, W, M = map(int, input().split())
ms = [
    [int(i) for i in input().split()]
    for m in range(M)
]
pd(f"{H=} {W=} {M=}")
pd(f"{ms=}")

rows = [0]*(H+1)
cols = [0]*(W+1)
targets = {}
for h, w in ms:
    rows[h] += 1
    cols[w] += 1
    targets[f"{h},{w}"] = True

rmax = max(rows)
cmax = max(cols)
rmax_hs = [i for i, v in enumerate(rows) if v == rmax]
cmax_wh = [i for i, v in enumerate(cols) if v == cmax]

for h, w in itertools.product(rmax_hs, cmax_wh):
    if f"{h},{w}" not in targets:
        print(rmax + cmax)
        exit()
print(rmax + cmax - 1)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
h,w,m=map(int, input().split())
a=[0]*m
hc=[0]*w
wc=[0]*h
for i in range(m):
	x,y=map(int, input().split())
	a[i]=[x-1,y-1]
	hc[y-1]+=1
	wc[x-1]+=1
hcm=max(hc)
wcm=max(wc)
hk=[]
wk=[]
for i in range(len(hc)):
	if hc[i]==hcm:
		hk.extend([i])
for i in range(len(wc)):
	if wc[i]==wcm:
		wk.extend([i])
for i in range(len(a)):
	if a[i][0] not in wk:
		if a[i][1] not in hk:
			print(hcm+wcm)
			exit()
print(hcm+wcm-1)

h,w,m=map(int, input().split())
a = [[0 for j in range(w)] for i in range(h)]
for i in range(m):
	x,y=map(int, input().split())
	a[x-1][y-1]+=1
hc=[0 for i in range(w)]
wc=[0 for i in range(h)]
for i in range(w):
	for j in range(h):
		hc[i] += a[j][i]
for i in range(h):
	for j in range(w):
		wc[i] += a[i][j]
ans=0
for i in range(len(hc)):
	for j in range(len(wc)):
		if a[i][j]==1:
			if ans<hc[i]+wc[j]-1:
				ans=hc[i]+wc[j]-1
		else:
			if ans<hc[i]+wc[j]:
				ans=hc[i]+wc[i]
print(ans)

h,w,m=map(int, input().split())
a=[0]*m
hc=[0]*w
wc=[0]*h
for i in range(m):
	x,y=map(int, input().split())
	a[i]=[x-1,y-1]
	hc[y-1]+=1
	wc[x-1]+=1
hcm=max(hc)
wcm=max(wc)
hk=[0]*h
wk=[0]*w
for i in range(len(hc)):
	if hc[i]==hcm:
		hk[i]=1
for i in range(len(wc)):
	if wc[i]==wcm:
		wk[i]=1
c=0
for i in range(len(a)):
	if a[i][0]==wk[i] and a[i][1]==hk[i]:
		c+=1
if c==len(hk)*len(wk):
	print(hcm+wcm-1)		
else:
	print(hcm+wcm)

h,w,m=map(int, input().split())
a = [[0 for j in range(w)] for i in range(h)]
for i in range(m):
	x,y=map(int, input().split())
	a[x-1][y-1]+=1
hc=[0 for i in range(w)]
wc=[0 for i in range(h)]
for i in range(w):
	for j in range(h):
		hc[i] += a[j][i]
for i in range(h):
	for j in range(w):
		wc[i] += a[i][j]
ans=0
for i in range(len(hc)):
	for j in range(len(wc)):
		if a[i][j]==1:
			if ans<hc[i]+wc[j]-1:
				ans=hc[i]+wc[j]-1
		else:
			if ans<hc[i]+wc[j]:
				ans=hc[i]+wc[i]
print(ans)

h,w,m=map(int, input().split())
a=[0]*m
hc=[0]*w
wc=[0]*h
for i in range(m):
	x,y=map(int, input().split())
	a[i]=[x-1,y-1]
	hc[y-1]+=1
	wc[x-1]+=1
hcm=max(hc)
wcm=max(wc)
hk=[0]*w
wk=[0]*h
for i in range(len(hc)):
	if hc[i]==hcm:
		hk[i]=1
for i in range(len(wc)):
	if wc[i]==wcm:
		wk[i]=1
c=0
for i in range(len(a)):
	if wk[a[i][0]]==1 and hk[a[i][1]]==1:
		c+=1
if c==sum(hk)*sum(wk):
	print(hcm+wcm-1)		
else:
	print(hcm+wcm)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import sys
import numpy as np
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    H, W, M = map(int, input().split())
    mm = []
    l = np.zeros((H, W))
    for i in range(M):
        a, b = map(int, input().split())
        mm.append([a, b])
        l[a-1][b-1] = 1
    row_max = 0
    row_num = 0
    col_max = 0
    col_num = 0

    r = np.count_nonzero(l == 1, axis=1)
    row_max = max(r)
    row_num = np.argmax(r)

    c = np.count_nonzero(l == 1, axis=0)
    col_max = max(c)
    col_num = np.argmax(c)

    a = np.count_nonzero(c == col_max)
    if [row_num+1, col_num+1] in mm:
        print(row_max + col_max - 1)
    else:
        print(row_max + col_max)
        
if __name__ == '__main__':
    main()

import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0] * H
    ws = [0] * W
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                exit()
    print(ans-1)


if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import sys
input = sys.stdin.buffer.readline
 
H, W, M = map(int, input().split())
 

for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map.append((h, w))
 
MX = max(X)
MY = max(Y)
ans = MX + MY
Xans = set()
Yans = set()
for i, x in enumerate(X):
    if x == MX:
        Xans.add(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.add(i)
cnt = 0
for h, w in Map:
    if h in Yans and w in Xans:
        cnt += 1
if cnt == len(Xans) * len(Yans):
    ans -= 1
print(ans)

import sys
input = sys.stdin.buffer.readline
 
H, W, M = map(int, input().split())
 
X = [0] * W
Y = [0] * H
Map = []
 
for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map.append((h, w))
 
MX = max(X)
MY = max(Y)
ans = MX + MY
Xans = set()
Yans = set()
for i, x in enumerate(X):
    if x == MX:
        Xans.add(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.add(i)
cnt = 0
for h, w in Map:
    if h in Yans and w in Xans:
        cnt += 1
if cnt == len(Xans) * len(Yans):
    ans -= 1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
h, w, m = map(int, input().split())
a = []
mh = [0 for i in range(h)]
mw = [0 for j in range(w)]

for i in range(m):
    hi, wi = map(lambda x:int(x) - 1, input().split())
    mh[hi] += 1
    mw[wi] += 1 
    a.append((hi, wi))

ans = max(mh) + max(mw)
mh_ = [i for i, v in enumerate(mh) if v == max(mh)]
mw_ = [i for i, v in enumerate(mw) if v == max(mw)]

for i in mh_:
    for j in mw_:
        if (i, j) in a:
            print(ans-1)
            exit()
print(ans)

h, w, m = map(int, input().split())
a = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
mh = [0 for i in range(h)]
mw = [0 for j in range(w)]

for i, j in a:
    mh[i] += 1
    mw[j] += 1 

hmax = max(mh)
wmax = max(mw)
ans = hmax + wmax

flag = mh.count(hmax) * mw.count(wmax)
for i,j in a:
    if mh[i] == hmax and mw[j] == wmax:
        flag -= 1

if flag == 0:
    print(ans - 1)
else:
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import numpy as np

H, W, M = map(int, input().split())
h_t = [0]*H
w_t = [0]*W
t = np.zeros((300000, 300000))
for i in range(M):
    h, w = map(int, input().split())
    t[h-1][w-1] = 1
    h_t[h-1]+=1
    w_t[w-1]+=1
h_max = max(h_t)
h_max_list = [i for i in range(len(h_t)) if h_t[i] == h_max]
w_max = max(w_t)
w_max_list = [i for i in range(len(w_t)) if w_t[i] == w_max]

for h in h_max_list:
    for w in w_max_list:
        if t[h][w] == 0:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)

import numpy as np

H, W, M = map(int, input().split())
h_t = [0]*H
w_t = [0]*W
t = {}
for i in range(M):
    h, w = map(int, input().split())
    t[(h-1, w-1)] = 1
    h_t[h-1]+=1
    w_t[w-1]+=1
print(t)
h_max = max(h_t)
h_max_list = [i for i in range(len(h_t)) if h_t[i] == h_max]
w_max = max(w_t)
w_max_list = [i for i in range(len(w_t)) if w_t[i] == w_max]

for h in h_max_list:
    for w in w_max_list:
        if (h, w) not in t:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)

import numpy as np

H, W, M = map(int, input().split())
h_t = [0]*H
w_t = [0]*W
t = np.zeros((H, W), dtype=int)
for i in range(M):
    h, w = map(int, input().split())
    t[h-1][w-1] = 1
    h_t[h-1]+=1
    w_t[w-1]+=1
print(t)
h_max = max(h_t)
h_max_list = [i for i in range(len(h_t)) if h_t[i] == h_max]
w_max = max(w_t)
w_max_list = [i for i in range(len(w_t)) if w_t[i] == w_max]

for h in h_max_list:
    for w in w_max_list:
        if t[h][w] == 0:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)

import numpy as np

H, W, M = map(int, input().split())
h_t = [0]*H
w_t = [0]*W
t = {}
for i in range(M):
    h, w = map(int, input().split())
    t[(h-1, w-1)] = 1
    h_t[h-1]+=1
    w_t[w-1]+=1
h_max = max(h_t)
h_max_list = [i for i in range(len(h_t)) if h_t[i] == h_max]
w_max = max(w_t)
w_max_list = [i for i in range(len(w_t)) if w_t[i] == w_max]

for h in h_max_list:
    for w in w_max_list:
        if (h, w) not in t:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import bisect


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

count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]
points = set()
for i in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    points.add((y, x))
    count_h[y] += 1
    count_w[x] += 1

ch_max, cw_max = max(count_h), max(count_w)
ys = [y for y in range(len(count_h)) if count_h[y] == ch_max]
xs = [x for x in range(len(count_w)) if count_w[x] == cw_max]

ans = ch_max + cw_max
for (y, x) in points:
    index = bisect.bisect_left(ys, y)
    if ys[index] == y and xs[index] == x:
        ans -= 1
        break

print(ans)



import bisect


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

count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]
points = set()
for i in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    points.add((y, x))
    count_h[y] += 1
    count_w[x] += 1

ch_max, cw_max = max(count_h), max(count_w)
ys = [y for y in range(len(count_h)) if count_h[y] == ch_max]
xs = [x for x in range(len(count_w)) if count_w[x] == cw_max]

ans = ch_max + cw_max
for (y, x) in points:
    index_y = bisect.bisect_left(ys, y)
    index_x = bisect.bisect_left(xs, x)
    if (index_y < len(ys) and ys[index_y] == y) and (index_x < len(xs) and xs[index_x] == x):
        ans -= 1
        break

print(ans)



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

count_h = [0 for i in range(h)]
count_w = [0 for i in range(w)]
points = set()
for i in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    points.add((y, x))
    count_h[y] += 1
    count_w[x] += 1

ch_max, cw_max = max(count_h), max(count_w)
ys = [y for y in range(len(count_h)) if count_h[y] == ch_max]
xs = [x for x in range(len(count_w)) if count_w[x] == cw_max]

    
ans = ch_max + cw_max
if len(ys) * len(xs) <= m:
    def _find():
        for x in xs:
            for y in ys:
                if (y, x) not in points:
                    return True
        return False
    if not _find():
        ans -= 1
print(ans)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
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)


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)


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)


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()


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import sys, math, heapq, bisect





if(__name__ == "__main__"):
    
    H, W, N_bombs= map(int, input().strip().split() )

    H_N_bomb = [ [0, i]  for i in range(H) ]
    W_N_bomb = [ [0, i]  for i in range(W) ]
    bombs = [ [0]*W for _ in range(H)  ]


    for i in range(N_bombs):
        y, x = map(int, input().strip().split() )

        W_N_bomb[x-1][0] += 1
        H_N_bomb[y-1][0] += 1
        bombs[y-1][x-1] = 1


    W_N_bomb.sort(key = lambda x: x[0])
    H_N_bomb.sort(key = lambda x: x[0])



    Ws = [0] * W
    Hs = [0] * H
    for i in range(W):
        Ws[i] = W_N_bomb[i][0]
    for i in range(H):
        Hs[i] = H_N_bomb[i][0]

    pos_x= bisect.bisect_left(Ws, Ws[-1])
    pos_y= bisect.bisect_left(Hs, Hs[-1])
    #print(W_N_bomb, H_N_bomb, pos_x, pos_y)
    flag = False
    value = Ws[i] + Hs[j]
    for i in range(pos_x, W):
        for j in range(pos_y, H):
            pos_i = W_N_bomb[i][1]
            pos_j = H_N_bomb[j][1]
            if(bombs[pos_j][pos_i]==0):
                flag=True
                break
    if(flag==True):
        print(value)
    else:
        print(value-1)


import sys, math, bisect



def solve(W_N, V_N, bombs, H, W):

    max_x = 1
    xs = []
    for i in range(W):
        if(W_N[i] > max_x):
            max_x = W_N[i]
            xs = [i]
        elif(W_N[i] == max_x):
            xs.append(i)
    max_y = 1
    ys = []
    for j in range(H):
        if(V_N[j] > max_y):
            max_y = V_N[j]
            ys = [j]
        elif(V_N[j] == max_y):
            ys.append(j)

    value = max_x + max_y

    for j in ys:

        bombs[j].sort()
        for i in xs:
            index = bisect.bisect_left(bombs[j], i)
            if(index == V_N[j] or i != bombs[j][index]):
                return value
            
    return value-1



if(__name__ == "__main__"):
    
    H, W, N_bombs= map(int, input().strip().split() )


    V_N = [0] * H
    W_N = [0] * W
    bombs = [ [] for _ in range(H) ]


    for i in range(N_bombs):
        y, x = map(int, input().strip().split() )
        """
        W_N_bomb[x-1][0] += 1
        V_N_bomb[y-1][0] += 1
        """
        V_N[y-1] += 1
        W_N[x-1] += 1
        bombs[y-1].append(x-1)




    print( solve(W_N, V_N, bombs, H, W) )


Verdicts: Runtime Error

Accepted
Problem: We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).  Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.  Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Submission attempts (in order):
import sys

H, W, M = map(int, sys.stdin.readline().split())
hlst = [0]*(H+1)
wlst = [0]*(M+1)
hwlst = []

for i in range(M):
    h, w = map(int, sys.stdin.readline().split())
    hlst[h] += 1
    wlst[w] += 1
    hwlst.append([h,w])

hmax = max(hlst)
wmax = max(wlst)
ans = 0
c = True
i = 0
for i in range(H+1):
    if hlst[i] == hmax:
        for j in range(W+1):
            if wlst[j] == wmax:
                if [i, j] in hwlst:
                    ans = hmax + wmax -1
                else:
                    ans = hmax + wmax

print(ans)


import sys
H, W, M = map(int, sys.stdin.readline().split())
hlst = [0]*(H+1)
wlst = [0]*(M+1)
hwlst = []

for i in :
    h, w = map(int, sys.stdin.readline().split())
    hlst[h] += 1
    wlst[w] += 1
    hwlst.append([h,w])

hmax = max(hlst)
wmax = max(wlst)
ans = hmax + wmax -1
c = False
i = 0
for i in range(H+1):
    if hlst[i] == hmax:
        for j in range(W+1):
            if wlst[j] == wmax:
                if [i, j] not in hwlst:
                    ans += 1
                    c = True
            if c:
                break
    if c:
        break
    
print(ans)

import sys
H, W, M = map(int, sys.stdin.readline().split())
hlst = {}
wlst = {}
hwlst = []

for i in range(M):
    h, w = map(int, sys.stdin.readline().split())
    hlst[h] += 1
    wlst[w] += 1
    hwlst.append([h, w])

h = max(hlst)
w = max(wlst)
hmax = [i for i in range(H+1) if hlst[i] == h]
wmax = [i for i in range(W+1) if wlst[i] == w]
ans = h + w -1


for i in hmax:
    for j in wmax:
        if [i, j]  not in hwlst:
            ans += 1
            break

print(ans)


import sys
H, W, M = map(int, sys.stdin.readline().split())
hlst = {}
wlst = {}
hwlst = []

for i in range(M):
    h, w = map(int, sys.stdin.readline().split())
    if h in hlst:
        hlst[h] += 1
    else:
        hlst[h] = 1

    if w in wlst:
        wlst[w] += 1
    else:
        wlst[w] = 1

    hwlst.append([h, w])

h = max(hlst.values())
w = max(wlst.values())
hmax = [i for i in hlst if hlst[i] == h]
wmax = [i for i in wlst if wlst[i] == w]
num = len(hmax)*len(wmax)


for i in hwlst:
    if hlst[i[0]] == h and wlst[i[1]] == w:
        num -= 1

if num:
    print(h+w)
else:
    print(h+w-1)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted