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:
import numpy as np
H, W, M = map(int, input().split())
hwlist = [list(map(int, input().split())) for i in range(M)]
a = np.zeros(H)
b = np.zeros(W)
for m in range(M):
    a[hwlist[m][0]-1] += 1
    b[hwlist[m][1]-1] += 1
max_a = max(a)
a_max_id = [i for i, v in enumerate(a) if v == max_a]
max_b = max(b)
b_max_id = [i for i, v in enumerate(b) if v == max_b]
for i in range(len(a_max_id)):
    for j in range(len(b_max_id)):
        if not [a_max_id[i]+1, b_max_id[j]+1] in hwlist:
            print(max_a + max_b)
            exit()
print(max_a + max_b - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

h, w, m= map(int, input().split())
line=np.zeros(h, dtype='int8')
colm=np.zeros(w, dtype='int8')
locline=np.zeros(m,dtype='int8')
loccolm=np.zeros(m,dtype='int8')

for i in range(0,m):
  hi, wi = map(int, input().split())
  line[hi-1]=line[hi-1]+1 
  colm[wi-1]=colm[wi-1]+1 
  locline[i]=hi-1
  loccolm[i]=wi-1
    
#colm=np.sum(ans, axis=0)
#line=np.sum(ans, axis=1)

colmarg=np.argsort(-colm)
linearg=np.argsort(-line)

hhh=int(h/2)
www=int(w/2)
if (h < 1000): hhh=h
if (w < 1000): www=w

ataimax=0
for ih in linearg[0:5]:
  for iw in colmarg[0:5]:
    cho=0
    for i in range(0,m):
      if ((locline[i] == ih) and (loccolm[i] == iw)): cho=1
    atai=colm[iw]+line[ih]-cho
    if (atai >= ataimax): ataimax=atai

print (ataimax)

Submission status: Wrong Answer

Solution code:
import numpy as np

h, w, m= map(int, input().split())
line=np.zeros(h, dtype='int8')
colm=np.zeros(w, dtype='int8')
locline=np.zeros(m,dtype='int8')
loccolm=np.zeros(m,dtype='int8')

for i in range(0,m):
  hi, wi = map(int, input().split())
  line[hi-1]=line[hi-1]+1 
  colm[wi-1]=colm[wi-1]+1 
  locline[i]=hi-1
  loccolm[i]=wi-1
    
#colm=np.sum(ans, axis=0)
#line=np.sum(ans, axis=1)

colmarg=np.argsort(-colm)
linearg=np.argsort(-line)

hhh=int(h/2)
www=int(w/2)
if (h < 1000): hhh=h
if (w < 1000): www=w

ataimax=0
for ih in linearg[0:1]:
  for iw in colmarg[0:1]:
    cho=0
    for i in range(0,m):
      if ((locline[i] == ih) and (loccolm[i] == iw)): cho=1
    atai=colm[iw]+line[ih]-cho
    if (atai >= ataimax): ataimax=atai

print (ataimax)

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)
    countx = g0items[0][1]
    county = g1items[0][1]
    for x, s in g0items:
        if s != countx:
            break
        for y, t in g1items:
            if t != county:
                break
            if (x, y) not in bombs_set:
                break
    ans = countx + county - ((x, y) in bombs)
    print(ans)


if __name__ == "__main__":
    main()

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

Submission status: Wrong Answer

Solution code:
import itertools
H,W,m = map(int,input().split())
hs = [0 for _ in range(H)]
ws = [0 for _ in range(W)]
data = set()

for j in range(m):
	h,w = map(int,input().split())
	data.add((h-1, w-1))
	hs[h-1] += 1
	ws[w-1] += 1

maxhs = 0
maxws = 0
maxhsindex = []
maxwsindex = []

for i in range(H):
	targ = hs[i]
	if targ > maxhs:
		maxhs = targ
		maxhsindex = [targ]
	elif targ == maxhs:
		maxhsindex.append(targ)

for i in range(W):
	targ = ws[i]
	if targ > maxws:
		maxws = targ
		maxwsindex = [targ]
	elif targ == maxws:
		maxwsindex.append(targ)

