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 numpy as np
h, w, m = map(int, input().split())
graph = np.zeros((h, w), dtype='int64')
row_sum = np.zeros(h, dtype='int64')
col_sum = np.zeros(w, dtype='int64')

for _ in range(m):
  i, j = map(int, input().split())
  graph[i-1][j-1] = 1
  row_sum[i-1] += 1
  col_sum[j-1] += 1

max_row = max(row_sum)
max_col = max(col_sum)

result = max_row+max_col

ris = np.where(row_sum == max_row)
cis = np.where(col_sum == max_col)

for ri in ris[0]:
  for ci in cis[0]:
    if graph[ri][ci] == 0:
      print(result)
      exit()
print(result-1)

Submission status: Runtime Error

Solution code:
#E
import numpy as np
H,W,M=map(int,input().split())
arr=np.array([[0 for _ in range(W)] for i in range(H)])
h_arr=[]
w_arr=[]
for _ in range(M):
    h,w=map(int,input().split())
    arr[h-1][w-1]=int(1)
    h_arr.append(h-1)
    w_arr.append(w-1)
h_arr=list(set(h_arr))
w_arr=list(set(w_arr))
ans=0
for i in h_arr:
    for j in w_arr:
        num=np.sum(arr[i,:])+np.sum(arr[:,j])
        if arr[i][j]==1:
            num-=1
        #print(np.sum(arr[i,:]))
        #print(np.sum(arr[:,j]))
        if num>ans:
            ans=num
    
        


#print(arr)
print(ans)

Submission status: Runtime Error

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

h = [0] * M
w = [0] * M
for i in range(M):
    h[i], w[i] = map(int, input().split())


S = Counter(h)
T = Counter(w)

if (S.most_common()[0][1] > T.most_common()[0][1]):
    smc = S.most_common()[0][0]
    for i in range(M):
        if (h[i] == smc):
            w[i] = 'boom'

    w1 = [s for s in w if s != 'boom']
    T = Counter(w1)
    tmc = T.most_common()[0][0]
    for i in range(len(w1)):
        if (w1[i] == tmc):
            w1[i] = 'boom' 

    w2 = [s for s in w1 if s != 'boom']
    print(M-len(w2))

else:
    tmc = T.most_common()[0][0]
    for i in range(M):
        if (w[i] == tmc):
            h[i] = 'boom'

    h1 = [s for s in h if s != 'boom']
    S = Counter(h1)
    smc = S.most_common()[0][0]
    for i in range(len(h1)):
        if (h1[i] == S.most_common()[0][0]):
            h1[i] = 'boom' 

    h2 = [s for s in h1 if s != 'boom']
    print(M-len(h2))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
from bisect import bisect_left
def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    h,w,m = get_nums_l()
    targets = []
    H = []
    W = []
    HW = []
    for i in range(m):
        hi, wi = get_nums_l()
        HW.append((hi-1, wi-1))
        H.append(hi-1)
        W.append(wi-1)

    HW.sort()
    
    rows = [0] * h
    cols = [0] * w

    for i in range(m):
        rows[H[i]] += 1
        cols[W[i]] += 1

    rmax = 0
    rmaxi = []
    for i,x in enumerate(rows):
        if x > rmax:
            rmax = x
            rmaxi = [i]
        elif x == rmax:
            rmaxi.append(i)
    cmax = 0
    cmaxi = []
    for i,x in enumerate(cols):
        if x > cmax:
            cmax = x
            cmaxi = [i]
        elif x == cmax:
            cmaxi.append(i)

    # log(rmax,cmax)
    # log(rmaxi, cmaxi)

    for rmi in rmaxi:
        for cmi in cmaxi:
            ok = True
            i = bisect_left(HW, (rmi, cmi))
            if HW[i] == (rmi, cmi):
                ok = False
            # for i in range(m):
            #     if H[i] == rmi and W[i] == cmi:
            #         ok = False
            #         break
            if ok:
                print(rmax + cmax)
                return

    print(rmax + cmax - 1)

