Problem:


Score : 500 points

Problem Statement

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.

Constraints

All values in input are integers.

1 \leq H, W \leq 3 \times 10^5

1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)

1 \leq h_i \leq H

1 \leq w_i \leq W

\left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

We can destroy all the targets by placing the bomb at \left(1, 2\right).

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4

Sample Output 3

6



Sample input:
2 3 3
2 2
1 1
1 3


Sample output:
3

Submission status: Wrong Answer

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

bombw = [0]*w
bombh = [0]*h
bomb = [""]*m
# print(bomb)
for i in range(m):
    hi,wi = map(int,input().split())
    bombw[wi-1] += 1
    bombh[hi-1] += 1
    bomb[i] = str(hi-1)+"-"+str(wi-1)
    # print(bomb)
maw = max(bombw)
mah = max(bombh)
# print(maw,mah)
inmaw = [i for i, x in enumerate(bombw) if x == maw]
inmah = [i for i, x in enumerate(bombh) if x == mah]
# print(inmaw,inmah)

ans = maw + mah
# print(bomb)
# print(ans)
for i in inmah:
    for j in inmaw:
        if [str(i)+"-"+str(j)] not in bomb:
            print(ans)
            exit()
print(ans-1)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
objs=[tuple(map(int,input().split())) for i in range(m)]
setobj=set(objs)
xs,ys=zip(*objs)
from collections import Counter as co
wk,wv= co(ys).most_common(1)[0]
hk,hv= co(xs).most_common(1)[0]
print(wv+hv-int((hk,wk)in setobj))

Submission status: Wrong Answer

Solution code:
h, w, m=map(int,input().split())
H=[0]*h
W=[0]*w
HW=[]

for i in range(m) :
    h_, w_=map(int,input().split())
    H[h_-1]+=1
    W[w_-1]+=1
    HW.append([h_-1,w_-1])
    
maxH=max(H)
maxW=max(W)

mh=[i for i,v in enumerate(H) if v==maxH]
mw=[i for i,v in enumerate(W) if v==maxW]

for i in mh :
    for j in mw :
        if [i,j] in HW :
            print(maxH+maxW-1)
            exit()
print(maxH+maxW)

Submission status: Wrong Answer

Solution code:
#import random

def putmx(lis,mx):
  ret=[]
  for (i,j) in zip(range(len(lis)),lis):
    if j==mx:
      ret.append(i)
  return ret
  

h,w,m=map(int,input().split())
hb=[0]*h
wb=[0]*w
bmb=[]
for i in range(h):
  bmb.append({-1})
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  bmb[hh].add(ww)
  hb[hh]+=1
  wb[ww]+=1
mhb=max(hb)
mwb=max(wb)
hmx=putmx(hb,mhb)
wmx=set(putmx(wb,mwb))

#print(hb,wb,hmx,wmx)
fl=False
for i in hmx:
  if len(wmx&bmb[i])==0:
    print(mhb+mwb)
    break
else:
  print(mhb+mwb-1)

Submission status: Wrong Answer

Solution code:
#import random

def putmx(lis,mx):
  ret=[]
  for (i,j) in zip(range(len(lis)),lis):
    if j==mx:
      ret.append(i)
  return ret
  

h,w,m=map(int,input().split())
hb=[0]*h
wb=[0]*w
bmb=[]
for i in range(h):
  bmb.append({-1})
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  bmb[hh].add(ww)
  hb[hh]+=1
  wb[ww]+=1
mhb=max(hb)
mwb=max(wb)
hmx=putmx(hb,mhb)
wmx=set(putmx(wb,mwb))

#print(hb,wb,hmx,wmx)
fl=False
for i in hmx:
  if len(wmx&bmb[i])>0:
    print(mhb+mwb)
    break
else:
  print(mhb+mwb-1)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
bomb_list = []

bomb_list = [list(map(int, input().split())) for i in range(m)]

for o in range(m):
    for p in range(2):
        bomb_list[o][p] -= 1

h_count_list = [0 for j in range(h)]
w_count_list = [0 for k in range(w)]

max_h_count = 0
max_w_count = 0

x_list = []
y_list = []

for l in range(m):
    a = bomb_list[l][0]
    h_count_list[a] += 1

max_h_count = max(h_count_list)

for c in range(h):
    if h_count_list[c] == max_h_count:
        x_list.append(c)
    
