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:
import sys
H, W, M = map(int, sys.stdin.readline().split())
hlst = [0]*(H+1)
wlst = [0]*(M+1)
hwlst = []

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

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

Submission status: Runtime Error

Solution code:
H,W,M=map(int,input().split())
countH=[0]*(H+1)
countW=[0]*(W+1)
S=[[0]*(W+1)for _ in range(H+1)]
hw=[[0,0]for _ in range(M)]
i=0
for _ in range(M):
    h,w=map(int,input().split())
    countH[h]+=1
    countW[w]+=1
    hw[i]=[h,w]
    S[h][w]=1

hw.sort()
mh=max(countH)
mw=max(countW)
ans=mh+mw-1

c_mh=[]
i=0
while i<=H:
    if countH[i]==mh:
        c_mh.append(i)
    i+=1

c_mw=[]
i=0
while i<=W:
    if countW[i]==mw:
        c_mw.append(i)
    i+=1

ok=0
for h in c_mh:
    for w in c_mw:
        if S[h][w]==0:
            ans+=1
            ok=1
        if ok:
            break
    if ok:
        break

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = [int(n) for n in input().split()]
grid = np.zeros((H, W))

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,M=map(int,input().split())
bord=np.zeros((H,W))
for i in range(M):
    h,w=map(int,input().split())
    bord[h-1][w-1]=1
各行=np.sum(bord, axis=1)
各列=np.sum(bord, axis=0)
爆破数=[]
for i in range(H):
    for j in range(W):
        if bord[i][j]==0:
            爆破数.append(各行[i]+各列[j])
        else:
            爆破数.append(各行[i]+各列[j]-1)
print(int(max(爆破数)))

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

# 別変数の整数複数個
H, W, M = [int(x) for x in input().strip().split(" ")]

G = np.zeros((H, W), int)
for _ in range(M):
    h, w = [int(x) for x in input().strip().split(" ")]
    G[h-1][w-1] = 1

h_sums = np.sum(G, axis=1)
w_sums = np.sum(G, axis=0)
h_sum_max = max(h_sums)
w_sum_max = max(w_sums)

for h, w in itertools.product(
        [i for i, v in enumerate(h_sums) if v == h_sum_max],
        [i for i, v in enumerate(w_sums) if v == w_sum_max],
        ):
    if G[h][w] == 0:
        print(h_sum_max + w_sum_max)
        import sys; sys.exit(0)
print(h_sum_max + w_sum_max - 1)

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    h,w,m = map(int,input().split())
    p = np.zeros((h,w),dtype=int)
    
    for _ in range(m):
        s,t = map(int,input().split())
        p[s-1] += 1
        p[:,t-1] += 1
        p[s-1][t-1] -= 1

    print(np.max(p))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np


h, w, m = map(int, input().split())
grid = np.zeros((h, w), dtype=bool)
for _ in range(m):
    hi, wi = map(lambda x: int(x) - 1, input().split())
    grid[hi, wi] = True

h_cnt = np.count_nonzero(grid, axis=1)
w_cnt = np.count_nonzero(grid, axis=0)

w_max = w_cnt.max()

h_argsort = h_cnt.argsort()[::-1]
w_argsort = w_cnt.argsort()[::-1]

bomber = 0
for hi in h_argsort:
    if h_cnt[hi] + w_max < bomber:
        break
    
    for wi in w_argsort:
        if h_cnt[hi] + w_cnt[wi] < bomber:
            break

        if grid[hi, wi]:
            bomber = max(bomber, h_cnt[hi] + w_cnt[wi] - 1)
        else:
            bomber = max(bomber, h_cnt[hi] + w_cnt[wi])

print(bomber)

Submission status: Runtime Error

Solution code:
import numpy as np

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

sh = [0] * H
sw = [0] * W
bomb = np.zeros((H, W), dtype=int)
for i in range(M):
    sh[hw[i][0] - 1] += 1
    sw[hw[i][1] - 1] += 1
    bomb[hw[i][0] - 1, hw[i][1] - 1] = 1
    