main()

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
Hs = [0] * m
Ws = [0] * m
for i in range(m):
  _h, _w = map(int, input().split())
  Hs[_h - 1] += 1
  Ws[_w - 1] += 1

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    H,W,M = map(int,input().split())
    h = [[0,i] for i in range(H)]
    w = [[0,i] for i in range(W)]
    HW = np.zeros((H,W))
    for i in range(M):
        tmp_0,tmp_1 = map(int,input().split())
        tmp_0 -= 1
        tmp_1 -= 1
        h[tmp_0][0] += 1
        w[tmp_1][0] += 1
        HW[tmp_0][tmp_1] += 10
    
    list.sort(h, reverse=True)
    list.sort(w, reverse=True)
    max_h = h[0][0]
    max_w = w[0][0]
    ans = max_h + max_w
    for i in range(len(h)):
        if h[i][0] < max_h:
            break
        HW[h[i][1]] += 1
        
    for i in range(len(w)):
        if w[i][0] < max_w:
            break
        HW[:,w[i][1]] += 1
    
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = [i for i, v in enumerate(lh) if v == nh]
    lw = [i for i, v in enumerate(lw) if v == nw]

    for h in lh:
        for w in lw:
            if (h, w) not in B:
                print(nh + nw)
                return

    print(nh + nw - 1)


main()

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)
c_sum.sort()
r_sum.sort()
print(int(c_sum[-1]+r_sum[-1]))

Submission status: Runtime Error

Solution code:
def resolve():
    h,w,m = map(int, input().split())
    mine = []
    mineh = [0]*h
    minew = [0]*w
    for i in range(m):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        mine.append((a,b))
        mineh[a] += 1
        minew[b] += 1
    mine = set(mine)
    maxh = max(mineh)
    hnum = []
    maxw = max(minew)
    wnum = []
    for i in range(h):
        if mineh[i] == maxh:
            hnum.append(i)
        if minew[i] == maxw:
            wnum.append(i)
    for i in hnum:
        for j in wnum:
            if [i,j] in mine:
                continue
            else:
                print(maxw+maxh)
                exit()
    print(maxw+maxh-1)
resolve()

Submission status: Runtime Error

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

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]

new_dist = np.tile(w_sum, W).reshape(W, H).T + h_sum.repeat(H).reshape(H, W) - dist

#print(dist)
#print(new_dist)