for n in range(m):
    b = bomb_list[n][1]
    w_count_list[b] += 1

max_w_count = max(w_count_list)

for d in range(w):
    if w_count_list[d] == max_w_count:
        y_list.append(d)

e = 0

for x in x_list:
    for y in y_list:
        if [x, y] in bomb_list is True and e < max_w_count + max_h_count - 1:
            e = max_w_count + max_h_count - 1
        else:
            e = max_w_count + max_h_count 

print(e)

Submission status: Wrong Answer

Solution code:
import collections
import sys

*data, = map(int, sys.stdin.read().split()[::-1])

def inp():
    return data.pop()

h, w, m = inp(), inp(), inp()


targets = set()
xs = []
ys = []
for _ in range(m):
    y, x = inp(), inp()
    # y -= 1
    # x -= 1
    ys.append(y)
    xs.append(x)
    targets.add((y, x))

x_stat = collections.Counter(xs)
y_stat = collections.Counter(ys)

xs = sorted(set(xs), key=lambda obj: x_stat[obj], reverse=True)
ys = sorted(set(ys), key=lambda obj: y_stat[obj], reverse=True)

mx_x = x_stat[xs[0]]
mx_y = y_stat[ys[0]]
while xs and x_stat[xs[-1]] < x_stat[xs[0]]:
    xs.pop()
while ys and y_stat[ys[-1]] < y_stat[ys[0]]:
    ys.pop()
# print(xs, x_stat)
# print(ys, y_stat)

found = False
ans = mx_y + mx_x
if len(xs) * len(ys) <= len(targets):
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

h = []
w = []
for _ in range(M):
    x, y = map(int, input().split())
    h.append(x)
    w.append(y)


ch = Counter(h)
cw = Counter(w)
ans = ch.most_common()[0][1] + cw.most_common()[0][1]
bom = (ch.most_common()[0][0], cw.most_common()[0][0])

for x, y in zip(h, w):
    if (x, y) == bom:
        ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]
high = [0] * h
weig = [0] * w
for i in range(m):
    high[hw[i][0] - 1] += 1
    weig[hw[i][1] - 1] += 1
ans = max(high) + max(weig)
hmax_list = [i + 1 for i, x in enumerate(high) if x == max(high)]
wmax_list = [i + 1 for i, x in enumerate(weig) if x == max(weig)]
flag = False
for i in hmax_list:
    for j in wmax_list:
        if [i, j] in hw:
            ans -= 1
            flag = True
            break
    if flag == True:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
lsh = [0] * h
lsw = [0] * w

bom = []
for _ in range(m):
    m1, m2 = map(int, input().split())
    lsh[m1 - 1] += 1
    lsw[m2 - 1] += 1
    bom.append((m1-1, m2-1))
print(lsh)
print(lsw)

lshmax = max(lsh)
lswmax = max(lsw)

jd= False

for i in range(h):
    if lsh[i] == lshmax:
        for j in range(w):
            if lsw[j] == lswmax:
                if (i, j) not in bom:
                    jd= True
                    #print(i,j)
if jd:
    print(lshmax+lswmax)
