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: Runtime Error

Solution code:
H, W ,M = map(int,input().split())
t = [0] * M
x = [0] * M
for i in range(M):
    t[i], x[i] = map(int, input().split())
tate=[0]*H
yoko=[0]*W
for i in range(1,H+1):
    tate[i-1]=t.count(i)
for i in range(1,H+1):
    yoko[i-1]=x.count(i)
print(max(yoko)+max(tate)-1)

Submission status: Runtime Error

Solution code:
import numpy as np

h, w, m = map(int, input().split())
bb = [[0] * w for _ in range(h)]
mx = 0
for _ in range(m):
    bh, bw = map(int, input().split())
    bb[bh - 1][bw - 1] = 1
smr = np.sum(bb,axis=1)
bb.pop(np.argmax(smr))
smc = np.sum(bb,axis=0)
print(max(smr) + max(smc))

Submission status: Runtime Error

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


for _ in range(m):
    a,b = map(int, input().split())
    try:
        x[a-1][b-1] = 1
    except IndexError:
        continue

ans = 0
temp = 0
for i in range(h):
    for j in range(w):
        temp = 0

        for n in range(h):
            if x[n][j] == 1:
                temp += 1
        temp += sum(x[i])
        if x[i][j] == 1:
            temp -= 1
        ans = max(ans,temp)
            
print(int(ans))

Submission status: Runtime Error

Solution code:
import collections
H,W,M = map(int, input().split())
hw = [map(int, input().split()) for _ in range(M)]
h, w = [list(i) for i in zip(*hw)]
 
cnt = 0
h_p = collections.Counter(h).most_common()
h_s = h_p[0][0]
 
for i in range(M):
  if h[i] == h_s:
    w[i] = 0
    cnt += 1

w_p = collections.Counter(w).most_common()
if w_p[0][0] == 0:
  w_s_1 = w_p[1][0]
else:
  w_s_1 = w_p[0][0]

for i in range(len(w)):
  if w[i] == w_s_1:
    cnt += 1
    
print(cnt)

Submission status: Runtime Error

Solution code:
H,W,M=map(int,input().split(" ")) 
hl=[] 
wl=[] 
c=[list(input().split(" "))for i in range(M)]
for i in range(M): 
    hl.append(c[i][0]) 
    wl.append(c[i][1]) 
from collections import Counter 
ac=Counter(hl)
bc=Counter(wl)

a=ac.most_common()
b=bc.most_common()
count=a[0][1]+b[0][1]-1
def f(*d):
    for i in range(len(d)):
        if d[0][1]>d[i][1]:
            return int(i-1)
        else:
            return 1
for i in range(f(a)):
    for j in range(f(b)):
        if [a[i][0],b[j][0]] not in c:
            count+=1
            break
    else:
        continue
print(count)

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for i in range(m)]
hs=[0]*h
ws=[0]*w
field=[[0]*w for i in range(h)]
k=0

for hx,wx in hw:
  field[hx-1][wx-1]=1
  hs[h-1]+=1
  ws[w-1]+=1
hmax=max(hs)
wmax=max(ws)
hindexs=[i for i, x in enumerate(hs) if x == hmax]
windexs=[i for i, x in enumerate(ws) if x == wmax]
#print(hindexs,windexs)
for x in hindexs:
  for y in windexs:
    if field[x][y]==0:
      k=1
      break
      
if k==1:
  print(hmax+wmax)
else:
  print(hmax+wmax-1)

Submission status: Runtime Error

Solution code:
import numpy as np

HWM = [int(a) for a in input().split()]
H = HWM[0]
W = HWM[1]
M = HWM[2]

Bombs = [[int(b) for b in input().split()] for l in range(M)]

npBombs = np.zeros((H,W))
for x,y in Bombs:
  npBombs[x-1,y-1] = 1

Hs = []
for x in range(H):
  s = int(np.sum(npBombs[x,:]))
  Hs.append(s)

Ws = []
for y in range(W):
  s = int(np.sum(npBombs[:, y]))
  Ws.append(s)

Hmax = int(max(Hs))
Wmax = int(max(Ws))

answer = Hmax + Wmax - 1
for x in range(H):
  for y in range(W):
    if Hs[x] == Hmax and Ws[y] == Wmax:
      if npBombs[x,y] == 0:
      	answer = Hmax + Wmax