print(int(new_dist.max()))

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
boms = [[0,0] for i in range(m)]
Hs = [0] * m
Ws = [0] * m
for i in range(m):
  _h, _w = map(int, input().split())
  boms[i][0] = _h - 1
  boms[i][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:
h,w,m = map(int,input().split())
s = [0]
t = [0]
for i in range(h):
    s.append([])
for i in range(w):
    t.append([])
for i in range(m):
    a,b = map(int,input().split())
    s[a-1].append(b)
    t[b-1] += 1
if(h == 1 or w == 1):
    print(m)
else:
    p = max(t)
    q = max(len(s[i]) for i in range(h))
    if(t.index(p) in s[q]):
        print(max(s)+max(t) - 1)
    else:
        print(max(s)+max(t))

Submission status: Runtime Error

Solution code:
H,W,M = map(int,input().split())
for i in range (M):
 h,w = map(str,input().split())
 H,W = map(int,input().split())
x = 0
for i in range (H):
 x = list(h.count("i"))
 maxx = 0
 if maxx < x[i]:
  maxx = x[i]
for i in range (H):
 if maxx = int(h.count("i")):
  maxh = list(i)
  maxhcount = len(maxh)
y = 0
for i in range (W):
 y = list(h.count("i"))
 maxy = 0
 if maxy < y[i]:
  maxy = y[i]
for i in range (W):
 if maxy = int(h.count("i")):
  maxw = list(i)
  maxwcount = len(maxw)
for i in range (maxhcount):
 for j in range (maxwcount):
  if H[maxh[i]],W[maxw[j]] = False が一つ以上ある:
   ans = maxx + maxy
  else:
   ans = maxx + maxy -1
print (ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

h_max = np.argmax(np.sum(boms, axis=0))
maxh = np.max(np.sum(boms, axis=0))
w_max = np.argmax(np.sum(boms, axis=1))
maxw = np.max(np.sum(boms, axis=1))

if boms[h_max, w_max] == 0:
    print(maxh+maxw)
else:
    print(maxh+maxw-1)

Submission status: Runtime Error

Solution code:
#E
import numpy as np
H,W,M=map(int,input().split())
arr=np.array([[0 for _ in range(W)] for i in range(H)])
h_arr=[]
w_arr=[]
for _ in range(M):
    h,w=map(int,input().split())
    arr[h-1][w-1]=int(1)
    h_arr.append(h-1)
    w_arr.append(w-1)
h_arr=list(set(h_arr))
w_arr=list(set(w_arr))
ans=0
for i in h_arr:
    for j in w_arr:
        num=np.sum(arr[i,:])+np.sum(arr[:,j])
        if arr[i][j]==1:
            num-=1
        #print(np.sum(arr[i,:]))
        #print(np.sum(arr[:,j]))
        if num>ans:
            ans=num
    
        
 
 
#print(arr)
print(ans)

Submission status: Runtime Error

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

horg = []
worg = []
obj = []
ans = 0

for _ in range(M):
    h_, w_ = map(int, input().split())
    horg.append(h_)
    worg.append(w_)
    obj.append([h_, w_])

h = collections.Counter(horg).most_common()
w = collections.Counter(worg).most_common()

i = 0
while h[i % H][1] == h[0][1] and i < H:
    i += 1
del h[i:]

k = 0
    k += 1

del w[k:]

count = 0

for hitem in h:
    for witem in w:
        if [hitem[0], witem[0]] in obj:
            count += 1

if count == len(h) * len(w):
    ans = -1

ans += h[0][1] + w[0][1]

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys 
import itertools
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M= map(int,readline().split())
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
data = [[False]*(W+1) for i in range(H+1)]

for i in range(M):
    h,w = map(int,readline().split())
    data[h][w] = True
    h_cnt[h] += 1 
    w_cnt[w] += 1
    
max_h = max(h_cnt)
max_w = max(w_cnt)

max_h_ind = []
max_w_ind = []
max_h_cnt = 0
max_w_cnt = 0

for i in range(H+1):
    if max_h == h_cnt[i]:
        max_h_cnt += 1
        max_h_ind.append(i)

for i in range(W+1):
    if max_w == w_cnt[i]:
        max_w_cnt += 1
        max_w_ind.append(i)
max_h_ind = set(max_h_ind)
max_w_ind = set(max_w_ind)

a = np.array(max_h_ind)
b = np.array(max_w_ind)
c = np.outer(a,b)


if max_w_cnt * max_h_cnt > M:
    print(max_h+max_w)
else:
    for h,w in c:
        if data[h][w] == False:
            print(max_h+max_w)
            sys.exit()
    print(max_h+max_w-1)

Submission status: Runtime Error

Solution code:
#abc176-e
import sys,math,collections,itertools
import numpy as np
from numba import jit

@jit
def main()
    input = sys.stdin.readline
    H,W,M=list(map(int,input().split()))

    point_bom = np.array([[0]*(W+1) for _ in range(H+1)])
    for _ in range(M):
        h,w = map(int,input().split())
        point_bom[h][w]=1
    point_bom = np.array(point_bom)
    row_bom = point_bom.sum(axis=0)
    col_bom = point_bom.sum(axis=1)
    max_row = row_bom.max()
    max_col = col_bom.max()

    ind_max_row =[]
    ind_max_col = []

    for i in range(len(row_bom)):
        if row_bom[i] == max_row:
             ind_max_row.append(i)
    for i in range(len(col_bom)):
        if col_bom[i] == max_col:
            ind_max_col.append(i)

    flag = 1#爆破対象が置かれる　おかれている＝１　いない＝０
    for mr in ind_max_row:
        for mc in ind_max_col:
            if point_bom[mc][mr] == 0:
                flag = 0
                break
        if flag == 0:
            break
    print(max_row+max_col - flag)

main()

Submission status: Runtime Error

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

bom=[[0 for i in range(w+1)] for i in range(h+1)]

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


from itertools import accumulate
for i in range(h+2):
  bom[i]=list(accumulate(bom[i]))


for i in range(1,h+2):
  for j in range(w+1):
    bom[i][j]=bom[i][j]+bom[i-1][j]

ans=0  
for i in range(1,h+2):
  for j in range(1,w+1):
    
    ans=max(ans,bom[h+1][w]-(bom[i-1][j-1]+bom[i-1][w]-bom[i-1][j]+bom[h][j-1]-bom[i][j-1]+bom[h+1][w]-bom[i][w]-bom[h+1][j]+bom[i][j]))
   
    
print(ans)

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)]
    
    if M == 1:
        return 1
    
    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
    for i in range(len(h_idx_list)):
        for j in range(len(w_idx_list)):
            if hw[h_idx_list[i] - 1][w_idx_list[j] - 1] != 1:
                cnt = 0
                break
    return w_max + h_max - cnt

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