else:
    print(lshmax + lswmax -1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
H, W, M = map(int, input().split())
r = defaultdict(int)
c = defaultdict(int)
rc = defaultdict(int)
for i in range(M):
    h, w = map(int, input().split())
    rc[(h, w)] += 1
    r[w] += 1
    c[h] += 1

ri, rmax = 0, 0
ci, cmax = 0, 0
for i in r.keys():
    v = r[i]
    if v > rmax:
        ri = i
        rmax = v
for i in c.keys():
    v = c[i]
    if v > cmax:
        ci = i
        cmax = v

rml, cml = [], []
for i, v in r.items():
    if v == rmax:
        rml.append((i, v))
for i, v in c.items():
    if v == cmax:
        cml.append((i, v))


ans = rmax+cmax-1
for i, vi in rml:
    for j, vj in cml:
        if not (j, i) in rc:
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

H,W,M = map(int,input().split())
h = []
w = []
S = []

for _ in range(M):
    tmp_h,tmp_w = map(int,input().split())
    h.append(tmp_h)
    w.append(tmp_w)
    S.append((tmp_h,tmp_w))

H_count = Counter(h).most_common()
W_count = Counter(w).most_common()
flag = True


for a,b in S:
    if (H_count[0][0],W_count[0][0]) == (a,b):
        flag = False
print(H_count[0][0] + W_count[0][0] if flag else H_count[0][0] + W_count[0][0] - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

H,W,M = map(int,input().split())
h = []
w = []
S = []

for _ in range(M):
    tmp_h,tmp_w = map(int,input().split())
    h.append(tmp_h)
    w.append(tmp_w)
    S.append((tmp_h,tmp_w))

H_count = Counter(h).most_common()
W_count = Counter(w).most_common()
flag = True


for a,b in S:
    if (H_count[0][0],W_count[0][0]) == (a,b):
        flag = False
print(H_count[0][1] + W_count[0][1] if flag else H_count[0][1] + W_count[0][1] - 1)

Submission status: Wrong Answer

Solution code:
H, W, M = [int(i) for i in input().split()]

cnt_dict_h = {}
cnt_dict_w = {}
bomb_list = []

for i in range(M):
    h, w = [int(i)-1 for i in input().split()]
    bomb_list.append((h,w))
    cnt_dict_h.setdefault(h, 0)
    cnt_dict_h[h] += 1
    cnt_dict_w.setdefault(w, 0)
    cnt_dict_w[w] += 1

max_h_key_list = [kv[0] for kv in cnt_dict_h.items() if kv[1] == max(cnt_dict_h.values())]
max_w_key_list = [kv[0] for kv in cnt_dict_w.items() if kv[1] == max(cnt_dict_w.values())]
max_h = max(cnt_dict_h.values())
max_w = max(cnt_dict_w.values())

bomb_num = max_h + max_w

flag = False
for bomb in bomb_list:
    if bomb[0] in max_h_key_list and bomb[1] in max_w_key_list:
        flag = True
        break

if flag:
    bomb_num = bomb_num - 1

print(bomb_num)

Submission status: Wrong Answer

Solution code:
import collections

H, W, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]

hb = [l[0] for l in L]
wb = [l[1] for l in L]

ans = 0
hc = collections.Counter(hb).most_common()
wc = collections.Counter(wb).most_common()
ans += hc[0][1]
ans += wc[0][1]

if hc[0][1] == 1 or wc[0][1] == 1:
    pass
else:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
  H,W,m=map(int,input().split())
  h=np.zeros(H, dtype = int)
  w=np.zeros(W, dtype = int)
  hw=np.zeros(m, dtype = int)
  for i in range(m):
    hi,wi=map(int,input().split())
    hi=hi-1
    wi=wi-1
    h[hi]+=1
    w[wi]+=1
    hw[i]=hi*W+wi
  hw.sort()
  yn=1
  hm=np.max(h)
  wm=np.max(w)
  #print(hw)
  hwi=0
  for j in range(H):
    if h[j]==hm:
      #print(h)
      for k in range(W):
        if w[k]==wm:
          #print(k)
          #print(hw[3,k])
          for l in range(hwi,m):
            hwi=l
            if j*W+k>hw[l]:
              continue
            elif j*W+k==hw[l]:
              break
            else:
              yn=0
              break
      else:
        continue
      break
  print(hm+wm-yn)
main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
H, W, M = map(int, input().split())
r = defaultdict(int)
c = defaultdict(int)
rc = defaultdict(int)
for i in range(M):
    h, w = map(int, input().split())
    rc[(h, w)] += 1
    r[w] += 1
    c[h] += 1

ri, rmax = 0, 0
ci, cmax = 0, 0
for i in r.keys():
    v = r[i]
    if v > rmax:
        ri = i
        rmax = v
for i in c.keys():
    v = c[i]
    if v > cmax:
        ci = i
        cmax = v

ans = rmax+cmax
if (ci, ri) in rc:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
row_boms=[0 for i in range(H)]
col_boms=[0 for i in range(W)]

boms=[[0] *W]*H
for i in range(M):
  h,w=map(int,input().split())
  boms[h-1][w-1]=1
  row_boms[h-1]+=1
  col_boms[w-1]+=1

row_max=max(row_boms)
col_max=max(col_boms)

rowmax_h=[]
colmax_w=[]
for i in range(H):
  if row_boms[i]==row_max:
    rowmax_h+=[i]
for i in range(W):
  if col_boms[i]==col_max:
    colmax_w+=[i]
rows=len(rowmax_h)
cols=len(colmax_w)
tf=0
for i in rowmax_h:
  for j in colmax_w:
    if boms[i][j]==0:
      tf=1
      break

if tf==1:
  print(row_max+col_max)
else:
  print(row_max+col_max-1)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)

