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:
# -*- coding: utf-8 -*-
from collections import Counter as C

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

hs, ws = [], []
hw = []

for i in range(m):
    hi, w = map(int, input().split())
    hs.append(hi)
    ws.append(w)
    hw.append([hi, w])


ch = C(hs).most_common()
cw = C(ws).most_common()
anss = []
pre_ans = -float('inf')
mrow = ch[0][0]
mcow = cw[0][0]

for num1, num2 in zip(ch, cw):
    row, cow = num1[0], num2[0]
    if mrow > row or mcow > cow:
        break
    ans1 = hs.count(row)
    ans2 = ws.count(cow)
    ans = ans1 + ans2

    if [row, cow] in hw:
        ans -= 1

    anss.append(ans)

    if pre_ans >= ans:
        ans = pre_ans
        break
    else:
        pre_ans = ans


print(max(anss))

Submission status: Wrong Answer

Solution code:
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) 

I=sys.stdin.readline

 #s="abcdefghijklmnopqrstuvwxyz"

"""
x_move=[-1,0,1,0,-1,1,1,-1]
y_move=[0,1,0,-1,1,1,-1,-1]
"""
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


	
	

	

def main():
	h,w,m=mi()
	if h==1 or w==1:
		print(m) 
	else:
		row=defaultdict(int)
		col=defaultdict(int)

		d=defaultdict(int)
		for _ in range(m):
			x,y=mi()
			d[(x,y)]=1
			row[x]+=1
			col[y]+=1


		r_max=max(row.values())
		c_max=max(col.values())
		r_val=0
		c_val=0
		
		for i in row:
			if row[i]==r_max:
				r_val=i
				break

		for j in col:
			if col[j]==c_max:
				c_val=j
				break



		#print(r_val,c_val)
		max_val=-1

		for i in range(1,w+1):
			if d[(r_val,i)]==1:
				if row[r_val]+col[i]-1>max_val:
					max_val=row[r_val]+col[i]-1
			elif row[r_val]+col[i]>max_val:
				max_val=row[r_val]+col[i]







		print(max_val)

	


	
	
	
		







	












	
	
	





if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import heapq
import collections
from heapq import heapify
H, W, M = map(int, input().split())
hw = set([tuple(map(int, input().split())) for i in range(M)])
D1 = [0]*H
D2 = [0]*W

for x, y in hw:
    x -= 1
    y -= 1
    D1[x] += 1
    D2[y] += 1

X = max(D1)
Y = max(D2)

h = [x for x in range(H) if D1[x] == X]
w = [x for x in range(W) if D2[x] == Y]
ans = X+Y-1
for x in h:
    for y in w:
        if (x+1, y+1) not in hw:
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from time import time

start = time()

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)

ans=0
for idx1,val1 in sum1:
  if time()-start>2.7:break
  for idx2,val2 in sum2:
    tmp = val1+val2-hw[(idx1,idx2)]
    ans = max(ans,tmp)
    
print(ans)

Submission status: Wrong Answer

Solution code:



def LI():
    return list(map(int,input().split()))
    
def OPEN():
    return map(int,open(0).read().split())
import numpy   
h,w,m=LI()
S=[[0]*w for i in range(h)]
for i in range(m):
    h,w=LI()
    S[h-1][w-1]=1
S=numpy.array(S)
now=0
ind_x=[]
ind_y=[]
Ssumx=[sum(i) for i in S]
SS=S.T
Ssumy=[sum(i) for i in SS]



mx=max(Ssumx)
for i,j in enumerate(Ssumx):
    if j==mx:
        ind_x.append((i,j))
my=max(Ssumy)
for i,j in enumerate(Ssumy):
    if j==my:
        ind_y.append((i,j))

Submission status: Wrong Answer

Solution code:
import random
h,w,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
exist = set()
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

for y,x in lis:
    exist.add(format(y).zfill(6)+format(x).zfill(6))
    tate[y-1][0] += 1
    yoko[x-1][0] += 1

tate.sort(key=lambda x:x[1])
yoko.sort(key=lambda x:x[1])
tate.sort(key=lambda x:x[0],reverse=True)
yoko.sort(key=lambda x:x[0],reverse=True)

ans = tate[0][0]+yoko[0][0]-1
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