Submission status: Runtime Error

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

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

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

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

max_h_count = 0
max_w_count = 0

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

max_h_count = max(h_count_list)
x = h_count_list.index(max_h_count)
    
for n in range(m):
    b = bomb_list[n][1]
    w_count_list[b] += 1

max_w_count = max(w_count_list)
y = w_count_list.index(max_w_count)

if bomb_list[x][y] in bomb_list.items(): 
    print(max_w_count + max_h_count + 1)
else:
    print(max_w_count + max_h_count)

Submission status: Runtime Error

Solution code:
import numpy as np
def main():
  H,W,m=map(int,input().split())
  if H==1:
    if W==1:
      print(1)
      exit()
  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:
h,w,m=map(int,input().split())

H=[0]*h
W=[0]*w
li_h=[]
li_w=[]

for i in range(m):
    h1,w1=list(map(int,input().split()))
    li_h.append(h1)
    li_w.append(w1)
    H[h1-1]+=1
    W[w1-1]+=1


h_flag=0
w_flag=0

if H.count(max(H))==1:
    ans_h=max(H)
    h_flag+=1

if W.count(max(W))==1:
    ans_w=max(W)
    w_flag+=1

if h_flag==1 and w_flag==1:
    print(max(H)+max(W))



else:
    if h_flag==1:
        for i in range(m):
            if li_w[i]==max(H):
                if li_h[i]==0:
                    print(max(H)+max(W))
                    h_flag+=1:
        else:
             h_flag==1:
             print(max(H)+max(W)-1)                   
                
            


    elif w_flag==1:
        for i in range(m):
            if li_h[i]==max(W):
                if li_w[i]==0:
                    print(max(H)+max(W))
                    w_flag+=1:
        else:
             w_flag==1:
             print(max(H)+max(W)-1)

Submission status: Runtime Error

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

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

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, M=map(int, input().split())
x=np.array([0]*(H+1))
y=np.array([0]*(W+1))
hw=np.array([list(map(int, input().split())) for _ in range(M)])
for i in range(M):
  x[hw[i, 0]]+=1
  y[hw[i, 1]]+=1
  
maxx=max(x)
a=set()
for i in range(1, H+1):
  if x[i]==maxx:
    a.add(i)
maxy=max(y)
b=set()
for i in range(1, W+1):
  if y[i]==maxy:
    b.add(i)

for i in range(M):
  if hw[i][0] not in a and hw[i][1] not in b:
    print(max(x)+max(y))
    exit()
    
print(max(x)+max(y)-1)

Submission status: Runtime Error

Solution code:
import sys
 
H,W,M = list(map(int, input().split()))
 
hw = [[0] * (W+30) for _ in range(H+30)]
 
w = [0] * (W+1)
h = [0] * (H+1)
mxw = []
mxw_v = 0
mxh = []
mxh_v = 0
 
 
for i in range(M):
    h_i, w_j = list(map(int, input().split()))
    hw[h_i][w_j] = 1
    h[h_i] += 1
    w[w_j] += 1
    if mxw_v < w[w_j]:
        mxw_v = w[w_j]
        mxw = [w_j]
    elif mxw_v == w[w_j]:
        mxw.append(w_j)
 
    if mxh_v < h[h_i]:
        mxh_v = h[h_i]
        mxh = [h_i]
    elif mxh_v == h[h_i]:
        mxh.append(h_i)

a = 0
for i in mxh:
    for j in mxw:
        d = hw[i][j]
        a = max(a, h[i]+w[j]-d)
print(a)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

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