print(6)

Submission status: Runtime Error

Solution code:
H,W,M = list(map(int,input().split()))
import numpy as np
Target = np.zeros((H,W))
for i in range(M):
    l,r = list(map(int,input().split()))
    Target[l-1,r-1] = 1
hvec = np.dot(Target,np.ones(W))
hmax = max(np.dot(Target,np.ones(W)))
wvec = np.dot(Target.T,np.ones(H))
wmax = max(np.dot(Target.T,np.ones(H)))
res = 0
for h in range(H):
    if hvec[h] == hmax:
        for w in range(W):
            if wvec[w] == wmax:
                if Target[h][w] == 1:
                    res = max(res,hmax + wmax -1)
                else:
                    res = hmax + wmax
print(int(res))

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
l=[[0 for i in range(w+1)] for j in range(h+1)]
for i in range(m):
    x,y=map(int,input().split())
    l[x][y]=1
    
row=[0 for i in range(h+1)]
col=[0 for j in range(w+1)]

for i in range(1,h+1):
    row[i]=sum(l[i])
    
        
for j in range(1,w+1):
    sumi=0
    for i in range(1,h+1):
        sumi+=l[i][j]
    col[i]=sumi
maxa=0    
for i in range(1,h+1):
    for j in range(1,w+1):
        if(l[i][j]):maxa=max(maxa,row[i]+col[j]-1)
        else:maxa=max(maxa,row[i]+col[j])
        
print(maxa)

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
bomb = [[0] * W for _ in range(H)]
Height = [0] * H
Width = [0] * W
for m in range(M):
  h, w = map(lambda x:int(x)-1, input().split())
  bomb[h][w] += 1
  Height[h] += 1
  Width[w] += 1
max_H, max_W = max(Height), max(Width)
cH, cW = [], []
for i in range(H):
  if Height[i] == max_H:
    cH.append(i)
for i in range(W):
  if Width[i] == max_W:
    cW.append(i)

dont_sub = 0
for idx_h in cH:
  for idx_w in cW:
    if bomb[idx_h][idx_w] == 0:
      dont_sub = 1
      break
  if dont_sub == 1:
    break
if dont_sub == 0:
  print(max_H + max_W - 1)
else:
  print(max_H + max_W)

Submission status: Runtime Error

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
import numpy as np
#n = int(input())
h, w, m = map(int, sys.stdin.readline().split())
#n = input()
#a = list(map(int, sys.stdin.readline().split()))

ver = [0 for i in range(w)]
par = [0 for i in range(h)]
b = np.zeros((h, w), dtype=np.int64)

for i in range(m):
    H, W = map(int, sys.stdin.readline().split())
    b[H-1][W-1] = 1
    par[H-1] += 1
    ver[W-1] += 1

mp = max(par)
mplist = [i for i, x in enumerate(par) if x == mp]
mv = max(ver)
mvlist = [i for i, x in enumerate(ver) if x == mv]

flag = 1
for i in range(len(mplist)):
    for j in range(len(mvlist)):
        if b[mplist[i]][mvlist[j]] == 0:
            flag = 0
            break

print(mp + mv - flag)

Submission status: Runtime Error

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


tgt_map = []
for i in range(H):
  tgt_map.append( [0]*W )

h_tgt = [0]*H
w_tgt = [0]*W
for i in range(M):
  input_tgt = list(map(int,input().split()))
  
  h_tgt[ input_tgt[0]-1 ] += 1
  w_tgt[ input_tgt[1]-1 ] += 1
  
  tgt_map[ input_tgt[0]-1 ][ input_tgt[1]-1 ] = 1
  
#print(tgt_map)
#print(h_tgt,w_tgt)