i = 0
j = 0
while i < h and i <= 60:
    while j < w and j <= 60:
        ans = max(ans,tate[i][0]+yoko[j][0]-bool(format(tate[i][1]+1).zfill(6)+format(yoko[j][1]+1).zfill(6) in exist))
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
bom = [list(map(int, input().split())) for _ in range(m)]
ans = 0
for i in range(h):
    for j in range(w):
        cnt = 0
        for k in range(m):
            if bom[k][0] == i or bom[k][1] == j:
                cnt += 1
        ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
hm = [""]*h
h_len = [0]*h
wm = [""]*w
w_len = [0]*w
for i in range(m):
    hi, wi = map(str, input().split())
    hm[int(hi)-1] += wi
    h_len[int(hi)-1] += 1
    wm[int(wi)-1] += hi
    w_len[int(wi)-1] += 1
ans_1 = 0
ans_2 = 0

h_max = [i for i, v in enumerate(h_len) if v == max(h_len)]
w_max = [i for i, v in enumerate(w_len) if v == max(w_len)]

for i in h_max:
    for j in w_max:
        if str(j+1) in hm[i]:
            ans_1 = h_len[i] + w_len[j] - 1
        else:
            ans_2 = h_len[i] + w_len[j]
            break
    else:
        continue
    break

print(max(ans_1,ans_2))

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 = True
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:
      wind = 0
      break
  if found:
    break
  hind += 1
  if hind == H or hcol[hind][0] < hmax:
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
x=0
H,W,M = map(int,input().split())
h = [0]*M
w = [0]*M
for i in range(0,M):
  h[i],w[i] = map(int,input().split())
a = Counter(h).most_common()
b = Counter(w).most_common()
x = a[0][1]+b[0][1]
for i in range(0,M):
  if h[i] == a[0][0] and w[i] == b[0][0]:
    x = x-1
print(x)

Submission status: Wrong Answer

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

    row_dict = {}
    col_dict = {}
    maps = []

    try:
        while True:
            row, col = map(int, input().split())
            maps.append((row, col))

            if row_dict.get(row):
                row_dict[row] += 1
            else:
                row_dict[row] = 1

            if col_dict.get(col):
                col_dict[col] += 1
            else:
                col_dict[col] = 1
    except EOFError:
        # print(row_dict)
        # print(col_dict)
        # print(maps)

        row_max_key = max(row_dict, key=row_dict.get)
        col_max_key = max(col_dict, key=col_dict.get)

        total = row_dict[row_max_key]
        total += col_dict[col_max_key]

        if (row_max_key, col_max_key) in maps:
            total -= 1

        print(total)


def main():
    probE()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
inpl = lambda: list(map(int,input().split()))
H, W, M = inpl()
Shw = set()
Sh = []
Sw = []
for _ in range(M):
    h, w = inpl()
    h -= 1
    w -= 1
    Sh.append(h)
    Sw.append(w)
    Shw.add((h,w))

Gh = Counter(Sh).most_common()
Gw = Counter(Sw).most_common()
mh = Gh[0][1]
mw = Gw[0][1]
Lh = len(Gh)
Lw = len(Gw)
i = j = 0
while i < Lh and Gh[i][1] == mh:
    while j < Lw and Gw[j][1] == mw:
        if not (Gh[i][0],Gw[i][0]) in Shw:
            ans = Gh[0][1] + Gw[0][1]
            break
        j += 1
    else:
        i += 1
        continue
    break
else:
   ans = Gh[0][1] + Gw[0][1] - 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
h, w, m = map(int, input().split())
row = [0 for _ in range(h)]
col = [0 for _ in range(w)]
info = dict()
tmpx = [-1, -1]
tmpy = [-1, -1]
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if x not in info:
        info[x] = set()
    info[x].add(y)
    row[x] += 1
    if row[x] > tmpx[0]:
        tmpx[0] = row[x]
        tmpx[1] = x
    col[y] += 1
    if col[y] > tmpy[0]:
        tmpy[0] = col[y]
        tmpy[1] = y

res = tmpx[0]+tmpy[0]
if tmpx[1] in info and tmpy[1] in info[tmpx[1]]:
    res -= 1
print(max(res,0))

Submission status: Wrong Answer

Solution code:
from collections import Counter
h,w,m = map(int,input().split())
lir = []
lic = []
ans = 0
for _ in range(m):
    x,y = map(int,input().split())
    lir.append(x)
    lic.append(y)