grid = np.zeros((H, W), dtype=int)
for _ in range(M):
  h, w = map(int, input().split())
  grid[h-1][w-1] = 1
h_grid = np.sum(grid, axis=0)
w_grid = np.sum(grid, axis=1)

h_max = h_grid.max()
w_max = w_grid.max()
count = h_max+w_max
"""
for h in h_sort:
  if h_grid[h] != h_grid[h_sort[0]]:
    break
  for w in w_sort:
    if w_grid[w] != w_grid[w_sort[0]]:
      break
    print(w, h)
    print(grid[w][h])
    if grid[w][h] == 0:
      break

else:
  count -= 1
"""

for h, w in itertools.product(range(W), range(H)):
  if h_grid[h] == h_max and w_grid[w] == w_max:
    if grid[w][h] == 0:
      break
else:
  count -= 1

print(count)

Submission status: Runtime Error

Solution code:

h,w,m=map(int,input().split())
tate=[0]*(h+1)
yoko=[0]*(w+1)
#box=[[0]*(w+1) for i in range(h+1)]

for i in range(m):
    a, b = map(int, input().split())
    tate[a] += 1
    yoko[b] += 1
    box[a][b] += 1
tmax = max(tate)
ymax = max(yoko)
tbox = [i for i, v in enumerate(tate) if v == tmax]
ybox = [i for i, v in enumerate(yoko) if v == ymax]

flag = True
#for i in tbox:
 #   for j in ybox:
  #      if box[i][j] == 0:
#            flag = False
#print(tmax,ymax,tbox,ybox,flag,box)
if flag:
    print(tmax + ymax - 1)
else:
    print(tmax + ymax)

Submission status: Runtime Error

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

y = max(h)
u = max(w)
if c.count(y) == 0
  c += 0
else:
  c -= 1
if c.count(u) == 0
  c += 0
else:
  c -= 1
print(y+u-c)

Submission status: Runtime Error

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


h_cnt=[]
w_cnt=[]
h_set=list(set(h))
w_set=list(set(w))
"""
for i in h_set:
  h_cnt.append(h.count(i))
for i in w_set:
  w_cnt.append(w.count(i))
"""

  
h1=[0]*(3*(10**5))
w1=[0]*(3*(10**5))
for i in h:
  h1[i]+=1
for i in w:
  w1[i]+=1

  
max_h_cnt=max(h1)
max_w_cnt=max(w1)

h_indices=[i for i, x in enumerate(h1) if x ==max_h_cnt]
w_indices=[i for i, x in enumerate(w1) if x ==max_w_cnt]
"""
h_max=[h_set[i] for i in h_indices]
w_max=[w_set[i] for i in w_indices]
"""
flag=True
for i in h_indices:
  for j in w_indices:
    if (i,j) not in list(zip(h,w)):
      print(max_h_cnt+max_w_cnt)
      flag=False
      break

if flag:
  print(max_h_cnt+max_w_cnt-1)

Submission status: Runtime Error

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

bomb = []
for i in range(m):
    bomb.append(list(map(int, input().split())))
    
sum_hor, sum_ver = {}, {}
for i in range(m):
    h_i = bomb[i][0]-1
    w_i = bomb[i][1]-1
    if h_i not in sum_hor:
        sum_hor[h_i] = 1
    else:
        sum_hor[h_i] += 1
    if w_i not in sum_ver:
        sum_ver[w_i] = 1
    else:
        sum_ver[w_i] += 1

cost = []
for i in sum_hor.keys():
    for j in sum_ver.keys():
        if bomb[i][j] == 1:
            cost.append(sum_hor[i] + sum_ver[j] - 1)
        else:
            cost.append(sum_hor[i] + sum_ver[j])
print(max(cost))

Submission status: Runtime Error

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

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

#print(init)
for i in range(M):
  x, y = [int(x)-1 for x in input().split()]
  init[x,y] = 1

#print(init)

row = np.sum(init, axis=1)
col = np.sum(init, axis=0)

max_H = np.where(row == row.max())[0]
max_W = np.where(col == col.max())[0]

before_point = 0
max_point = row[max_H[0]] + col[max_W[0]]