"""
max_h_tgt_index = h_tgt.index( max(h_tgt) )
print(max_h_tgt_index)
max_w_tgt_index = w_tgt.index( max(w_tgt) )
print(max_w_tgt_index)
"""

max_h_tgt = max(h_tgt)
max_h_tgt_index = []
for i in range(H):
  if ( h_tgt[i] == max_h_tgt ):
    max_h_tgt_index.append( i )

max_w_tgt = max(w_tgt)
max_w_tgt_index = []
for i in range(W):
  if ( w_tgt[i] == max_w_tgt ):
    max_w_tgt_index.append( i )

#print(max_h_tgt_index)
#print(max_w_tgt_index)

#
ans_chk = 0
for i in range( len(max_h_tgt_index) ):
  for j in range( len(max_w_tgt_index) ):
    
    if ( tgt_map[ max_h_tgt_index[i] ][ max_w_tgt_index[j] ] == 0 ):
      print( max_h_tgt + max_w_tgt )
      ans_chk = 1
      break
  
  if( ans_chk==1 ):
    break

if( ans_chk==0 ):
  print( max_h_tgt + max_w_tgt -1 )

Submission status: Runtime Error

Solution code:
import numpy as np

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

col_sum = np.sum(bomb, axis=0)
row_sum = np.sum(bomb, axis=1)

col_max = col_sum.max()
row_max = row_sum.max()

max_col_indexs = np.where(col_sum == col_max)[0]
max_row_index = np.argmax(row_sum)

ans = col_sum.max() + row_sum.max() - 1
for col in max_col_indexs:
    if bomb[max_row_index, col] == 0:
        ans = ans = col_sum.max() + row_sum.max()
        break

print(int(ans))

Submission status: Runtime Error

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

c = [0 for _ in range(h)]
r = [0 for _ in range(w)]
bakuset = {}
for i, j in hw:
    # print(i, j)
    c[i-1] += 1
    r[j-1] += 1
    if not str(i-1) + "+" + str(j-1) in bakuset:
        bakuset[str(i-1) + "+" + str(j-1)] = 0
    # print(bakuset, i-1, j-1)
    bakuset[str(i-1) + "+" + str(j-1)] += 1

ans = max(c) + max(r)

mc = max(c)
mr = max(r)
cc = []
rr = []

for i in range(h):
    if c[i] == mc:
        cc.append(i)

for i in range(h):
    if r[i] == mr:
        rr.append(i)

flag = 10**10

for i in cc:
    for j in rr:
        if not str(i) + "+" + str(j) in bakuset:
            flag = 0
            break
        flag = min(flag, bakuset[str(i) + "+" + str(j)])
    if not flag:
        break

if flag:
    ans -= 1

print(ans)

Submission status: Runtime Error

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

list1 = []
for i in range(M):
    list1.append(list(map(int, input().split())))

listh = [0 for i in range(H+1)]
listw = [0 for i in range(W+1)]
for k in range(M):
    listh[list1[k][0]]+=1

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

max2_total = 0
for jjj in range(1, loc1):
    for k in range(M):
        if list1[k][0] == loc1[jjj]:
            continue
        listw[list1[k][1]]+=1
    max2 = 0
    loc2 = 0
    for i in range(len(listw)):
        if max2 < listw[i]:
            max2 = listw[i]
            loc2 =  i
    if max2_total<max2:
        max2_total = max2

print(max1 + max2_total)

Submission status: Runtime Error

Solution code:
import sys
import math
import numpy as np