maxr = Counter(lir).most_common()[0][0]
for i in range(m):
    if lir[i] == maxr:
        ans+=1
        lir[i] = -1
        lic[i] = w+i
if min(lic) == w:
    print(ans)
else:
    maxc = Counter(lic).most_common()[0][0]
    for i in lic:
        if i == maxc:
            ans+=1
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

xx=[]
yy=[]

for i in range(m):
  x,y=map(int,input().split())
  xx.append(x)
  yy.append(y)

import collections
cx = collections.Counter(xx)
cy = collections.Counter(yy)

mx=next(iter(cx))
my=next(iter(cy))

idx=[]
ans=0

for i,xxx in enumerate(xx):
  if xxx == mx:
    ans+=1
    idx.append(i)

for j,yyy in enumerate(yy):
  if j in idx:
    continue
  if yyy == my:
    ans+=1

print(ans+1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if w_cnt[i] == w_max:
        w_max_idx.append(i)

# print(h_max_idx)
# print(w_max_idx)

if len(h_max_idx)>=10**3:
    h_max_idx = h_max_idx[:10**3]
if len(w_max_idx)>=10**3:
    w_max_idx = w_max_idx[:10**3]

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
        ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]

lh,lw=[],[]

for i in range(h):
    lh.append(0)
for i in range(w):
    lw.append(0)

for i in range(m):
    lh[l[i][0]-1]+=1
    lw[l[i][1]-1]+=1

lhm=max(lh)
lhml=[i for i, x in enumerate(lh) if x == lhm]
lwm=max(lw)
lwml=[i for i, x in enumerate(lw) if x == lwm]

ll=[]
for i in range(len(lhml)):
    for j in range(len(lwml)):
        k=[]
        k.append(lhml[i]+1)
        k.append(lwml[j]+1)
        l.append(k)
        ll.append(k)

llc=len(ll)
l_arr = np.unique(l, axis=0)
if len(l_arr)==m+llc:print(lhm+lwm-1)
else:print(lhm+lwm)

Submission status: Wrong Answer

Solution code:
import random
h,w,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
exist = []
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

for y,x in lis:
    exist.append(format(y).zfill(6)+format(x).zfill(6))
    tate[y-1][0] += 1
    yoko[x-1][0] += 1

tate.sort(key=lambda x:x[1])
yoko.sort(key=lambda x:x[1])
tate.sort(key=lambda x:x[0],reverse=True)
yoko.sort(key=lambda x:x[0],reverse=True)

ans = tate[0][0]+yoko[0][0]-1
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

i = 0
j = 0
while i < h and i <= 50:
    while j < w and j <= 50:
        ans = max(ans,tate[i][0]+yoko[j][0]-bool(format(tate[i][1]+1).zfill(6)+format(yoko[j][1]+1).zfill(6) in exist))
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
h, w, m = map(int, input().split())
row = [0 for _ in range(h)]
col = [0 for _ in range(w)]
info = dict()
tmpx = [-1, -1]
tmpy = [-1, -1]
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if x not in info:
        info[x] = set()
    info[x].add(y)
    row[x] += 1
    if row[x] > tmpx[0]:
        tmpx[0] = row[x]
        tmpx[1] = x
    col[y] += 1
    if col[y] > tmpy[0]:
        tmpy[0] = col[y]
        tmpy[1] = y

res = tmpx[0]+tmpy[0]
if tmpx[1] in info and tmpy[1] in info[tmpx[1]]:
    res -= 1
print(res)

Submission status: Wrong Answer

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

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

#print(h)
#print(w)

# 重複要素のmaxを求める
hcount = [x for x in set(h) if h.count(x) > 1]

maxh = 0
hraw = 0
for i in range(len(hcount)):
    hcnt = h.count(hcount[i])
    if hcnt>maxh:
        maxh = hcnt
        hraw = hcount[i]
# 重複要素のmaxを求める
wcount = [x for x in set(w) if w.count(x) > 1]

maxw = 0
wraw = 0
for i in range(len(wcount)):
    wcnt = w.count(wcount[i])
    if wcnt>maxw:
        maxw = wcnt
        wraw = wcount[i]
if maxw == 0:
    maxw = 1

#print(hraw)
#print(wraw)

bomb = False
for i in range(len(h)):
    if h[i]==hraw and w[i]==wraw:
        bomb = True

cnt = maxh + maxw
if bomb:
    cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M = map(int,input().split( ))