if len(max_H) != 1 or len(max_W) != 1:
  for h in max_H:
    for w in max_W:
      point = row[h] + col[w]
      if init[h,w] == 0:
        pass
      else:
        point -= 1
      if point > before_point:
        max_point = point
      before_point = point

print(int(max_point))

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]
high = [0] * h
weig = [0] * w
for i in range(m):
    high[hw[i][0] - 1] += 1
    weig[hw[i][1] - 1] += 1
m_high = high.index(max(high))
m_weig = weig.index(max(weig))
ans = max(high) + max(weig)
for i, x in enumerate(high) if x == max(high):
    for j, y in enumerate(l_dup) if x == max(weig):
        ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    H,W,M = map(int,input().split())
    h = [[0,i] for i in range(H)]
    w = [[0,i] for i in range(W)]
    HW = np.zeros((H,W))
    for i in range(M):
        tmp_0,tmp_1 = map(int,input().split())
        tmp_0 -= 1
        tmp_1 -= 1
        h[tmp_0][0] += 1
        w[tmp_1][0] += 1
        HW[tmp_0][tmp_1] += 10
    
    max_h = h[0][0]
    max_w = w[0][0]
    ans = max_h + max_w
    for i in range(len(h)):
        if h[i][0] < max_h:
            break
        HW[h[i][1]] += 1
        
    for i in range(len(w)):
        if w[i][0] < max_w:
            break
        HW[:,w[i][1]] += 1
    
    if 2 not in HW:
        ans -= 1
    
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
y,x,z = map(int, input().split())

ylist = [0] * y
xlist = [0] * x
yxlist= [[0] * x for i in range(y)]
hyou=[]
num_list = []
for i in range(z):
    y,x = map(int, input().split())
    ylist[y-1]+=1
    xlist[x-1]+=1
    yxlist[y-1][x-1]=1
ymax_i=[i for i, v in enumerate(ylist) if v == max(ylist)]

flag=0

for i in ymax_i:
    if sum(yxlist[i])==x:
        flag=1
        break
if flag==0:
    print(max(ylist)+max(xlist))
else:
    print(max(ylist)+max(xlist)-1)

Submission status: Runtime Error

Solution code:
H,W,M=map(int, input().split())
hh=[0 for i in range(H)]
ww=[0 for j in range(W)]
cord=[[False for i in range(W)]for j in range(H)]
for i in range(M):
    h,w=map(int,input().split())
    cord[h-1][w-1]=True
    hh[h-1]+=1
    ww[w-1]+=1
mxh=max(hh)
mxw=max(ww)
mh=[i for i,x in enumerate(hh)if x==mxh]
mw=[i for i,x in enumerate(ww)if x==mxw]
for mhs in mh:
    for mws in mw:
        if not(cord[mhs][mhw]):
            print(mxh+mxw)
            exit()
print(mxh+mxw-1)

Submission status: Runtime Error

Solution code:
import collections
h_max,w_max,m = map(int,input().split())
hw = []
for i in range(m):
    HW = list(map(int,input().split()))
    hw.append(HW)
h = []
w = []
for i in range(m):
    h.append(hw[i][0])
    w.append(hw[i][1])
y = [] #爆破数まとめ
for i in list(set(h)): #どの行を爆破するか
    x = 0 #爆破数
    h_copy = h.copy
    w_copy = w.copy
    for j in range(m): #爆破されると座標-jになる
        if h_copy[j] == i:
            h_copy[j] = -j
            w_copy[j] = -j
            x += 1
    w_counter = collections.Counter(w) #wの最頻値
    x += w_counter.most_common()[0][1]
    y += x
print(max(x))

Submission status: Runtime Error

Solution code:
#E
import numpy as np

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

num = np.zeros((h,w))

for i in range(m):
    a,b = map(int,input().split())
    num[a-1,b-1] = 1

Sumw = (np.sum(num , axis = 1))
point1  = np.argmax(Sumw)
Maxw = max(Sumw)

num = np.delete(num,point1,axis = 0)

Sumh = (np.sum(num , axis = 0))
Maxh = max(Sumh)

print(int(Maxw+Maxh))

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())


import itertools

ans = MAX_h+MAX_w

if len(h_list)*len(w_list)<=3*10**5:
    X = h_list


    check = 0


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

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