lst=[]
cnt=[[False]*(w+1) for i in range(h+1)]
for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  lst.append([a,b])
  

hcnt,wcnt=max(hlist),max(wlist)

hh,ww=[],[]

for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,w+1):
  if wlist[i]==wcnt:
    ww+=[i]


    
hhlist=[]
wwlist=[False]*(w+1)

for i in ww:
  wwlist[i]=True
  
for i in hh:
  cnt[i]=wwlist

for i in lst:
  if cnt[i[0]][i[1]]==False:
    print(hcnt+wcnt-1)
    exit()

print(hcnt+wcnt)

Submission status: Wrong Answer

Solution code:
h, w, m= map(int, input().split())
hs = [0 for i in range(h)]
ws = [0 for i in range(w)]
for i in range(m):
  mh, mw = map(int, input().split())
  hs[mh-1] += 1
  ws[mw-1] += 1
print(max(hs)+max(ws)-1)

Submission status: Wrong Answer

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

bombw = [0]*w
bombh = [0]*h
bomb = []
# print(bomb)
for i in range(m):
    hi,wi = map(int,input().split())
    bombw[wi-1] += 1
    bombh[hi-1] += 1
    bomb.append([str(hi)+"-"+str(wi)])
    # print(bomb)
maw = max(bombw)
mah = max(bombh)
# print(maw,mah)
inmaw = [i for i, x in enumerate(bombw) if x == maw]
inmah = [i for i, x in enumerate(bombh) if x == mah]
# print(inmaw,inmah)

ans = maw + mah
# print(bomb)
# print(ans)
for i in inmah:
    for j in inmaw:
        if str(i)+"-"+str(j) not in bomb:
            print(ans)
            exit()
print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    H, W, M = MI()
    Hlist = [[0, i] for i in range(H)]
    Wlist = [[0, i] for i in range(W)]
    Dlist = [[] for i in range(H)]
    for i in range(M):
        h, w = MI()
        Hlist[h-1][0]+=1
        Wlist[w-1][0]+=1
        Dlist[h-1].append(w-1)
        
    Hlist.sort(key = lambda x:x[0], reverse = True)
    Wlist.sort(key = lambda x:x[0], reverse = True)
    ans = -float('inf')
    past_num1 = Hlist[0][0]
    past_num2 = Wlist[0][0]
    
    for num1, index1 in Hlist:
        if num1 < past_num1:
            break
        for num2, index2 in Wlist:
            if num2 < past_num2:
                break
            else:
                if index2 in Dlist[index1]:
                    ans = max(ans, num1+num2-1)
                else:
                    ans = max(ans, num1+num2)
                    break
                past_num1 = num1
                past_num2 = num2
        else:
            continue
        break
            
    print(ans)
            

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x,y,m = map(int,input().split())
row = {}
ch = set()
column = {}
for i in range(m):
	h,k = map(int,input().split())
	ch.add((h,k))
	if h in row:
		row[h] += 1
	else:
		row[h] = 1

	if k in column:
		column[k] += 1
	else:
		column[k] = 1


r_max = 0
c_max = 0

for i in row:
	r_max = max(r_max,row[i])
for j in column:
	c_max = max(c_max,column[j])

r_inx = 0
w_inx = 0

for i in row:
	if row[i] == r_max:
		r_inx = i
		break
for j in column:
	if column[j] == c_max:
		w_inx = j
		break
if (r_inx,w_inx) in ch:
	print(r_max+c_max-1)
else:
	print(r_max+c_max)

Submission status: Wrong Answer

Solution code:
#import random

def putmx(lis,mx):
  ret=[]
  for (i,j) in zip(lis,range(len(lis))):
    if i==mx:
      ret.append(j)
  return ret
  

h,w,m=map(int,input().split())
hl=[0]*h
wl=[0]*w
hb=[]
wb=[]
bmb=[]
for i in range(h):
  bmb.append([])
  hb.append([0,i])
for i in range(w):
  wb.append([0,i])
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  bmb[hh].append(ww)
  hb[hh][0]+=1
  wb[ww][0]+=1
  hl[hh]+=1
  wl[ww]+=1
mhb=max(hl)
mwb=max(wl)
hmx=putmx(hb,mhb)
wmx=putmx(wb,mwb)