Hs = [0 for _ in range(H)]
Ws = [0 for _ in range(W)]
hws = []
for _ in range(M):
    h,w = map(int,input().split( ))
    hws.append([h-1,w-1])
    Hs[h-1] += 1
    Ws[w-1] += 1
hw = [np.argmax(Hs),np.argmax(Ws)]
hs = []
ws = []
maxh = max(Hs)
maxw = max(Ws)
for h in Hs:
    if h == maxh:
        hs.append(h)
for w in Ws:
    if w == maxw:
        ws.append(w)

in_out = 0
for w in ws:
    for h in hs:
        if not([h,w] in hws):
            in_out = 1
if not(in_out):
    print(maxh + maxw - 1)
else:
    print(maxh + maxw)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
H, W, M = map(int, input().split())

h_list = [0 for _ in range(H + 1)]
w_list = [0 for _ in range(W + 1)]
m_list = [[0 for _ in range(W + 1)] for _ in range(H + 1)]
for i in range(M):
    h, w = map(int, input().split())
    h_list[h] += 1
    w_list[w] += 1
    m_list[h][w] = 1

max_h_list = []
max_h = -1
for i in range(H + 1):
    if max_h == h_list[i]:
        max_h_list.append(i)
    elif max_h < h_list[i]:
        max_h = h_list[i]
        max_h_list = [i]

max_w_list = []
max_w = -1
for i in range(W + 1):
    if max_w == w_list[i]:
        max_w_list.append(i)
    elif max_w < w_list[i]:
        max_w = w_list[i]
        max_w_list = [i]

print(max_h + max_w)
# adjust_dupl = 1
# for i in range(len(max_h_list)):
#     for j in range(len(max_w_list)):
#         if m_list[max_h_list[i]][max_w_list[j]] == 0:
#             adjust_dupl = 0
#             break
#     if adjust_dupl == 0:
#         break
# print(max_h + max_w - adjust_dupl)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import numpy as np

# 標準入力を取得
H, W, M = list(map(int, input().split()))
I, R = {}, {}
for m in range(M):
    h_m, w_m = list(map(int, input().split()))
    if h_m in I.keys():
        I[h_m].append(w_m)
    else:
        I[h_m] = [w_m]
    if w_m in R.keys():
        R[w_m].append(h_m)
    else:
        R[w_m] = [h_m]

# 求解処理
h_bom = -1
max_bom_h = 0
for h in I.keys():
    bom_h = len(I[h])
    if max_bom_h < bom_h:
        max_bom_h = bom_h
        h_bom = h

w_bom = -1
max_bom_w = 0
for w in R.keys():
    bom_w = len(R[w])
    if h_bom in R[w]:
        bom_w -= 1
    if max_bom_w < bom_w:
        max_bom_w = bom_w
        w_bom = w

ans = max_bom_h + max_bom_w

# 結果出力
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
H, W, M = map(int, input().split())
Hsum = [0] * H
Wsum = [0] * W
hw = []
for m in range(M):
  h, w = map(int, input().split())
  Hsum[h-1] += 1
  Wsum[w-1] += 1
  hw.append(str(h-1)+"_"+str(w-1))

hmax_ind = list(map(lambda x: True if x == max(Hsum) else False, Hsum))
hmax_ind = list(itertools.compress(range(len(Hsum)), hmax_ind))
wmax_ind = list(map(lambda x: True if x == max(Wsum) else False, Wsum))
wmax_ind = list(itertools.compress(range(len(Wsum)), wmax_ind))

res = []
for n in itertools.product(hmax_ind, wmax_ind):
  res.append(str(n[0])+"_"+str(n[1]))
if len(set(res).intersection(set(hw))) == len(hw):
  print(max(Hsum) + max(Wsum))
else:
  print(max(Hsum) + max(Wsum)-1)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int, input().split())
hw=[list(map(int, input().split())) for _ in range(m)]

tate=[]
yoko=[]

for i in range(m):
    tate.append(hw[i][0])
    yoko.append(hw[i][1])

from collections import Counter

tatec=Counter(tate).most_common()
yokoc=Counter(yoko).most_common()

c_1=tatec[0][0]
c_2=yokoc[0][0]

flag=True
for i in range(m):
    h_i=hw[i][0]
    w_i=hw[i][1]
    if h_i==c_1 and w_i==c_2:
        flag=False