if __name__ == '__main__':
    H, W, M = list(map(lambda x: int(x), sys.stdin.readline().split()))

    dic = {}
    # h = [0 for i in range(H)]
    # w = [0 for i in range(W)]
    h = np.zeros(H, dtype=np.int64)
    w = np.zeros(W, dtype=np.int64)
    for i in range(M):
        # P.append(list(map(lambda x: int(x), sys.stdin.readline().split())))
        x, y = list(map(lambda x: int(x), sys.stdin.readline().split()))
        x -= 1
        y -= 1
        h[x] += 1
        w[y] += 1
        dic[x*H+y] = 1
    
    lh = np.where(h == h.max())
    lw = np.where(w == w.max())

    mx = np.max(h)
    my = np.max(w)
    # print(mx, my)

    # print(lh[0])
    # print(lw[0])

    max = 0
    for i in lh[0]:
        for j in lw[0]:
            tmp = h[i] + w[j]
            if i*H+j in dic:
                tmp -= 1
            if tmp > max:
                max = tmp
    print(max)


    # for i in lh[0]:
    #     for j in lw[0]:
    #         if i*H+j not in dic:
    #             print(i, j)
    #             break
    # else:
    #     print(mx+my, 'hi')
    #     exit()
    
    # print(mx+my-1)
    # exit()

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
lis =[]
Hlis = [0]*H
Mlis = [0]*M
for _ in range(M):
    Ch, Cm = map(int, input().split())
    Hlis[Ch-1] += 1
    Mlis[Cm-1] += 1
    lis.append([Ch, Cm])

Hmax = max(Hlis)
Hidx = [i+1 for i, v in enumerate(Hlis) if v == Hmax]
Mmax = max(Mlis)
Midx = [i+1 for i, v in enumerate(Mlis) if v == Mmax]

if [Hidx, Midx] in lis:
    print(Hmax + Mmax -1)
else:
    print(Hmax+Mmax)

Submission status: Runtime Error

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

array = np.zeros([H, W])
for _ in range(M):
    i, j = map(int, input().split())
    array[i-1, j-1] = 1
    
# 行
sum_j = np.sum(array, axis = 0)
# 列
sum_i = np.sum(array, axis = 1)

i_list = np.where(sum_i == np.max(sum_i))[0]
j_list = np.where(sum_j == np.max(sum_j))[0]

flg = False
for i, j in itertools.product(i_list, j_list):
    if array[i, j] == 0:
        flg = True
        break

if flg:
    print(int(np.max(sum_i)+np.max(sum_j)))
else:
    print(int(np.max(sum_i)+np.max(sum_j)-1))

Submission status: Runtime Error

Solution code:
import sys
import math
import numpy as np

if __name__ == '__main__':
    H, W, M = list(map(lambda x: int(x), sys.stdin.readline().split()))

    dic = {}
    # h = [0 for i in range(H)]
    # w = [0 for i in range(W)]
    h = np.zeros(H, dtype=np.int64)
    w = np.zeros(W, dtype=np.int64)
    for i in range(M):
        # P.append(list(map(lambda x: int(x), sys.stdin.readline().split())))
        x, y = list(map(lambda x: int(x), sys.stdin.readline().split()))
        x -= 1
        y -= 1
        h[x] += 1
        w[y] += 1
        dic[x*H+y] = 1
    
    lh = np.where(h == h.max())
    lw = np.where(w == w.max())

    mx = np.max(h)
    my = np.max(w)
    # print(mx, my)

    # print(lh[0])
    # print(lw[0])

    max = 0
    for i in lh[0]:
        for j in lw[0]:
            tmp = h[i] + w[j]
            if i*H+j in dic:
                tmp -= 1
            if tmp > max:
                max = tmp
    print(max)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = [int(n) for n in input().split()]
grid = np.zeros((H, W))
for i in range(M):
    h, w = [int(n) for n in input().split()]
    grid[h-1, w-1] = 1

Submission status: Runtime Error

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

map_ = [[0]*W for i in range(W)]

for i in range(M):
  h, w = list(map(int, input().split()))
  map_[h - 1][w - 1] = 1
#print(map_)
cnt_h = [0] * W
cnt_w = [0] * H
for h in range(H):
  cnt_w[h] = sum(map_[h])
  for w in range(W):
    cnt_h[w] += map_[h][w] 
#print(cnt_h, cnt_w)

h_max = max(cnt_h)
w_max = max(cnt_w)
h_max_index = []
w_max_index = []