for i, j in itertools.product(maxhsindex, maxwsindex):
	if (i, j) in data:
		print(max(hs)+max(ws)-1)
		exit()
print(max(hs)+max(ws))

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)

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


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

#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)))
for maxH in maxHList:
  for maxW in maxWList:
    if (maxH, maxW) in pList:
      print(hList[maxH] + wList[maxW] - 1)
      sys.exit(0)

print(hList[maxH] + wList[maxW])

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
Hinx = [0 for _ in range(H+1)]
Winx = [0 for _ in range(W+1)]
isExist = [0 for _ in range(M)]
for i in range(M):
    h,w = map(int,input().split())
    Hinx[h] += 1
    Winx[w] += 1
    isExist[i] = (h,w)
HMinx = []
WMinx = []
Hmax = max(Hinx)
Wmax = max(Winx)
ans = Hmax+Wmax

isExist = set(isExist)
for i in range(1,H+1):
    if Hinx[i] == Hmax:
        HMinx.append(i)
for i in range(1,W+1):
    if Winx[i] == Wmax:
        WMinx.append(i)
flag = False
for i in HMinx:
    for j in WMinx:
        flag2 = False
        if (i,j) in isExist:
            flag2 = True
            break
        if flag2 == False:
            flag = True
            break
    if flag == True:
        break
if flag == True:
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
h = [0]*H
w = [0]*W
c = []
C = 0
for i in range(M):
  a,b = map(int,input().split())
  h[a-1] += 1
  w[b-1] += 1
  if a==b:
    c.append(a)

A = max(h)
B = max(w)
if c.count(A) == c.count(B):
  C += 1
print(A+B-C)

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]

for i in hh:
  cnt[h]=[True]*(w+1)

for i in ww:
  for j in range(h+1):
    cnt[j][i]=True


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:
a=list(map(int,input().split()))
h=a[0]
w=a[1]
m=a[2]
sh=[0]*10000000
sw=[0]*10000000
ss=[0]*10000000
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=-1
for i in range(0,m):
    if (sh[ss[i][0]]==mh and sw[ss[i][1]]!=mw) or (sh[ss[i][0]]!=mh and sw[ss[i][1]]==mw):
        q=0
z=mh+mw+q
print(z)

Submission status: Wrong Answer

Solution code:
import numpy as np

#H, W, M = map(int, input().split())
#h = np.zeros(H)
#w = np.zeros(W)
m = np.zeros((3*10**3, 3*10**3))
#ans = 3
'''
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
#print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
h,w,m = list(map(int,input().split()))

C = [0]*h
R = [0]*w

for _ in range(m):
  a,b = list(map(int,input().split()))
  a,b = a-1, b-1
  C[a] += 1
  R[b] += 1
  
print(max(C)+max(R)-1)

Submission status: Wrong Answer

Solution code:
#import random

def putmx(lis):
  ret=[]
  mx=max(lis)
  lis.sort(key=lambda x: x[0],reverse=True)
  for i in lis:
    if i[0]!=mx:
      break
    ret.append(i[1])
  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

hmx=putmx(hb)
wmx=putmx(wb)
mhb=max(hl)
mwb=max(wl)
#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())
#h = np.zeros(H)
#w = np.zeros(W)
m = np.zeros((3*10**2, 3*10**2))
#ans = 3
'''
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
#print(int(ans))

Submission status: Wrong Answer

Solution code:
#import random

def putmx(lis):
  ret=[]
  mx=max(lis)
  lis.sort(key=lambda x: x[0])
  for i in lis:
    if i[0]!=mx:
      break
    ret.append(i[1])
  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

hmx=putmx(hb)
wmx=putmx(wb)
mhb=max(hl)
mwb=max(wl)
#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 collections
H,W,M=map(int,input().split())
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=map(int,input().split())
c1=collections.Counter(h)
c2=collections.Counter(w)
for x in range(M):
    if h[x]==c1.most_common()[0][0] and w[x]==c2.most_common()[0][0]:
        print(c1.most_common()[0][1]+c2.most_common()[0][1]-1)
        exit()