print(tatec[0][1]+yokoc[0][1] if flag else tatec[0][1]+yokoc[0][1]-1)

Submission status: Wrong Answer

Solution code:
import random
h,w,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
exist = []
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

for y,x in lis:
    exist.append(format(y).zfill(6)+format(x).zfill(6))
    tate[y-1][0] += 1
    yoko[x-1][0] += 1

tate.sort(key=lambda x:x[1])
yoko.sort(key=lambda x:x[1])
tate.sort(key=lambda x:x[0],reverse=True)
yoko.sort(key=lambda x:x[0],reverse=True)

ans = tate[0][0]+yoko[0][0]-1
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

i = 0
j = 0
while i < h and i <= 30:
    while j < w and j <= 30:
        ans = max(ans,tate[i][0]+yoko[j][0]-bool(format(tate[i][1]+1).zfill(6)+format(yoko[j][1]+1).zfill(6) in exist))
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W,M = list(map(int,input().split()))

counterH = Counter()
counterW = Counter()
targets = set()
for i in range(M):
    h,w = list(map(int,input().split()))
    counterH[h] += 1
    counterW[w] += 1
    targets.add((h,w))

if M == 1:
    print(1)
else:
    ans = 2
    flg = False
    for count_H in counterH.most_common():
        for count_W in counterW.most_common():
            # print(count_H,count_W)
            if (count_H[0],count_W[0]) in targets:
                ans = max(ans,count_H[1]+count_W[1]-1)
                # print(count_H[1]+count_W[1]-1)
            else:
                ans = max(ans,count_H[1]+count_W[1])
                flg = True
                # print(count_H[1]+count_W[1])
            if flg:
                break
        if flg:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
N=[[0]*W]*H
a=0
for i in range(M):
  h,w=map(int,input().split())
  for j in range(H):
    N[j][w-1]+=1
    j=0
  for k in range(W):
    N[h-1][k]+=1
  N[h-1][w-1]-=1
for i in range(W):
  for j in range(H):
    if a<N[j][i]:
      a=N[j][i]
print(a)

Submission status: Wrong Answer

Solution code:
import collections

h, w, m = map(int, input().split())
HW = [list(map(int, input().split())) for _ in range(m)]
H = []
W = []
for hw in HW:
    H.append(hw[0])
    W.append(hw[1])
ch = collections.Counter(H)
h = ch.most_common()[0][0]
cw = collections.Counter(W)
w = cw.most_common()[0][0]
cnt = 0
for hw in HW:
    if hw[0] == h:
        cnt += 1
    elif hw[1] == w:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import product
H,W,M = map(int,input().split())
h_list = [0] * M
w_list = [0] * M
for m in range(M):
    h_list[m],w_list[m] = map(int,input().split())
hh_list = [0] * H
ww_list = [0] * W
for m in range(M):
    hh_list[h_list[m]-1] += 1
for m in range(M):
    ww_list[w_list[m]-1] += 1
h_max = max(hh_list)
w_max = max(ww_list)

h_ans = []
w_ans = []

for hh in range(H):
    if hh_list[hh] == h_max:
        h_ans.append(hh)
for ww in range(W):
    if ww_list[ww] == w_max:
        w_ans.append(ww)
h_ans_len = len(h_ans)
w_ans_len = len(w_ans)
hw_point = h_ans_len * w_ans_len
if h_ans_len == 1:
    if hw_point > h_max:
        print(h_max + w_max)
    else:
        print(h_max + w_max - 1)
elif w_ans_len == 1:
    if hw_point > w_max:
        print(h_max + w_max)
    else:
        print(h_max + w_max - 1)
else:
    if hw_point > h_max * h_ans_len:
        print(h_max + w_max)
    else:
        print(h_max + w_max - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M=map(int,input().split())
h=[0]*H
w=[0]*W
xy=[]
for i in range(M):
    x,y=map(int,input().split())
    xy.append([x,y])
    h[x-1]+=1
    w[y-1]+=1
ans=max(h)+max(w)
hm=list(*np.where(h == np.max(h)))
wm=list(*np.where(w == np.max(w)))
#for j in range(M):
#    x = xy[j][0]
#    y = xy[j][1]
#    for n in hm:
#        if x==n+1:
#            for m in wm:
#                if y==m+1:
#                    break
for n in hm:
    for m in wm:
        if [n+1,m+1] in xy:
#        for j in range(M):
#            x = xy[j][0]
#            y = xy[j][1]
#            if x == n + 1 and y == m + 1:
            break
        else:
            print(ans)
            exit()
print(ans-1)

Submission status: Wrong Answer

Solution code:
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)]
for m in range(M):
    h, w = map(int, input().split())
    # import random
    # h, w = (random.randrange(3*10**5), random.randrange(3*10**5))
    row[h] += 1
    row_set[h].add(w)
    column[w] += 1
    column_set[w].add(h)