#print(hb,wb,hmx,wmx)
fl=False
for i in hmx:
  for j in wmx:
    if not j in bmb[i]:
      print(mhb+mwb)
      fl=True
      break
  if fl:
    break
else:
  print(mhb+mwb-1)

Submission status: Wrong Answer

Solution 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)):
    if hl[i]==a:
        hmax.append(i)
for i in range(len(wl)):
    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)

Submission status: Wrong Answer

Solution code:
import collections
h,w,m=map(int,input().split())
C,R=[],[]
CR=[]
for i in range(m):
  c,r=map(int,input().split())
  C.append(c)
  R.append(r)
  CR.append([c,r])
C_coll=collections.Counter(C)
R_coll=collections.Counter(R)
c=C_coll.most_common(1)
r=R_coll.most_common(1)
ans=c[0][1]+r[0][1]
if [c[0][0],r[0][0]] in CR:
  ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W,M=map(int,input().split())
A=[[0]*H]*W
Bomb_ls=[]
X=[0]*M
Y=[0]*M
for i in range(M):
  X[i],Y[i]=[int(x) for x in input().split()]
  Bomb_ls.append([X[i],Y[i]])
R=Counter(X)
C=Counter(Y)
R_max = [letter for letter,count in R.most_common() if count == R.most_common()[0][1]]
C_max = [letter for letter,count in C.most_common() if count == C.most_common()[0][1]]
score=-1
for i in range(M):
  if not (X[i] in R_max and Y[i] in C_max):
    score=0
    break
print(max(R.values())+max(C.values())+score)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
if len(aa)*len(bb)>m:
    print(am+bm)
for i in aa:
    for j in bb:
        if [i,j] in bomb:
            continue
        else:
            print(am+bm)
            exit()
print(am+bm-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
INF = 10**18
sys.setrecursionlimit(10**6)
def li():
    return [int(x) for x in input().split()]

H, W, M = li()
PH = []
PW = []

for i in range(M):
    h, w = li()
    PH.append(h)
    PW.append(w)

most_common_h = Counter(PH).most_common(1)
most_common_w = Counter(PW).most_common(1)

most_common_h_value = most_common_h[0][0]
most_common_h_cnt = most_common_h[0][1]
most_common_w_value = most_common_w[0][0]
most_common_w_cnt = most_common_w[0][1]

is_same = False
for i in range(M):
    if PH[i] == most_common_h_value and PW[i] == most_common_w_value:
        is_same = True
cnt = most_common_h_cnt + most_common_w_cnt
if is_same:
    cnt -= 1

print(cnt)

Submission status: Wrong Answer

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

targets = []
n_target_h = [0] * H
n_target_w = [0] * W

for i in range(M):
    h, w = map(int, input().split())
    targets.append((h, w))
    n_target_h[h - 1] += 1
    n_target_w[w - 1] += 1

h_max = max(n_target_h)
w_max = max(n_target_w)

bomb_h = [i + 1 for i, h in enumerate(n_target_h) if h == h_max]
bomb_w = [i + 1 for i, w in enumerate(n_target_w) if w == w_max]

count = len(bomb_h) * len(bomb_w)
for target in targets:
    if (n_target_h[target[0] - 1] == h_max) and (n_target_h[target[0] - 1] == h_max):
        count -= 1

if count > 0:
    ans = h_max + w_max
else:
    ans = h_max + w_max - 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

m = np.zeros((3*10**3, 3*10**3))

Submission status: Wrong Answer

Solution 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][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)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M = map(int,input().split())
#h = np.empty(M,dtype=np.int)
#w = np.empty(M,dtype=np.int)
bomb = np.zeros((M,2),dtype=np.int32)
hh = np.zeros(H+1,dtype=np.int32)
ww = np.zeros(W+1,dtype=np.int32)

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

#print(bomb)
h_max_id = np.argmax(hh)
w_max_id = np.argmax(ww)

b = 0
for i in range(M):
    bomb[i] == [h_max_id, w_max_id]
    b = 1
print(hh[h_max_id] + ww[w_max_id] - b)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
lsh = [0] * h
lsw = [0] * w
for _ in range(m):
    m1, m2 = map(int, input().split())
    lsh[m1 - 1] += 1
    lsw[m2 - 1] += 1

print(max(lsh) + max(lsw) -1)

Submission status: Wrong Answer