for i in range(W):
  if cnt_h[i] == h_max:
    h_max_index.append(i)
for i in range(H):
  if cnt_w[i] == w_max:
    w_max_index.append(i)
#print(h_max_index, w_max_index)

ans = h_max + w_max
flg = False
for i in range(len(h_max_index)):
  for j in range(len(w_max_index)):
    if map_[w_max_index[j]][h_max_index[i]] == 0:
      flg = not flg
      break
  else:
      continue
  break
if flg:
  print(ans)
else:
  print(ans - 1)

Submission status: Runtime Error

Solution code:
from scipy.sparse import csr_matrix as sparse
import numpy as np

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

hs, ws = zip(*[list(map(lambda s: int(s)-1, input().split())) for _ in range(M)])
data = [1 for _ in range(M)]

matrix = sparse((data, (hs, ws)))

mines_in_row = np.array(matrix.sum(axis=1)).flatten()
mines_in_column = np.array(matrix.sum(axis=0)).flatten()

max_row = np.where(mines_in_row == max(mines_in_row))[0]
max_column = np.where(mines_in_column == max(mines_in_column))[0]

if np.all(matrix[max_row, max_column] == 1):
    print(max(mines_in_row) + max(mines_in_column)-1)
else:
    print(max(mines_in_row) + max(mines_in_column))

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, M = list(map(int, input().split()))
row = np.array([0]*H)
col = np.array([0]*W)
maps = np.zeros((H, W))
for i in range(M):
    h, w =list(map(int, input().split()))
    row[h-1] += 1
    col[w-1] += 1
    maps[h-1][w-1] = 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 maps[i][j] == 0:
            d = 0
            break
    if d == 0:
        break

print(int(rowMax + colMax - d))

Submission status: Runtime Error

Solution code:
H=2
W=3
M=3
H,W,M = list(map(int,input().split()))
import numpy as np
Target = np.zeros((H,W))
for i in range(M):
    l,r = map(int,input().split())
    Target[l-1,r-1] = 1
hvec = np.dot(Target,np.ones(W))
hmax = max(np.dot(Target,np.ones(W)))
wvec = np.dot(Target.T,np.ones(H))
wmax = max(np.dot(Target.T,np.ones(H)))
res = 0
for h in range(H):
    if hvec[h] == hmax:
        for w in range(W):
            if wvec[w] == wmax:
                if Target[h][w] == 1:
                    res = max(res,hmax + wmax -1)
                else:
                    res = hmax + wmax
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,M = list(map(int, input().split()))
p_list = []
for i in range(M):
    p_list.append(list(map(int, input().split())))

p_array = np.array(p_list)
freq = np.array(np.unique(p_array[:,0], return_counts=True))
H_max = freq[1,:].max()
max_index = np.where(freq[1,:]==H_max)
H_check = freq[0,:][max_index]

freq = np.array(np.unique(p_array[:,1], return_counts=True))
W_max = freq[1,:].max()
max_index = np.where(freq[1,:]==W_max)
W_check = freq[0,:][max_index]

res = H_max + W_max -1
for i in H_check:
    for j in W_check:
        if [i,j] not in p_list:
            res = H_max + W_max
            end_flag = True
            break
    if end_flag == True:
        break
print(res)

Submission status: Runtime Error

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
###############################################################################\
r,c,m=INPUT()
A=[[0 for i in range(c)]for j in range(r)]
R=[0]*r
C=[0]*c
for i in range(m):
    x,y=INPUT()
    A[x-1][y-1]=1
for i in range(r):
    s=0
    for j in range(c):
        if A[i][j]==1:
            s+=1
    R[i]=s
for j in range(c):
    s=0
    for i in range(r):
        if A[i][j]==1:
            s+=1
    C[j]=s