maxR = max(row)

flatten_max_rows = set()
for i, v in enumerate(row):
    if v != maxR:
        continue
    flatten_max_rows = flatten_max_rows | row_set[i]

maxC = max(column)
for i, v in enumerate(column):
    if v == maxC:
        if i not in flatten_max_rows:
            print(maxR + maxC)
            exit()

print(maxR + maxC - 1)

Submission status: Wrong Answer

Solution code:
import numpy

H,W,M = map(int, input().split())
row = [0 for i in range(H)]
col = [0 for i in range(W)]
m = []
for i in range(M):
  h,w = map(int, input().split())
  m.append((h,w))
  row[h-1] += 1
  col[w-1] += 1

ax = numpy.argmax(row)
ay = numpy.argmax(col)
res=0
#print(ax,ay)
#print(m)
for i in m:
  if(i[0]==ax+1 or i[1]==ay+1):
    res+=1
    
print(res)

Submission status: Wrong Answer

Solution code:
import random
h,w,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
exist = []
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

for y,x in lis:
    exist.append(format(y).zfill(6)+format(x).zfill(6))
    tate[y-1][0] += 1
    yoko[x-1][0] += 1

tate.sort(key=lambda x:x[1])
tate.sort(key=lambda x:x[0],reverse=True)
yoko.sort(key=lambda x:x[0],reverse=True)

ans = tate[0][0]+yoko[0][0]-1
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

i = 0
j = 0
while i < h and i <= 30:
    while j < w and j <= 30:
        ans = max(ans,tate[i][0]+yoko[j][0]-bool(format(tate[i][1]+1).zfill(6)+format(yoko[j][1]+1).zfill(6) in exist))
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split(' '))
row = dict()
col = dict()
tar = []
for i in range(m):
    r, c = map(int, input().split(' '))
    tar.append([r, c])
    if r in row.keys():
        row[r] += 1
    else:
        row[r] = 1
    if c in col.keys():
        col[c] += 1
    else:
        col[c] = 1

res = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        t = 0
        if [i, j] not in tar:
            if i in row.keys():
                t += row[i]
            if j in col.keys():
                t += col[j]
            res = max(res, t)
print(res)

Submission status: Wrong Answer

Solution code:
import collections

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

li, row_li, column_li = [], [], []

sum_row, sum_column, count = 0, 0, 0

for i in range(m):
    temp_li = list(map(int, input().split()))
    row_li.append(temp_li[0])
    column_li.append(temp_li[1])
    li.append(temp_li)

c_row = collections.Counter(row_li)
c_column = collections.Counter(column_li)

for n in li:
    if n[0] == c_row.most_common()[0][0] or n[1] == c_column.most_common()[0][0]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
hw1, hw2 = deepcopy(hw), deepcopy(hw)
hw1.sort()
hw2.sort(key=lambda x:x[1], reverse=True)
ans1, ans2 = 0, 0
cur1, cur2 = 1, 1
ind1, ind2 = float("inf"), float("inf")
sec1, sec2 = 0, 0
for i in range(1, m):
    if hw1[i][0] != hw1[i - 1][0]:
        if cur1 > ans1:
            ind1 = hw1[i - 1][0]
            sec1 = ans1
            ans1 = max(ans1, cur1)
        else:
            sec1 = max(sec1, cur1)
        cur1 = 1
    else:
        cur1 += 1
if cur1 >= ans1:
    ind1 = hw1[-1][0]
    sec1 = ans1
    ans1 = max(ans1, cur1)
for i in range(1, m):
    if hw2[i][1] != hw2[i - 1][1]:
        if cur2 > ans2:
            ind2 = hw[i - 1][1]
            sec2 = ans2
            ans2 = max(ans2, cur2)
        else:
            sec2 = max(sec2, cur2)
        ans2 = max(ans2, cur2)
        cur2 = 1
    else:
        cur2 += 1