print(c1.most_common()[0][1]+c2.most_common()[0][1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
if H==1 and W == 1:
  print(1)
  exit()
hwlist = [list(map(int, input().split())) for i in range(M)]
a = []
b = []
for h in range(H):
    a.append(0)
for w in range(W):
    b.append(0)
for m in range(M):
    a[hwlist[m][0]-1] += 1
    b[hwlist[m][1]-1] += 1
max_a = max(a)
a_max_id = [i for i, v in enumerate(a) if v == max_a]
max_b = max(b)
b_max_id = [i for i, v in enumerate(b) if v == max_b]
print(f'{a_max_id}, {b_max_id}')
for i in range(len(a_max_id)):
    for j in range(len(b_max_id)):
        if not [a_max_id[i]+1, b_max_id[j]+1] in hwlist:
            print(max_a + max_b)
            exit()
print(max_a + max_b - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

#H, W, M = map(int, input().split())
#h = np.zeros(H)
#w = np.zeros(W)
m = np.zeros((3*10**2, 3*10**2))
ans = 3
'''
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
print(int(ans))

Submission status: Wrong Answer

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

for i in range(M):
    h, w = 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]
ans = h + w -1


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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    H, W, M = map(int, input().split())
    # H, W, M = (3 * 10 ** 5, 3 * 10 ** 5, 3 * 10 ** 5)

    row = [0] * (H + 1)
    row_set = [set() for _ in range(H+1)]
    column = [0] * (W + 1)
    column_set = [set() for _ in range(W+1)]
    # import random

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

        # h, w = (random.randrange(3*10**5), random.randrange(3*10**5))
        row[h] += 1
        row_set[h].add(w)
        # if h in row_set:
        #     row_set[h].add(w)
        # else:
        #     row_set.update({h: set({w})})

        column[w] += 1
        column_set[w].add(h)
        # if w in column_set:
        #     column_set[w].add(h)
        # else:
        #     column_set.update({w: set({h})})

    flatten_max_rows = []
    maxR = -1
    for i, v in enumerate(row[1:]):
        if v > maxR:
            flatten_max_rows = []
            if v != 0:
                flatten_max_rows += list(row_set[i+1])
            maxR = v
        elif v == maxR:
            flatten_max_rows += list(row_set[i+1])
    flatten_max_rows_set = set(flatten_max_rows)

    maxC = max(column)
    for i, v in enumerate(column[1:]):
        if v == maxC:
            if i+1 not in flatten_max_rows_set:
                print(maxR + maxC)
                exit()

    print(maxR + maxC - 1)
main()

Submission status: Wrong Answer

Solution code:
import collections

h,w,m = map(int,input().split())
hS = []
wS = []
S = set()

for i in range(m):
    a = list(map(int,input().split()))
    S.add(str(a[0]) + '-' + str(a[1]))
    hS.append(a[0])
    wS.append(a[1])
    

ans = 0

ch = collections.Counter(hS)
cw = collections.Counter(wS)

chm = []
cwm = []
#print(ch.most_common()[0])
chm.append(ch.most_common()[0])
#print(cw.most_common()[0])
cwm.append(cw.most_common()[0])
for i in chm:
    for j in cwm:
        if str(i[0]) + '-' + str(j[0]) in S:
            ans = i[1]+j[1]-1
        else:
            ans = i[1]+j[1]
            break

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import Counter

def main():
    h, w, m = map(int, input().split())
    
    row_list = []
    col_list = []
    
    check = []
    
    for i in range(m):
        x, y = map(int, input().split())
        row_list.append(x)
        col_list.append(y)
        check.append((x, y))
    c_row = Counter(row_list)
    c_col = Counter(col_list)
    
    max_row_list = [kv for kv in c_row.items() if kv[1]==max(c_row.values())]
    max_col_list = [kv for kv in c_col.items() if kv[1]==max(c_col.values())]
    # print(max_row_list, max_col_list)
    for row in max_row_list:
        for col in max_col_list:
            if not (row[0], col[0]) in check:
                print(row[1] + col[1])
                break
    else:
        print(row[1] + col[1] - 1)
    
  
 
main()

Submission status: Wrong Answer

Solution code:
def main():
    H,W,M = map(int,input().split())
    h = [[0,i] for i in range(H)]
    w = [[0,i] for i in range(W)]
    X = []
    for i in range(M):
        tmp_0,tmp_1 = map(int,input().split())
        tmp_0 -= 1
        tmp_1 -= 1
        h[tmp_0][0] += 1
        w[tmp_1][0] += 1
        X.append([tmp_0,tmp_1])
    
    list.sort(h, reverse=True)
    list.sort(w, reverse=True)
    max_h = h[0][0]
    max_w = w[0][0]
    ans = max_h + max_w
    for i in range(len(h)):
        if h[i][0] < max_h:
            h[:i]
            break
        
    for i in range(len(w)):
        if w[i][0] < max_w:
            w[:i]
            break
    
    flag = True
    for x in X:
        if not(x[0] in h and x[1] in w):
            flag = False
            break
    
    if flag:
        ans -= 1
    
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
#m = np.zeros((H, W))
ans = 3
'''
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys;input=sys.stdin.readline
H, W, M = map(int, input().split())
dx = [0]*H
dy = [0]*W
HH = set()
for _ in range(M):
    x, y = map(int, input().split())
    dx[x-1] += 1
    dy[y-1] += 1
    HH.add((x-1, y-1))
mx=max(dx)
my=max(dy)
mxs = set()
mys = set()
for i in range(H):
    if dx[i] == mx:
        mxs.add(i)
for i in range(W):
    if dy[i] == my:
        mys.add(i)
#print(mxs, mys, mx, my)
for x in mxs:
    for y in mys:
        if (x, y) not in HH:
            print(x, y)
            print(mx+my)
            sys.exit()
print(mx+my-1)

Submission status: Wrong Answer

Solution code:
import collections
H,W,M=map(int,input().split())
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=map(int,input().split())
c1=collections.Counter(h)
c2=collections.Counter(w)
ans=0
cnt=0
while cnt<len(c1)-1:
    cnt2=0
    while cnt2<len(c2)-1:
        flag=True
        for x in range(M):
            if h[x]==c1.most_common()[cnt][0] and w[x]==c2.most_common()[cnt2][0]:
                ans=max((ans,c1.most_common()[cnt][1]+c2.most_common()[cnt2][1]-1))
                flag=False
                break
        if flag:
            ans=max((ans,c1.most_common()[cnt][1]+c2.most_common()[cnt2][1]))
        if c2.most_common()[cnt2][1]>c2.most_common()[cnt2+1][1]:
            break
        cnt2+=1
    if c1.most_common()[cnt][1]>c1.most_common()[cnt+1][1]:
        break
    cnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import Counter

def main():
    h, w, m = map(int, input().split())
    
    row_list = []
    col_list = []
    
    check = []
    
    for i in range(m):
        x, y = map(int, input().split())
        row_list.append(x)
        col_list.append(x)
        check.append((x, y))
    c_row = Counter(row_list)
    c_col = Counter(col_list)
    
    max_row_list = [kv for kv in c_row.items() if kv[1]==max(c_row.values())]
    max_col_list = [kv for kv in c_col.items() if kv[1]==max(c_col.values())]
    for row in max_row_list:
        for col in max_col_list:
            if not (row[0], col[0]) in check:
                print(row[1] + col[1])
                break
    else:
        print(row[1] + col[1] - 1)
    
  
 
main()

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)]
bom_places=[]

boms=[[0 for j in range(W)] for i in range(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
  bom_places+=[[h-1,w-1]]
max=0
for i in bom_places:
  n1=row_boms[i[0]]
  n2=col_boms[i[1]]
  n=n1+n2-1
  if n>max:
    max=n
print(max)

Submission status: Wrong Answer

Solution code:
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = 0
    for k_h, v_h in H[:10]:
        for k_w, v_w in W[:10]:
            tmp = v_h + v_w
            if (k_h, k_w) in bom:
                tmp -= 1
            ans = max(tmp, ans)

    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import deque
from numba import jit

h,w,m=map(int,input().split())
B=[]
BB=set()
for i in range(m):
  hi,wi=map(int,input().split())
  B.append([hi,wi])
  BB.add((hi,wi))

@jit
def main():
  ans=0
  H=np.zeros(h+1,dtype='int64')
  W=np.zeros(w+1,dtype='int64')
  for i in range(m):
    H[B[i][0]]+=1
    W[B[i][1]]+=1
  mx=-float('inf')
  for i in range(1,h+1):
    for j in range(1,w+1):
      if [i,j] in B:
        pass
      else:
        mx=max(mx,H[i]+W[j])
  return mx
  
  

if __name__=='__main__':
  print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
H, W, M = list(map(int, input().split()))
row = np.zeros(H)
col = np.zeros(W)
maps = np.zeros((M, 2), dtype=np.int64)
sys.exit()

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
l = []

sh,sw,m = map(int,input().split())
H = [0]*sh
W = [0]*sw
for i in range(m):
    h,w = map(int,input().split())
    l.append((h-1,w-1))
    H[h-1] += 1
    W[w-1] += 1

maxh = max(H)
maxw = max(W)
# print(H,W)
# print(maxh,maxw)

hlist = []
wlist = []

for i in range(sh):
    if H[i] == maxh:
        hlist.append(i)
for j in range(sw):
    if W[j] == maxw:
        wlist.append(j)
# print(hlist,wlist)

if len(hlist)*len(wlist) > m:
    print(maxh+maxw)

ans = maxh+maxw-1
for i in hlist:
    for j in wlist:
        if (i,j) not in l:
            print(ans+1)
            exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
input = sys.stdin.readline
h,w,m=map(int, input().split())
hd=defaultdict(int)
wd=defaultdict(int)
hd2=[[] for i in range(h+1)]
hmax=0
wmax=0
for i in range(m):
    h0,w0=map(int, input().split())
    hd[h0]+=1
    hmax=max(hmax,hd[h0])
    hd2[h0].append(w0)
    wd[w0]+=1
    wmax=max(wmax,wd[w0])

max_h_list=[]
max_w_list=[]
for k in hd.keys():
    if hd[k]==hmax:
        max_h_list.append(k)

for k in wd.keys():
    if wd[k]==wmax:
        max_w_list.append(k)

Submission status: Wrong Answer

Solution code:
import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((2+1, 2+1), dtype=np.int64)
#for i in range(M):
#    [h, w] = map(int, input().split())
#    mp[h][w] = 1

#colsum = np.sum(mp, axis=0)
#rowsum = np.sum(mp, axis=1)

#maxcol = max(colsum)
#maxrow = max(rowsum)

#colchk = np.where(colsum==maxcol)
#rowchk = np.where(rowsum==maxrow)

#for i in range(len(rowchk[0])):
#    for j in range(len(colchk[0])):
#        if mp[rowchk[0][i]][colchk[0][j]] == 0:
#            print(int(max(colsum)+max(rowsum)))
#            quit()

#print(int(max(colsum)+max(rowsum))-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd
h, w, m = map(int, input().split())

#dic[row, col] -> set(ids)
h_dic = dd(int)
w_dic = dd(int)
spot = set()

for i in range(m):
    h_c, w_c = map(int, input().split())
    h_dic[h_c] += 1
    w_dic[w_c] += 1
    spot.add((h_c, w_c))
#print(h_dic, w_dic)

#H_lis -> [i, num_spot(int)]
max_h_num = 0
for key, val in h_dic.items():
    max_h_num = max(max_h_num, val)
max_w_num = 0
W_lis = []
for key, val in w_dic.items():
    max_w_num = max(max_w_num, val)


#print(H_lis, W_lis)
#print(max_h)

ans = 0
max_h_lis = [key for key in h_dic if h_dic[key] == max_h_num]
max_w_lis = [key for key in w_dic if w_dic[key] == max_w_num]
for i in max_h_lis:
    for j in max_w_lis:
        if (i, j) not in spot:
            print(max_h_num * max_w_num)
            break
else:
    print(max_h_num * max_w_num - 1)

"""    
max_counter = 0
for i in h_dic.keys():
    for j in w_dic.keys():
        counter = len(h_dic[i] | w_dic[j])
        #print(i, j, h_dic[i] | w_dic[j],counter)
        max_counter = max(max_counter, counter)
print(max_counter)

"""

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    h, w, m = LI()
    mat = [[0 for i in range(w+1)] for i in range(h+1)]
    hs = defaultdict(int)
    ws = defaultdict(int)
    for i in range(m):
        hi, wi = LI()
        mat[hi][wi] = 1
        hs[hi] += 1
        ws[wi] += 1

    hsums_top = []
    wsums_top = []

    maxh = max(hs)
    maxw = max(ws)

    # maxh = 0
    for i, top in hs.items():
        if maxh == top:
            hsums_top.append(i)
        # elif maxh < top:
        #     maxh = top
        #     hsums_top = [i]

    # maxw = 0
    for i, top in ws.items():
        if maxw == top:
            wsums_top.append(i)
        # elif maxw < top:
        #     maxw = top
        #     wsums_top = [i]

    if len(hsums_top) * len(wsums_top) > m:
        print(maxh + maxw)
        return
    for i in hsums_top:
        for j in wsums_top:
            if mat[i][j] == 0:
                print(maxh + maxw)
                return
    print(maxh + maxw - 1)


if __name__ == '__main__':
    main()

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 (x[i][0],y[j][0]) in s:
        pass
    else:
        sw = 1
        break
    if x[i][1] + y[j][1] != ma+mb:
        break
    
    if x[i+1][1] != ma:
        j += 1
        i = 0
    else:
        i += 1
print(ma+mb+sw-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H, W, M = list(map(int, input().split()))
row = np.zeros(H)
col = np.zeros(W)
#maps = np.zeros((M, 2), dtype=np.int64)
for i in range(M):
    h, w =list(map(int, input().split()))
    row[h-1] += 1
    col[w-1] += 1
    #maps[i] = [h - 1, w - 1]

rowMax = row.max()
colMax = col.max()
rowMaxs = np.where(row == rowMax)
colMaxs = np.where(col == colMax)
d = 1
'''
for i in rowMaxs[0]:
    for j in colMaxs[0]:
        if not np.any(np.all(maps == [i, j], axis = 1)):
            d = 0
            break
    if d == 0:
        break
'''

print(int(rowMax + colMax - d))

Submission status: Wrong Answer

Solution code:
#E
import os
import sys
import numpy as np
from collections import Counter

def main():
    # height, width, m = map(int, input().split())
    # h = [0] * m
    # w = [0] * m
    # for i in range(m):
    #     h[i], w[i] = map(int, input().split())
    height = inp[0]
    width = inp[1]
    m = inp[2]
    h = inp[3::2] - 1
    w = inp[4::2] - 1
    
    ch = Counter()
    ch.update(h)
    cw = Counter()
    cw.update(w)
    
    row = int(ch.most_common()[0][0])
    col = int(cw.most_common()[0][0])
    
    flag = False
    index = np.where(h == row)
    l = len(index[0])
    
    for i in range(l):
        if w[index[0][i]] == col:
            flag = True
    
    if flag:
        print(ch.most_common()[0][1] + cw.most_common()[0][1] - 1)
    else:
        print(ch.most_common()[0][1] + cw.most_common()[0][1])
    
if __name__ == "__main__":
    if os.name == 'posix':
        # noinspection PyUnresolvedReferences
        #from my_module import solve
        1
    else:
        from numba import njit
     
        solve = njit('(i8[:],)', cache=True)(solve)
        print('compiled', file=sys.stderr)
     
    inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
    
    # ans = solve(inp)
    # print('\n'.join(map(str, ans)))
    
    main()