ans=0
for i in range(r):
    for j in range(c):
        if A[i][j]==0:
            ans=max(ans,R[i]+C[j])
        else:
            ans=max(ans,R[i]-1+C[i])
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
def main():
  h, w, m =  map(int, input().split())
  H = [0]*h
  W = [0]*w
  grid = [[0]*w for _ in range(h)]
  for i in range(m):
    a, b = map(int, input().split())
    H[a-1] += 1
    W[b-1] += 1
    grid[a-1][b-1] += 1
  h_max = max(H)
  w_max = max(W)
  h_sec = [i for i, x in enumerate(H) if x == h_max]
  w_sec = [i for i, x in enumerate(W) if x == w_max]
  ans = h_max + w_max
  flag = True
  for gri in itertools.product(h_sec, w_sec):
    if grid[gri[0]][gri[1]] == 0:
      flag = False
      break
  if flag:
    print(ans-1)
  else:
    print(ans)
  
if __name__ == "__main__":
  main()

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 = np.array([[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 = np.sum(npBombs[x,::])
  Hs.append(s)

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

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

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

print(int(answer))

Submission status: Runtime Error

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

import numpy as np

area = np.zeros((H, W), int)

for _ in range(M):
    y, x = map(int, input().split(" "))
    area[y-1][x-1] = 1
    
W_sum_ = area.sum(axis = 1)
H_sum_ = area.sum(axis = 0)

max_sum = 0
x_max = y_max = 0

for y in range(H):
    for x in range(W):
        sum_ = H_sum_[x] + W_sum_[y]
        if area[y][x] == 1:
            sum_ -= 1
        if sum_ > max_sum:
            max_sum = sum_
            x_max = x
            y_max = y
            
print(max_sum)

Submission status: Runtime Error

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

B=np.zeros((H,W))
for i in range(M):
    inp=list(map(int,input().split()))
    B[inp[0]-1][inp[1]-1]=1
BT=B.T
maxmax=0
for i in range(H):
    for j in range(W):
        sumsum=0
        sumsum=np.sum(B[i])+np.sum(BT[j])-B[i][j]
        #print((np.sum(B[i]),np.sum(BT[j]),B[i][j]))
        if maxmax<sumsum:
            maxmax=sumsum
print(maxmax)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m=map(int,input().split())
data=np.zeros((h,w),dtype=np.int64)
for i in range(m):
    x,y=map(int,input().split())
    data[x-1][y-1]+=1
ans=0
hdata=np.sum(data,axis=1)
wdata=np.sum(data,axis=0)
for i in range(h):
    cnt=0
    for j in range(w):
        cnt=hdata[i]+wdata[j]-data[i][j]
        ans=max(ans,cnt)
print(int(ans))

Submission status: Runtime Error

Solution code:
import statistics
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)
w_s = statistics.mode(w)
for i in range(M):
  if h[i] == h_s:
    w[i] = 0
    cnt += 1

while 0 in w:
  w.remove(0)
  
w_s_1 = statistics.mode(w)

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

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, M = map(int, input().split())
ans = 0
S = np.zeros((H, W))
for _ in range(M):
  h, w = map(int, input().split())
  S[h-1, :] += 1
  S[:, w-1] += 1
  S[h-1, w-1] -= 1
print(int(np.nanmax(S)))

Submission status: Runtime Error

Solution code:
# abc176_e.py
H, W, M = map(int,input().split())
hcnt = [0]*H
wcnt = [0]*W
duplicate = [[0]*W for i in range(H)]

for i in range(M):
    h,w = map(int,input().split())
    hcnt[h-1]+=1
    wcnt[w-1]+=1
    duplicate[h-1][w-1] += 1
hmax = 0
hmaxidx = 0
hsameflg = True
for i,v in enumerate(hcnt):
    if hmax < v:
        hmax = v
        hmaxidx = i
    if i>0 and hcnt[i-1] != hcnt[i]:
        hsameflg = False

wmax = 0
wmaxidx = 0
wsameflg = True
for i,v in enumerate(wcnt):
    if wmax < v:
        wmax = v
        wmaxidx = i
    if i>0 and wcnt[i-1] != wcnt[i]:
        wsameflg = False

# print(hcnt,wcnt)
if hsameflg or wsameflg:
    print(hmax+wmax)
else:
    print(hmax+wmax - duplicate[hmaxidx][wmaxidx])

Submission status: Runtime Error

Solution code:
import numpy as np
def resolve():
    H,W,M = map(int,input().split())
    
    Hnum = np.zeros(H+1)
    Wnum = np.zeros(W+1)
    Mdata = np.zeros((H+1, W+1), dtype = int)
    
    for i in range(M):
        h,w = map(int,input().split())
        Mdata[h,w] = 1
        Hnum[h] += 1
        Wnum[w] += 1
    
    ans = int(max(Hnum) + max(Wnum))
    HmaxIdx = np.where(Hnum == Hnum.max())[0]
    WmaxIdx = np.where(Wnum == Wnum.max())[0]
    
    for i in HmaxIdx:
        for j in WmaxIdx:
            if Mdata[i,j] == 1:
                continue
            else:
                return ans
    return ans - 1
    

ans = resolve()

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

L=np.zeros((H,W))

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

a=np.sum(L,axis=0)
b=np.sum(L,axis=1)
aa,bb=np.meshgrid(a,b)

print(int((aa+bb-L).max()))

Submission status: Runtime Error

Solution code:
import sys
h,w,m=map(int, input().split())
hlist=[0]*h
wlist=[0]*w
hw=[[0]*w for i in range(h)]
for i in range(m):
  x,y=map(int, input().split())
  hlist[x-1]+=1
  wlist[y-1]+=1
  hw[x-1][y-1]+=1
maxh=max(hlist)
maxw=max(wlist)
hlist1=[]
wlist1=[]
for i in range(h):
  if hlist[i]==maxh:
    hlist1.append(i)
for i in range(w):
  if wlist[i]==maxw:
    wlist1.append(i)
for i in hlist1:
  for j in wlist1:
    if hw[i][j]<1:
      print(hw[i][j])
      sys.exit()
print(maxh+maxw-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 = np.array([[int(b) for b in input().split()] for l in range(M)])

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

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

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

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

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

print(int(answer))

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
bom = [[0]*W for _ in range(H)]
# row = [[] for _ in range(H)]
# col = [[] for _ in range(W)]
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].append(w)
    # col[w-1].append(h)
    row[h-1] += 1
    col[w-1] += 1

col_max = max(col)
col_max_ix = [i for i, v in enumerate(col) if v == col_max]
ans = 0

# print('bom: ', bom)
# print('col_max_ix: ', col_max_ix)

for i in range(H):
    r = row[i]
    # print('r: ', r)
    # print('col_max: ', col_max)
    r += col_max
    r -= 1

    for ix in col_max_ix:
        if not bom[i][ix]:
            r += 1
            break
    # print('r: ', r)
    # print()
    ans = max(ans, r)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8,i8,i8[:]), cache=True)