Solution code:
import collections

h,w,m=map(int,input().split())
Y=[]
X=[]
B=[]
for i in range(m):
    y,x = map(int,input().split())
    B.append([y,x])
    Y.append(y)
    X.append(x)

xc=collections.Counter(X)
yc=collections.Counter(Y)
xmc=xc.most_common()
ymc=yc.most_common()


addans=0
maxans=0
for i in range(len(xmc)):
    if xmc[i][0]!=xmc[0][0]:
        break
    for j in range(len(ymc)):
        if ymc[i][0]!=ymc[0][0]:
            break
        if not [ymc[j][0],xmc[i][0]] in B:
            addans=1
        else:
            addans=0
        maxans = max(xmc[i][1]+ymc[j][1]-1+addans,maxans)
print(maxans)

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
H = [0]*(h+1)
W = [0]*(w+1)
s = set([])
for i in range(m):
    a,b = map(int,input().split())
    s.add((a,b))

    H[a] += 1
    W[b] += 1

x = [0]*(h+1)
y = [0]*(w+1)
    
for i in range(h+1):
    x[i] = [i,H[i]]
for i in range(w+1):
    y[i] = [i,W[i]]

x.sort(key= lambda val : val[1],reverse=True)
y.sort(key= lambda val : val[1],reverse=True)

ma = x[0][1]
mb = y[0][1]

i,j = 0,0
sw = 0

xx = x.count(ma)
yy = y.count(mb)

for i in range(xx):
    for j in range(yy):
        if (x[i][0],y[j][0]) not in s:
            sw = 1
            break 
print(ma+mb+sw-1)

Submission status: Wrong Answer