print(answer)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
import numpy as np
array_hw = np.zeros((h,w)) 
for i in range(m):
    h_loc, w_loc = map(int, input().split())
    array_hw[h_loc - 1, w_loc - 1] = 1
a = np.sum(array_hw,axis=0)
b = np.sum(array_hw,axis=1)
maxIndex_retu = [i for i, x in enumerate(a) if x == max(a)]
maxIndex_gyou = [i for i, x in enumerate(b) if x == max(b)]
import itertools
count = 0
for i in list(itertools.product(maxIndex_gyou, maxIndex_retu)):
    count += (array_hw[i] == 0)
print(int(np.max(a)  + np.max(b) - (count == 0)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

check = np.zeros((h, w)).astype(np.uint16)

for i,j in li:
    check[i-1, :] += 1
    check[:, j-1] += 1
    check[i-1, j-1] -= 1

print(int(np.max(check)))

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
hwList = [[0] * (w + 1) for i in range(h + 1)]
hList = [0] * (h + 1)
wList = [0] * (w + 1)
for x in range(m):
    h_i, w_i = map(int, input().split())
    hList[h_i] += 1
    wList[w_i] += 1
    hwList[h_i][w_i] += 1
h_max = max(hList)
w_max = max(wList)
h_maxid = [i for i, v in enumerate(hList) if v == h_max]
w_maxid = [i for i, v in enumerate(wList) if v == w_max]
isminus = 1
if len(h_maxid) * len(w_maxid) > 3 * (10 ** 5): isminus = 0
else:
    for a in h_maxid:
        if isminus == 0: break
        for b in w_maxid:
            if hwList[a][b] == 1: continue
            isminus = 0
            break
print(max(hList) + max(wList) - isminus)

Submission status: Runtime Error

Solution code:
import numpy as np
R,C,M=input().split()
row=int(R)
col=int(C)
m=int(M)
main=[]
arr=np.zeros((row,col))
for i in range(m):
  A,B=input().split()
  a=int(A)-1
  b=int(B)-1
  arr[a][b]=1
c_sum=arr.sum(axis=0)
r_sum=arr.sum(axis=1)
l_r=len(r_sum)
l_c=len(c_sum)

for i in range(l_r):
    for j in range(l_c):
        main.append(r_sum[i]+c_sum[j])
main.sort()
print(int(main[-1]))

Submission status: Runtime Error

Solution code:
import sys, math, heapq, bisect





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

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


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

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


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


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

    pos_x= bisect.bisect_left(Ws, Ws[-1])
    pos_y= bisect.bisect_left(Hs, Hs[-1])
    #print(W_N_bomb, H_N_bomb, pos_x, pos_y)
    for i in range(pos_x, W):
        for j in range(pos_y, H):
            value = Ws[i] + Hs[j]
            pos_i = W_N_bomb[i][1]
            pos_j = H_N_bomb[j][1]
            if(bombs[pos_j][pos_i]==1):
                value -= 1
            heapq.heappush(queues, (-1) * value)
    print(-1 * queues[0])

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, N = list(map(int, input().rstrip().split(' ')))

dist = np.zeros([H, W])

for _ in range(N):
    h, w = list(map(int, input().rstrip().split(' ')))
    dist[h - 1, w - 1] = 1


ans = 0

#for h in range(H):
#    for w in range(W):
#        _sum = dist[h].sum() + dist[:, w].sum() - dist[h, w]   
#        ans = max(ans, _sum)
#print(int(ans))
        
h_sum = dist.sum(axis=0)
w_sum = dist.sum(axis=1)


new_dist = np.zeros_like(dist)

for h in range(H):
    new_dist[h] = w_sum[h] + h_sum - dist[h]


    
#print(dist)
#print(new_dist)

print(int(new_dist.max()))

Submission status: Runtime Error

Solution code:
from collections import Counter
H, W, M = [int(i) for i in input().split()]
g = [[0] * M for i in range(M)]
h = [0] * M
w = [0] * M
for i in range(M):
    h[i], w[i] = [int(j) for j in input().split()]
    g[h[i]-1][w[i]-1] = 1

ch = Counter(h)
cw = Counter(w)

hi = [i for i in ch.keys() if ch[i] == max(ch.values())]
wi = [i for i in cw.keys() if cw[i] == max(cw.values())]

for i in hi:
    for j in wi:
        if g[i-1][j-1] == 0:
            print(ch[i] + cw[j])
            exit()
print(ch[hi[0]] + cw[wi[0]] - 1)

Submission status: Runtime Error

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((H, W), 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[hi,wi]+=1
  yn=1
  hm=np.max(h)
  wm=np.max(w)
  #print(hw)
  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])
          if hw[j,k]==0:
            yn=0
            break
      else:
        continue
      break
  print(hm+wm-yn)
main()

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

# input
H, W, M = map(int, input().split()) # H * Mのマス目, M個のターゲット
A = np.zeros(H * W)
A = A.reshape(H, W)
for _ in range(M):
    i, j = map(int, input().split())
    A[i - 1][j - 1] = 1

# print(A, "\n")

# output
a = np.sum(A, axis=0)
b = np.sum(A, axis=1)

a_max, b_max = map(int, (a.max(), b.max()))
a_i_list = np.where(a == a_max)
b_i_list = np.where(b == b_max)

# print(a, b)
# print(a_i_list, b_i_list)

flg = False
for a_i, b_i in itertools.product(a_i_list[0], b_i_list[0]):
    if A[a_i][b_i] == 0:
        flg = True
        break

if flg:
    print(a_max + b_max)
else:
    print(a_max + b_max - 1)

Submission status: Runtime Error

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

from collections import defaultdict
counter_h = defaultdict(int)
counter_w = defaultdict(int)

for i in range(M):
    h[i],w[i] = map(int, input().split())
    counter_h[h[i]] += 1
    counter_w[w[i]] += 1
    
MAX_h = max(counter_h.values())
h_list = [k for k, v in counter_h.items() if v == MAX_h]
MAX_w = max(counter_w.values())
w_list = [k for k, v in counter_w.items() if v == MAX_w]

import itertools

if len(h_list)*len(w_list)<=3*10**5:
    X = list(itertools.product(h_list, w_list))

    ans = MAX_h+MAX_w
    check = 0


    for i in range(M):
            if (h[i],w[i]) in X:
                check += 1

    if len(X)==check:
        ans -= 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import collections
h,w,m=map(int,input().split())
H=[]
W=[]
S=[]
for _ in range(m):
  a,b=map(int,input().split())
  H.append(a)
  S.append([a,b])
  
HC=collections.Counter(H)
commonHC=HC.most_common()[0][0]
for i in range(m):
  if S[i][0]!=commonHC:
    W.append(S[i][1])
WC=collections.Counter(W)
commonWC=WC.most_common()[0][0]

print(HC[commonHC]+WC[commonWC])

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
FIELD = [[0] * W for i in range(H)]
w_list = [0] * W
h_list = [0] * H
for i in range(M):
    h, w = map(int, input().split())
    FIELD[h-1][w-1] = 1
    w_list[w-1] += 1
    h_list[h-1] += 1

max_value_h = max(h_list)
max_index_h = [i for i, x in enumerate(h_list) if x == max_value_h]

max_value_w = max(w_list)
max_index_w = [i for i, x in enumerate(w_list) if x == max_value_w]

ans = 0
for i in max_index_h:
    for j in max_index_w:
        if FIELD[i][j] == 1:
            ans = max(ans, h_list[i]+w_list[j]-1)
        else:
            ans = max(ans, h_list[i]+w_list[j])
print(ans)

Submission status: Runtime Error

Solution code:
from statistics import mode
H, W, M = map(int, input().split())
H_l = []
W_l = []
for i in range(M):
    a, b = map(int, input().split())
    H_l.append(a)
    W_l.append(b)

h = mode(H_l)
w = mode(W_l)
seen = [True] * M
res = 0
for i in range(M):
    if (H_l[i] == h):
        res += 1
        seen[i] = False
    else:
        continue

for j in range(M):
    if (W_l[j] == w and seen[j]):
        res += 1
    else:
        continue
print(res)

Submission status: Runtime Error

Solution code:
a=list(map(int,input().split()))
h=a[0]
w=a[1]
m=a[2]
sh=[0]*1000000
sw=[0]*1000000
mw=0
mh=0
for i in range (0,m):
    s=list(map(int,input().split()))
    sh[s[0]]+=1
    if sh[s[0]]>mh:
        mh=sh[s[0]]
        hh=s[0]
    sw[s[1]]+=1
    if sw[s[0]]>mw:
        mw=sw[s[0]]
        ww=s[1]
z=mh+mw
if sh[hh]>0 and sw[ww]>0:
    z-=1

print(z)

Submission status: Runtime Error

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

hc = [0] * H
wc = [0] * W
hwc = [[0] * W for _ in range(H)]
for _ in range(M):
    h, w = map(lambda x: int(x) - 1,input().split())
    hc[h] += 1
    wc[w] += 1
    hwc[h][w] += 1

result = 0
for h in range(H):
    for w in range(W):
        result = max(result, hc[h] + wc[w] - hwc[h][w])
print(result)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

Submission status: Runtime Error

Solution code:
H,W,M=map(int,input().split())
dp=[[0]*W for i in range(H)]
dp_h=[0]*H
dp_w=[0]*W

for i in range(M):
  h,w=map(int,input().split())
  dp_h[h-1]+=1
  dp_w[w-1]+=1
  dp[h-1][w-1]+=1
max_h=max(dp_h)
max_w=max(dp_w)
max_dp_h=[i for i, x in enumerate(dp_h) if x==max_h]
max_dp_w=[i for i, x in enumerate(dp_w) if x==max_w]
flag=True
for i in max_dp_h:
  for j in max_dp_w:
    if dp[i][j]!=1:
      flag=False
      break
if flag:
  print(max_h+max_w-1)
else:
  print(max_h+max_w)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
H, W, M = map(int, input().split())
d = np.zeros((H, W), dtype=np.int64)
for _ in range(M):
    h, w = map(int, input().split())
    #d[h-1, w-1] = 1

print(1)
exit()
tate = np.sum(d, axis=0)
yoko = np.sum(d, axis=1)
tate_max = tate.max()
yoko_max = yoko.max()

ans_tate, ans_yoko = [], []

for i in range(W):
    if tate[i] == tate_max:
        ans_tate.append(i)

for i in range(H):
    if yoko[i] == yoko_max:
        ans_yoko.append(i)

for h in ans_yoko:
    for w in ans_tate:
        if not d[h, w]:
            print(tate_max+yoko_max)
            sys.exit()
print(tate_max+yoko_max-1)

Submission status: Runtime Error

Solution code:
def main():
    H, W, M = map(int, input().split())
    bombs = [list(map(int, input().split())) for i in range(M)]
    
    hw = [[0] * W for i in range(H)]
    
    for i in range(len(bombs)):
        [h, w] = bombs[i]
        hw[h - 1][w - 1] = 1
    
    wh = [list(x) for x in zip(*hw)]
    hw_tuple_list = []
    for i in range(len(hw)):
        hw_tuple_list.append((sum(hw[i]), i+1))
    
    wh_tuple_list = []
    for i in range(len(wh)):
        wh_tuple_list.append((sum(wh[i]), i+1))

    h_list = sorted(hw_tuple_list, reverse = True)
    w_list = sorted(wh_tuple_list, reverse = True)

    h_max = h_list[0][0]
    h_idx_list = []
    for i in range(len(h_list)):
        if h_max > h_list[i][0]:
            break
        h_idx_list.append(h_list[i][1])

    w_max = w_list[0][0]
    w_idx_list = []
    for i in range(len(w_list)):
        if w_max > w_list[i][0]:
            break
        w_idx_list.append(w_list[i][1])
    
    cnt = 1
    return w_max + h_max - cnt

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

Submission status: Runtime Error

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

H, W, M= map(int,input().split(' '))
X = []
Y = []
for i in range(M):
  x, y = map(int,input().split(' '))
  X.append(x)
  Y.append(y)

xc = Counter(X)
xmode = xc.most_common(1)

ans = []
for i in xmode:
  a = i[0]
  a2 = i[1]
  index_list = [k for k, x2 in enumerate(X) if x2 == a]
  list.sort(index_list, reverse=True)
  Ytmp = Y
  for j in index_list:
    Ytmp.pop(j)
  
  yc = Counter(Ytmp)
  ymode = yc.most_common(1)
  ans.append(a2 + ymode[0][1])

print(max(ans))

Submission status: Runtime Error

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

from collections import defaultdict
counter_h = defaultdict(int)
counter_w = defaultdict(int)

for i in range(M):
    h[i],w[i] = map(int, input().split())
    counter_h[h[i]] += 1
    counter_w[w[i]] += 1
    
MAX_h = max(counter_h.values())
h_list = [k for k, v in counter_h.items() if v == MAX_h]
MAX_w = max(counter_w.values())
w_list = [k for k, v in counter_w.items() if v == MAX_w]

import itertools

if len(h_list)*len(w_list)<=3*10**5:
    X = list(itertools.product(h_list, w_list))

    ans = MAX_h+MAX_w
    check = 0


        for i in range(M):
            if (h[i],w[i]) in X:
                check += 1

    if len(X)==check:
        ans -= 1
    
print(ans)

Submission status: Runtime Error

Solution code:
H, W, m = map(int, input().split())
hs = [0] * H
ws = [0] * W
fs = [[0]*W for i in range(H)]
for i in range(m):
    hi,wi  = map(int, input().split())
    hs[hi-1] += 1
    ws[wi-1] += 1
    fs[hi-1][wi-1] += 1
N = 10**6
Hs = [h*N+i for i,h in enumerate(hs)]
Ws = [w*N+i for i,w in enumerate(ws)]
Hs.sort(reverse=True)
Ws.sort(reverse=True)
cnt = 0
# for r in fs:
#     print(*r)
mx = 0
for h_ in Hs:
    nh, ih = divmod(h_,N)
    for w_ in Ws:
        nw, iw = divmod(w_,N)
        mx = max(mx, nh+nw-fs[ih][iw])
        cnt += 1
        if cnt >= m:
            print(mx)
            exit()
print(mx)

Submission status: Runtime Error

Solution code:
h, w, m = (int(x) for x in input().split())
bomb = [[0]*w for i in range(h)]
bomb_h = [0]*h
bomb_w = [0]*w
for i in range(m):
    hm, wm = (int(x) for x in input().split())
    hm-=1
    wm-=1
    bomb[hm][wm] = 1
    bomb_h[hm]+=1
    bomb_w[wm]+=1
h_kouho = []
w_kouho = []
h_max = max(bomb_h)
w_max = max(bomb_w)
for i in range(h):
    if bomb_h[i]==h_max:
        h_kouho.append(i)
for i in range(w):
    if bomb_w[i]==w_max:
        w_kouho.append(i)
boo = False
for i in h_kouho:
    for j in w_kouho:
        if bomb[i][j]==0:
            boo=True
            break
    else:
        continue
    break
if boo:
    print(h_max+w_max)
else:
    print(h_max+w_max-1)

Submission status: Runtime Error

Solution code:
import collections

H,W,M = map(int,input().split())
B = []
h = []
w = []
for i in range(M):
  hi,wi = map(int,input().split())
  B.append([hi,wi])
  h.append(hi)
  w.append(wi)

Hc=collections.Counter(h)
Wc=collections.Counter(w)
HM = Hc.most_common()[0]
WM = Wc.most_common()[0]
if WM[1] < HM[1]:
  ichi = [i for i, x in enumerate(h) if x == HM[0]]
  ichi.sort(reverse=True)
  for k in range(len(ichi)):
    del w[ichi[k]]
  wc = collections.Counter(w)
  wm = wc.most_common()[0]
  if B.count([HM[0],wm[0]]) == 1:
    print(HM[1]+wm[1]-1)
  else:
    print(HM[1]+wm[1])

elif WM[1] == HM[1]:
  ichi = [i for i, x in enumerate(h) if x == HM[0]]
  ichi.sort(reverse=True)
  for k in range(len(ichi)):
    del w[ichi[k]]
  wc = collections.Counter(w)
  wm = wc.most_common()[0]
  print(HM[1]+wm[1])

else:
  ichi = [i for i, x in enumerate(w) if x == WM[0]]
  ichi.sort(reverse=True)
  for k in range(len(ichi)):
    del h[ichi[k]]
  hc = collections.Counter(h)
  hm = hc.most_common()[0]
  if B.count([hm[0],WM[0]]) == 1:
    print(hm[1]+WM[1]-1)
  else:
    print(hm[1]+WM[1])

Submission status: Runtime Error

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

list_w = [0]*(W+1)
list_h = [0]*(H+1)

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

if list_w[list_h.index(max(list_h))]>=0:
    print(max(list_h)+max(list_w)-1)
else:
    print(max(list_h)+max(list_w)-1)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
H,W,M = map(int,input().split())
hh = [0]*H
ww = [0]*W
HW = [[0]*W for _ in range(H)]
for _ in range(M):
    h,w = map(int,input().split())
    h,w = h-1,w-1
    hh[h] += 1
    ww[w] += 1
    HW[h][w] = 1
hmax = max(hh)
wmax = max(ww)
hind = []
wind = []
for i in range(1,H+1):
    if hh[i] == hmax:
        hind.append(i)
for j in range(1,W+1):
    if ww[j] == wmax:
        wind.append(j)
flag = 0
for i in hind:
    if flag == 1:
        break
    for j in wind:
        if HW[i-1][j-1] == 0:
            flag = 1
            print(hmax+wmax)
            break
if flag == 0:
    print(hmax+wmax-1)

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
h = [0] * (H+1)
w = [0] * (W+1)
l = [[0]*(max(H+2, W+2)) for i in range(max(H+2, W+2))]
for i in range(M):
  x, y = map(int, input().split())
  h[x] += 1
  w[y] += 1
  l[x][y] = 1

a = [i for i, x in enumerate(h) if x == max(h)]
b = [i for i, x in enumerate(w) if x == max(w)]

flag = False
for s in a:
  for t in b:
    if l[s][t] == 0:
      flag = True
      break
  if flag:
    break
if flag:
  ans = max(h)+max(w)
else:
  ans = max(h)+max(w)-1
print(ans)

Submission status: Runtime Error

Solution code:
import copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = []
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object.append([h-1, w-1])
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max - 1
p = len(cand_h)*len(cand_w)
if M > p:
   for i in range(len(cand_h)):
      for j in range(len(cand_w)):
         if [i,j] in object:
         else:
            ans += 1
else:
   ans += 1
print(ans)

Submission status: Runtime Error

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 = 0
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: Runtime Error

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

column = [0] * H
row = [0] * W

for item in P:
  column[item[0] -1] += 1
  row[item[1] -1] += 1
  
co_max = sorted(column, reverse=True)[0]
ro_max = sorted(row, reverse=True)[0]

if M >= 2:
  if co_max == 1 and ro_max == 1 and sorted(column, reverse=True)[1] == 1 and sorted(row, reverse=True)[1] == 1:
    print(2)
  else:
    column_max = [i for i, x in enumerate(column) if x == co_max]
    row_max = [i for i, x in enumerate(row) if x == ro_max]

    flag = 0
    for i in column_max:
      for j in row_max:
        if [i+1, j+1] not in P:
          flag = 1
          break
    if flag == 1:
      print(max(column) + max(row))
    elif flag == 0:
      print(max(column) + max(row) -1)
else:
  column_max = [i for i, x in enumerate(column) if x == co_max]
    row_max = [i for i, x in enumerate(row) if x == ro_max]

    flag = 0
    for i in column_max:
      for j in row_max:
        if [i+1, j+1] not in P:
          flag = 1
          break
    if flag == 1:
      print(max(column) + max(row))
    elif flag == 0:
      print(max(column) + max(row) -1)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
bom = [[0]*W for _ in range(H)]
row = [0] * H
col = [0] * W

for _ in range(M):
    h, w = map(int, input().split())
    bom[h-1][w-1] += 1
    row[h-1] += 1
    col[w-1] += 1

max_row = max(row)
max_col = max(col)
ans = max_row + max_col - 1

max_ix_row = [i for i, v in enumerate(row) if v == max_row]
max_ix_col = [i for i, v in enumerate(col) if v == max_col]

flag = False

for i in max_ix_row:
    for j in max_ix_col:
        if not bom[i][j]:
            ans += 1
            flag = True
            break
    
    if flag:
        break

print(ans)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
boms = [[] for i in range(m)]
Hs = [0] * m
Ws = [0] * m
for i in range(m):
  _h, _w = map(int, input().split())
  boms[i] = [_h-1, _w-1]
  Hs[_h - 1] += 1
  Ws[_w - 1] += 1
Hmax = max(Hs)
Hcount = Hs.count(Hmax)
Wmax = max(Ws)
Wcount = Ws.count(Wmax)
Hindexs = [0] * Hcount
Windexs = [0] * Wcount
hcount = 0
wcount = 0

Submission status: Runtime Error

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

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

h_mx=max(h_list)
w_mx=max(w_list)
ans=h_mx+w_mx-1
h_idx=[]
w_idx=[]
for i in h_list:
    if i==h_mx:
        h_idx.append(i)
for i in w_list:
    if i==w_mx:
        w_idx.append(i)

lst=list(itertools.product(h_idx,w_idx))
for i in lst:
    if place[i[0]][i[1]]==0:
        ans+=1
        break
print(ans)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
boms = [[] for i in range(m)]
Hs = [0] * m
Ws = [0] * m
for i in range(m):
  _h, _w = map(int, input().split())
  boms[i] = [_h-1, _w-1]
  Hs[_h - 1] += 1
  Ws[_w - 1] += 1
Hmax = max(Hs)
Hcount = Hs.count(Hmax)
Wmax = max(Ws)
Wcount = Ws.count(Wmax)
Hindexs = [0] * Hcount
Windexs = [0] * Wcount
hcount = 0
wcount = 0
for i in range(m):
  if Hs[i] == Hmax:
    Hindexs[hcount] = i
    hcount += 1
  if Ws[i] == Wmax:
    Windexs[wcount] = i
    wcount += 1
count = 0
for bom in boms:
  if (bom[0] in Hindexs) and (bom[1] in Windexs):
    count += 1
if count == len(Hindexs) * len(Windexs):
  print(Hmax + Wmax - 1)
else:
  print(Hmax + Wmax)

Submission status: Runtime Error

Solution code:
import statistics
import collections
H,W,M = map(int, input().split())
hw = [map(int, input().split()) for _ in range(M)]
h, w = [list(i) for i in zip(*hw)]

cnt = 0
h_s = statistics.mode(h)

for i in range(M):
  if h[i] == h_s:
    w[i] = 0
    cnt += 1

w_p = collections.Counter(w).most_common()
if w_p[0][0] == 0:
  w_s_1 = w_p[1][0]
else:
  w_s_1 = w_p[0][0]

for i in range(len(w)):
  if w[i] == w_s_1:
    cnt += 1
    
print(cnt)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
from collections import defaultdict

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

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

print(w_max+h_max-1)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
S = np.zeros((H, W))
for m in range(M):
    h, w = map(int, input().split())
    S[h-1, w-1] = 1

Sh = np.sum(S, axis=1)
Sw = np.sum(S, axis=0)
hi = np.argmax(Sh)
wi = np.argmax(Sw)

maximum = Sh[hi] + Sw[wi]
if S[hi, wi] == 1:
    maximum -= 1
print(int(maximum))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
H, W, M = map(int, input().split())

d = np.zeros((H, W), dtype=np.int64)

for _ in range(M):
    h, w = map(int, input().split())
    d[h-1, w-1] = 1
print(1)
exit()
tate = np.sum(d, axis=0)
yoko = np.sum(d, axis=1)
tate_max = tate.max()
yoko_max = yoko.max()

ans_tate, ans_yoko = [], []

for i in range(W):
    if tate[i] == tate_max:
        ans_tate.append(i)

for i in range(H):
    if yoko[i] == yoko_max:
        ans_yoko.append(i)

for h in ans_yoko:
    for w in ans_tate:
        if not d[h, w]:
            print(tate_max+yoko_max)
            sys.exit()
print(tate_max+yoko_max-1)

Submission status: Runtime Error

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

list1 = []
listh = [0 for i in range(H+1)]
for i in range(M):
    list1.append(list(map(int, input().split())))
    listh[list1[k][0]]+=1


max1 = max(listh)
loc1 = [0]

for i in range(1, len(listh)):
    if max1 == listh[i]:
        loc1.append(i)

#print("Loc1 is ", loc1)
max2_total = 0
for jjj in range(1, len(loc1)):
    listw = [0 for i in range(W+1)]
    #print("jjj is ",jjj)
    for k in range(M):
        if list1[k][0] == loc1[jjj]:
            continue
        listw[list1[k][1]]+=1
    #print("listw is",listw)
    max2 = max(listw)
    #print("max2 is ",max2)
    if max2_total<max2:
        max2_total = max2
    if max2 == H:
        break

print(max1 + max2_total)

##############################

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
from collections import defaultdict

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

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

print(w_max+h_max-1)

Submission status: Runtime Error

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((H, W), 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[hi,wi]+=1
  yn=1
  hm=np.max(h)
  wm=np.max(w)
  #print(hw)
  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])
          if hw[j,k]==0:
            yn=0
  print(hm+wm-yn)
main()