def main(H, W, XY):
    A = np.zeros((H, W), np.int64)
    row = np.zeros(H, np.int64)
    col = np.zeros(W, np.int64)
    for i in range(0, len(XY), 2):
        x, y = XY[i:i + 2] - 1
        row[x] += 1
        col[y] += 1
        A[x, y] += 1
    ans = 0
    for h in range(H):
        for w in range(W):
            x = row[h] + col[w] - A[h, w]
            ans = max(ans, x)
    return ans

H, W, M = map(int, readline().split())
XY = np.array(read().split(), np.int64)

print(main(H, W, XY))

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, M = map(int, input(split()))
hwlist = []
a = np.zeros(H)
b = np.zeros(W)
for m in range(M):
  append.list = (list(map(int, input().split())))
  hwlist.append(append_list)
  a[append_list[0]-1] += 1
  b[append_list[1]-1] += 1
max_a = np.argmax(a)
max_b = np.argmax(b)
if [max_a, max_b] in hwlist:
    print(a[max_a] + b[max_b] - 1)
else:
    print(a[max_a] + b[max_b])

Submission status: Runtime Error

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

import numpy as np
from numba import jit
# stdin = open('sample.txt')

@jit(cache=True)
def main():
    H, W, M = map(int, readline().rstrip().split())
    HW = np.zeros((H + 1, W + 1), np.int64)
    HB = np.zeros((H + 1), np.int64)
    HS = set()
    WB = np.zeros((W + 1), np.int64)
    WS = set()
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        HW[h, w] = 1
        HB[h] += 1
        HS.add(h)
        WB[w] += 1
        WS.add(w)
    ans = 0
    for h in HS:
        for w in WS:
            tmp = HB[h] + WB[w]
            if HW[h, w] == 1:
                tmp -= 1
            ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