if cur2 >= ans2:
    ind2 = hw2[-1][1]
    sec2 = ans2
    ans2 = max(ans2, cur2)
print(ind1, ind2)
if [ind1, ind2] in hw:
    print(ans1 + ans2 - 1)
else:
    print(ans1 + ans2)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
dicti={}
dictj={}
bomb=[]
for i in range(M):
  h,w=map(int,input().split())
  bomb.append((h,w))
  if h in dicti:
    dicti[h]+=1
  if h not in dicti:
    dicti[h]=1
  if w in dictj:
    dictj[w]+=1
  if w not in dictj:
    dictj[w]=1
LI=sorted(dicti.items(),key=lambda x:x[1],reverse=True)
LJ=sorted(dictj.items(),key=lambda x:x[1],reverse=True)
answer=0
for i in range(min(len(LI),10)):
  for j in range(min(len(LJ),10)):
    ans=LI[i][1]+LJ[j][1]
    if (LI[i][0],LJ[j][0]) in bomb:
      ans-=1
    answer=max(ans,answer)
print(answer)

Submission status: Wrong Answer

Solution code:
h, w, m = list(map(int, input().split()))
bh = [0]*h
bw = [0]*w
bhw = [[0]*w]*h
hmaxs = []
wmaxs = []

for i in range(m):
    h,w = map(int, input().split())
    bh[h-1] +=1
    bw[w-1] +=1
    bhw[h-1][w-1] +=1

maxbh= max(bh)
maxbw =max(bw)

for i in range(h):
    if bh[i] == maxbh:
        hmaxs.append(i)

for i in range(w):
    if bw[i] == maxbw:
        wmaxs.append(i)

c =1

for i in hmaxs:
    for j in wmaxs:
        if bhw[i][j]==0:
            c=0

print(maxbh + maxbw -c)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int, input().split())
mx=[[0,i] for i in range(W)]
my=[[0,i] for i in range(H)]
bs =[]
for i in range(M):
    y,x = map(int, input().split())
    mx[x-1][0] += 1
    my[y-1][0] += 1
    bs.append((x-1,y-1))

mx.sort(reverse=True)
my.sort(reverse=True)

ans = 0
mxx = 0
myy = 0
for x in mx:
    mxx = max(mxx, x[0])
    if x[0] + 1 < mxx:
        break
    for y in my:
        myy = max(myy, y[0])
        if y[0] + 1 < myy:
            break
        s = x[0] + y[0]
        if (x[1],y[1]) in bs:
            s -= 1
        ans = max(ans, s)
        print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
i = list(map(int, input().split()))
H=i[0]
W=i[1]
N=i[2]
h=[0]*H
w=[0]*W
a = [[0 for j in range(W)] for i in range(H)]
for j in range(N):
    i = list(map(int, input().split()))
    h[i[0]-1]+=1
    w[i[1]-1]+=1
    a[i[0]-1][i[1]-1]=1
if a[h.index(max(h))][w.index(max(w))]==1:
    print(max(h)+max(w)-1)
else:
    print(max(h)+max(w))

Submission status: Wrong Answer

Solution code:
def main():
    h,w,m=map(int,input().split())
    target=[0]*m
    for i in range(m):
        th,tw=map(int,input().split())
        target[i]=(th-1,tw-1)
    lines=[0]*w
    rows=[0]*h
    for th,tw in target:
        lines[tw]+=1
        rows[th]+=1
    max_lines=max(lines)
    max_rows=max(rows)
    max_wi=[i for i,wi in enumerate(lines) if wi==max_lines]
    max_hi=[i for i,hi in enumerate(rows) if hi==max_rows]
    # print(max_rows,max_hi,max_lines,max_wi)
    ans=max_lines+max_rows-1
    for wi in max_wi:
        for hi in max_hi:
            if not (hi,wi) in target:
                ans+=1
                break
    return ans

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

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

h,w,m = map(int,readline().split())
inp = [list(map(int,readline().split())) for i in range(m)]

x = [0] * h
y = [0] * w

for i in range(m):
    inp[i][0] -= 1
    inp[i][1] -= 1

for xi,yi in inp:
    x[xi] += 1
    y[yi] += 1

ans = max(x)
idx = x.index(ans)


for xi,yi in inp:
    if idx == xi:
        y[yi] -= 1

ans += max(y)
print(ans)