Solution 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][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
    break
    
if count < len(max1)*len(max2):
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
readline=sys.stdin.readline

H,W,M = map(int,readline().split())

hcol = [[0,i] for i in range(H)]
wcol = [[0,i] for i in range(W)]

P = set()
for i in range(M):
  h,w = map(int,readline().split())
  h -= 1
  w -= 1
  hcol[h][0] += 1
  wcol[w][0] += 1
  P.add((h,w))
  
hcol = sorted(hcol, key = lambda x:x[0], reverse = True)
wcol = sorted(wcol, key = lambda x:x[0], reverse = True)

hmax = hcol[0][0]
wmax = wcol[0][0]

ans = 0
hind = 0
wind = 0

# 交点がないものがあればhmax + wmaxが答え
found = False
while hind < H:
  while wind < W:
    val = hcol[hind][0] + wcol[wind][0]
    if (hcol[hind][1],wcol[wind][1]) in P:
      val -= 1
    else:
      found = True
      ans = val
      break
    if ans < val:
      ans = val
    wind += 1
    if wind == W or wcol[wind][0] < wmax:
      break
  if found:
    break
  hind += 1
  if hind == H or hcol[hind][0] < hmax:
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
A = set()
for k in range(M):
  a,b = map(int,input().split())
  P[a] += 1
  Q[b] += 1
  A.add((a,b))
Pindex = [i for i, v in enumerate(P) if v == max(P)]
Qindex = [i for i, v in enumerate(Q) if v == max(Q)]

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
A = set()
for k in range(M):
  a,b = map(int,input().split())
  P[a] += 1
  Q[b] += 1
  A.add((a,b))

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
H = [0]*(h+1)
W = [0]*(w+1)
s = set([])
for i in range(m):
    a,b = map(int,input().split())
    s.add((a,b))

    H[a] += 1
    W[b] += 1

x = [0]*(h+1)
y = [0]*(w+1)
    
for i in range(h+1):
    x[i] = [i,H[i]]
for i in range(w+1):
    y[i] = [i,W[i]]

x.sort(key= lambda val : val[1],reverse=True)
y.sort(key= lambda val : val[1],reverse=True)

ma = x[0][1]
mb = y[0][1]

i,j = 0,0
sw = 0
while 1:
    if j > w:
        break
    if x[i][1]+y[j][1] != ma+mb:
        break
    if  x[i][1] == ma:
        if (x[i][0],y[j][0]) in s:
            pass
        else:
            if x[i][1]+y[j][1] == ma+mb:
                sw = 1
                break
        i += 1
    else:
        i = 0
        j += 1

    
print(ma+mb+sw-1)

Submission status: Wrong Answer

Solution code:
import sys
import collections

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    H, W, M = map(int, input().split())
    bombs = []
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append((h, w))
    bombs_set = set(bombs)
    g = list(zip(*bombs))
    g0 = collections.Counter(g[0])
    g1 = collections.Counter(g[1])
    g0items = list(g0.items()); g0items.sort(key=lambda x: x[1], reverse=True)
    g1items = list(g1.items()); g1items.sort(key=lambda x: x[1], reverse=True)
    x = g0items[0][0];countx = g0items[0][1]
    y = g1items[0][1];county = g1items[0][1]
    for xx, s in g0items:
        if s != countx:
            continue
        for yy, t in g1items:
            if t != county:
                continue
            if (xx, yy) not in bombs_set:
                x, y = xx, yy
                break
    ans = countx + county - ((x, y) in bombs)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
H, W, M = map(int, input().split())
hList = {i+1: 0 for i in range(H)}
wList = {i+1: 0 for i in range(W)}
pList = set()
#print(hList, wList, pList)
for _ in range(M):
  h, w = list(map(int, input().split()))
  #print(h, w)
  hList[h] += 1
  wList[w] += 1
  pList.add((h, w))
#print(hList, wList, pList)

maxHCount = max(hList.values())
maxHList = [h for h, count in hList.items() if count==maxHCount]


maxWCount = max(wList.values())
maxWList = [w for w, count in wList.items() if count==maxWCount]

#counterList = []
#for maxH in maxHList:
#  for maxW in maxWList:
#    counterList.append(hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0))
#print(max(counterList))
#print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))
#print(max(((hList[maxH] + wList[maxW] - (1 if ((maxH, maxW) in pList) else 0)) for maxH in maxHList for maxW in maxWList)))

if M < len(maxHList)*len(maxWList):
	print(maxHCount + maxWCount)
	sys.exit(0)

for maxH in maxHList:
  for maxW in maxWList:
    if (maxH, maxW) in pList:
      print(maxHCount + maxWCount - 1)
      sys.exit(0)

print(maxHCount + maxWCount)

Submission status: Wrong Answer

Solution code:
a=list(map(int,input().split()))
h=a[0]
w=a[1]
m=a[2]
sh=[0]*1000000
sw=[0]*1000000
ss=[0]*1000000
mw=0
mh=0
for i in range(0,m):
    ss[i]=list(map(int,input().split()))

for i in range(0,m):
    sh[ss[i][0]]+=1
    if sh[ss[i][0]]>mh:
        mh=sh[ss[i][0]]
    sw[ss[i][1]]+=1
    if sw[ss[i][0]]>mw:
        mw=sw[ss[i][0]]

q=0
for i in range(0,m):
    if sh[ss[i][0]]==mh and sw[ss[i][1]]==mw:
        q=-1
z=mh+mw+q
print(z)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
dich = {i: 0 for i in range(H)}
dicw = {i: 0 for i in range(W)}
dic = set()
for _ in range(M):
  h, w = map(lambda x: int(x)-1, input().split())
  dich[h] += 1
  dicw[w] += 1
  dic.add((h, w))

sh = sorted(dich.items(), key=lambda x:-x[1])
sw = sorted(dicw.items(), key=lambda x:-x[1])
maxh = max([i for _, i in sh])
maxw = max([i for _, i in sw])
ans = 0
for h, c1 in sh:
  flg = False
  if c1 < maxh:
    break
  for w, c2 in sw:
    if c2 < maxw:
      flg = True
      break
    if (h, w) in dic:
      ans = max(ans, c1+c2-1)
    else:
      ans = max(ans, c1+c2)
  if flg:
    break

print(ans)

Submission status: Wrong Answer

Solution 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]
count=0
for k in hw.keys():
  h,w=k
  if h in max1 and w in max2:
    count += 1
    break
    
if count < len(max1)*len(max2):
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M = map(int,input().split())
#h = np.empty(M,dtype=np.int)
#w = np.empty(M,dtype=np.int)
bomb = np.zeros((M,2),dtype=np.int)
hh = np.zeros(H+1,dtype=np.int)
ww = np.zeros(W+1,dtype=np.int)

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

#print(bomb)
h_max_id = np.argmax(hh)
w_max_id = np.argmax(ww)

b = 0
for i in range(M):
    bomb[i] == [h_max_id, w_max_id]
    b = 1
print(hh[h_max_id] + ww[w_max_id] - b)