h, w, m= map(int, input().split())
ans=np.zeros((h, w), dtype=int)
for i in range(0,m):
  hi, wi = map(int, input().split())
  ans[hi-1,wi-1]=1

colm=np.sum(ans, axis=0)
line=np.sum(ans, axis=1)

ataimax=0
for ih in range(0,h):
  for iw in range(0,w):
    atai=colm[iw]+line[ih]-ans[ih,iw]
    if (atai >= ataimax): ataimax=atai

print (ataimax)

Submission status: Runtime Error

Solution code:
H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(M+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
Pmax = max(P)
Qmax = max(Q)
ans = Pmax+Qmax-1
Pindex = [i for i, v in enumerate(P) if v == Pmax]
Qindex = [i for i, v in enumerate(Q) if v == Qmax]
key = 0
for x in Pindex:
  for y in Qindex:
    if A[x][y] == 0:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)

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 = np.array([[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 = []
Hmax = 0
for x in range(H):
  s = np.sum(npBombs[x,::])
  Hs.append(s)

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

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

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

print(int(answer))

Submission status: Runtime Error

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, M, BOMs):
    h_count = [[0, i] for i in range(H + 1)]
    w_count = [[0, i] for i in range(W + 1)]
    bom_map_h = [[] for i in range(H + 1)]
    BOMs.sort(key=lambda x: x[1])
    for bom in BOMs:
        h_count[bom[0]][0] += 1
        w_count[bom[1]][0] += 1
        bom_map_h[bom[0]].append(bom[1])
    h_count.sort(reverse=True)
    w_count.sort(reverse=True)
    h_max = h_count[0][0]
    w_max = w_count[0][0]
    ans = h_max + w_max - 1
    flg = False
    for hc in h_count:
        if hc[0] < h_max:
            break
        for wc in w_count:
            if wc[0] < w_max:
                break
            if bom_map_h[hc[1]][bisect.bisect_left(bom_map_h[hc[1]], wc[1])] != wc[1]:
            # if not wc[1] in bom_map_h[hc[1]]:
                ans = h_max + w_max
                flg = True
                break
        if flg:
            break
    print(ans)


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    H, W, M = map(int, input().split())
    BOMs = [[int(i) for i in input().split()] for _ in range(M)]
    # As = [int(i) for i in input().split()]
    # Bs = [int(i) for i in input().split()]
    solve(H, W, M, BOMs)

Submission status: Runtime Error

Solution code:
import numpy as np

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

MA=np.zeros((H,W))
MX=[0]*H
MY=[0]*W
for i in range(M):
  x,y=input().split()
  MA[int(x)-1,int(y)-1]=1

for x in range(H):
  MX[x]=sum(MA[x,:])

for y in range(W):
  MY[y]=sum(MA[:,y])

ix,xmax=max(enumerate(MX),key=lambda x: x[1])
iy,ymax=max(enumerate(MY),key=lambda x: x[1])

print(int(xmax+ymax-MA[ix,iy]))