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 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[h-1][w-1] = 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 object[cand_h[i]][cand_w[j]] == 0:
            ans += 1
else:
   ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
h,w,m  = list(map(int, input().strip().split()))
a=[0]*m
b=[0]*m
grid = []
for i in range(m):
    array = list(map(int, input().strip().split()))
    grid.append(array)
for i in range(m):
    a[i]=grid[i][0]
    b[i]=grid[i][1]
H=[0]*h
W=[0]*w
for i in range(h):
    H[i]=a.count(i+1)
for i in range(h):
    W[i]=b.count(i+1)
kosuu= []
for i in range(h):
    for j in range(w):
        if [i,j]in grid:
            kosuu.append(H[i]+W[j]-1)
        else:
            kosuu.append(H[i]+W[j])

print(max(kosuu))

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m=map(int, input().split())
a = np.zeros((h,w))
ans=0

for i in range(m):
    x,y=map(int, input().split())
    a[x-1,y-1]=1
    
c = a.sum(axis=0)
r = a.sum(axis=1)
cm = max(c)
rm = max(r)
ci = [i for i, x in enumerate(c) if x == cm]
ri = [i for i, x in enumerate(r) if x == rm]
ans = cm + rm

#print(a,c,r,ci,ri)

for i in ri:
    for j in ci:
        if a[i,j]==0:
            print(int(ans))
            exit()

print(int(ans)-1)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

x,y,n,=I()
arr=[[0]*y for _ in range(x)]

t1=[0]*x
t2=[0]*y

while n:
    n-=1
    a,b,=I()
    arr[a-1][b-1]=-1
    t1[a-1]+=1
    t2[b-1]+=1

maxi=0
for i in range(x):
    for j in range(y):
        val=t1[i]+t2[j]+arr[i][j]
        if maxi<val:
            maxi=val

print(maxi)

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

while 0 in w:
  w.remove(0)

w_p = collections.Counter(w).most_common()
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())
hw=[list(map(int,input().split())) for i in range(m)]
field=[[0]*w for i in range(h)]
hs=[0]*h
ws=[0]*w
for h,w in hw:
  field[h-1][w-1]=1
  hs[h-1]+=1
  ws[w-1]+=1
  

k=0
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:
    #print(x+1,y+1)
    if field[x][y]==0:
      #print(x+1,y+1)
      k=1
      break
if k==1:
  print(hmax+wmax)
else:
  print(hmax+wmax-1)

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)
bool = False
for i in h_kouho:
    for j in w_kouho:
        if bomb[i][j]==0:
            bool=True
if bool:
    print(h_max+w_max)
else:
    print(h_max+w_max-1)

Submission status: Runtime Error

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

hlist=[0]*H
wlist=[0]*W
hwset=set()
for _ in range(M):
  h,w=map(int,input().split())
  hlist[h-1]+=1
  wlist[w-1]+=1
  hwset.add((h-1,w-1))
  
hmax=max(hlist)
wmax=max(wlist)

hlist2=[]
for i in range(H):
  if hlist[i]==hmax:
    hlist2.append(i)
hlist2.sort(reverse=True)
random.shuffle(hlist2)

wlist2=[]
for i in range(W):
  if wlist[i]==wmax:
    wlist2.append(i)
wlist2.sort(reverse=True)
random.shuffle(wlist2)

#print(hlist2,wlist2)
H2=len(hlist2)
W2=len(wlist2)

if H2*W2>10**7:
  norm=(H2*W2)//(10**7)+1
  H2=int(H2/(norm**0.5))
  W2=int(W2/(norm**0.5))

for i in range(H2):
  ii=hlist2[i]
  for j in range(W2):
    jj=wlist2[j]
    if not (ii,jj) in hwset:
      print(hh+ww)
      sys.exit(0)
else:
  print(hmax+wmax-1)

Submission status: Runtime Error

Solution code:
from itertools import product
INF = float('inf')

H, W = map(int, input().split())
ch, cw = [int(i) - 1 for i in input().split()]
dh, dw = [int(i) - 1 for i in input().split()]
S = [input() for i in range(H)]
# print(S)

B = [[INF for w in range(W)] for h in range(H)]
B[ch][cw] = 0
# print(B)

def get_B(h, w):
    if not ((0 <= h < H) and (0 <= w < W)):
        return INF
    else:
        return B[h][w]

flag = True
while flag:
    flag = False

    for h, w in product(range(H), range(W)):
        if S[h][w] == '#':
            continue

        # 横
        min_v = min(get_B(h - 1, w),
                    get_B(h + 1, w),
                    get_B(h, w - 1),
                    get_B(h, w + 1))

        # ワープ
        for i, j in product(range(5), repeat=2):
            if not ((0 <= h - i + 2 < H) and (0 <= w - j + 2 < W)):
                continue
            min_v = min(min_v,
                        B[h - i + 2][w - j + 2] + 1)

        if B[h][w] > min_v:
            B[h][w] = min_v
            flag = True

print(B[dh][dw] if B[dh][dw] != INF else -1)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

L = MAP.sum( axis = 0 )
a = L.max()
LW = [ i for i, v in enumerate( L ) if v == L.max() ]

L = np.array( MAP.sum( axis = 1 ))
b = L.max()
LH = [ i for i, v in enumerate( L ) if v == L.max() ]

maxV = 0
is_true = False
for i in LH:
  for j in LW:
    if MAP[ i ][ j ] == 0:
      is_true = True
      break
if is_true:
  print( int( a + b ))
else:
  print( int( a + b - 1 ))

Submission status: Runtime Error

Solution code:
import sys
from copy import copy

h, w, m = sys.stdin.readline().split(' ')

field = []
for y in range(int(h)):
    line = []
    for x in range(int(w)):
        line.append('.')
    field.append(line)

for i in range(int(m)):
    y, x = sys.stdin.readline().split(' ')
    field[int(y) - 1][int(x) - 1] = '*'


class BombArea:
    i: int
    bomb_count: int


bombs_horizontal = []
for y in range(int(h)):
    bomb_count = sum([
        1 if pixel == '*' else 0
        for pixel in field[y]
    ])
    bombs_horizontal.append((y, bomb_count))

bombs_horizontal = sorted(
    bombs_horizontal,
    key=lambda t: t[1],
    reverse=True,
)

field_tuple = list(zip(*field))
bombs_vertical = []
for x in range(int(w)):
    bomb_count = sum([
        1 if pixel == '*' else 0
        for pixel in field_tuple[x]
    ])
    bombs_vertical.append((x, bomb_count))

bombs_vertical = sorted(
    bombs_vertical,
    key=lambda t: t[1],
    reverse=True,
)


def vertical():
    maxes = []
    max = bombs_vertical[0]
    for v in bombs_vertical:
        if max[1] == v[1]:
            maxes.append(v)
    return maxes


def horizontal():
    maxes = []
    max = bombs_horizontal[0]
    for v in bombs_horizontal:
        if max[1] == v[1]:
            maxes.append(v)
    return maxes


exit = False
while True:
    x_list = vertical()
    y_list = horizontal()
    max_pos = None
    max = 0
    for x in x_list:
        for y in y_list:
            if field[y[0]][x[0]] == '.':
                if max < y[1] + x[1]:
                    max_pos = x[0], y[0]
                    max = y[1] + x[1]

    if max_pos is not None:
        print(max)
        break

    if bombs_vertical[0][1] < bombs_horizontal[0][1]:
        bombs_vertical.pop(0)
    else:
        bombs_horizontal.pop(0)

    if exit:
        break

Submission status: Runtime Error

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

T_FIELD = np.array(FIELD).T.tolist()
for i in range(W):
    sum = 0
    for j in range(H):
        sum += T_FIELD[i][j]
    w_list.append(sum)

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:
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
sum_retu = np.sum(array_hw,axis=0)
sum_gyou = np.sum(array_hw,axis=1)
ans = 0
for i in range(h):
    for j in range(w):
        ans_temp = sum_gyou[i] + sum_retu[j] - (array_hw[i,j] == 1)
        ans = max(ans, ans_temp)
print(int(ans))

Submission status: Runtime Error

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

B = [[0] * W for _ in range(H)]

for _ in range(M):
  i, j = map(int, input().split())
  B[i-1][j-1] = 1

ans = 0
  
for i in range(H):
  for j in range(W):

    tmp = sum(B[i])
    tmp -= B[i][j]
    for h in range(H):
      tmp += B[h][j]
      
    ans = max(ans, tmp)

print(ans)

Submission status: Runtime Error

Solution code:
H, W, M = list(map(int, input().split()))
import numpy as np
Mat = np.zeros((H,W), dtype=np.int32)
for i in range(M):
  i,j = list(map(int, input().split()))
  Mat[i-1, j-1] = 1

x = np.argmax(Mat.sum(axis=0))
out = Mat[:, x].sum()
Mat[:, x] = 0
out += np.max(Mat.sum(axis=1))
print(out)

Submission status: Runtime Error

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

M = np.zeros((H+1, W+1))
temp = np.zeros((2, H+W))
for i in range(N):
    a, b = list(map(int, input().split()))
    M[a][b] = 1
    temp[0][a] += 1
    temp[1][b] += 1

max_ = 0
for i in range(H):
    for j in range(W):
        if temp[0][i+1]+temp[1][j+1]-M[i+1][j+1] > max_:
            max_ = temp[0][i+1]+temp[1][j+1]-M[i+1][j+1]
print(max_)

Submission status: Runtime Error

Solution code:



def LI():
    return list(map(int,input().split()))
    
def OPEN():
    return map(int,open(0).read().split())

h,w,m=LI()
S=[[0]*w for i in range(h)]
a=[0]*h
b=[0]*w
for i in range(m):
    h,w=LI()
    
    S[h-1][w-1]+=1
    a[h-1]+=1
    b[w-1]+=1

# print(S)

    
now=0
ind_x=[]
ind_y=[]
# Ssumx=[sum(i) for i in S]
# SS=S.T
# Ssumy=[sum(i) for i in SS]



mx=max(a)
# max(Ssumx)
for i,j in enumerate(a):
    if j==mx:
        ind_x.append((i,j))
my=max(b)
# max(Ssumy)
for i,j in enumerate(b):
    if j==my:
        ind_y.append((i,j))
ans=0
for x,numx in ind_x:
    for y,numy in ind_y:
        if S[x][y]==0:
            tmp=numx+numy
        else:
            tmp=numx+numy-1

            
        ans=max(ans,tmp)
        
print(ans)

Submission status: Runtime Error

Solution code:
INF = float('inf')

H, W = map(int, input().split())
ch, cw = [int(i) - 1 for i in input().split()]
dh, dw = [int(i) - 1 for i in input().split()]
S = [input() for i in range(H)]
# print(S)

B = [[INF for w in range(W)] for h in range(H)]
B[ch][cw] = 0
# print(B)

def get_B(h, w):
    if not ((0 <= h < H) and (0 <= w < W)):
        return INF
    else:
        return B[h][w]

flag = True
while flag:
    flag = False

    for h, w in product(range(H), range(W)):
        if S[h][w] == '#':
            continue

        # 横
        min_v = min(get_B(h - 1, w),
                    get_B(h + 1, w),
                    get_B(h, w - 1),
                    get_B(h, w + 1))

        # ワープ
        for i, j in product(range(5), repeat=2):
            if not ((0 <= h - i + 2 < H) and (0 <= w - j + 2 < W)):
                continue
            min_v = min(min_v,
                        B[h - i + 2][w - j + 2] + 1)

        if B[h][w] > min_v:
            B[h][w] = min_v
            flag = True
            # for b in B:
            #     print(b)
            # print()

print(B[dh][dw] if B[dh][dw] != INF else -1)

Submission status: Runtime Error

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

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

wb = numpy.sum(mine, axis = 0)
wcandidate = numpy.where(wb == numpy.max(wb))[0]

hb = numpy.sum(mine, axis = 1)
hcandidate = numpy.where(hb == numpy.max(hb))[0]

ans = 0

for h, w in itertools.product(hcandidate, wcandidate):
    ans = max(ans, numpy.sum(mine[h, :]) + numpy.sum(mine[:, w]) - mine[h, w])

print(int(ans))

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)

colmarg=np.argsort(-colm,kind='quicksort')
linearg=np.argsort(-line,kind='quicksort')

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

ataimax=0
for ih in linearg[0:hhh]:
  for iw in colmarg[0:www]:
    atai=colm[iw]+line[ih]-ans[ih,iw]
    if (atai >= ataimax): ataimax=atai

print (ataimax)

Submission status: Runtime Error

Solution code:
import numpy as np
h, w, n = map(int, input().split())
b_lists = []
for i in range(n):
   b_lists.append(list(map(int, input().split())))

mx = np.zeros((h,w))
for b_list in b_lists:
  m_h = b_list[0] - 1
  m_w = b_list[1] - 1 
  mx[m_h, m_w] = 1

sum_max = 0
print(list(map(str, list(mx[:,0]))).count("1.0"))
for i in range(h):
  for j in range(w):
    icount = list(map(str, list(mx[i,:]))).count("1.0")
    jcount = list(map(str, list(mx[:,j]))).count("1.0")
    if mx[i, j] == 1:
      tmp_max = icount + jcount - 1
    else:
      tmp_max = icount + jcount
    if sum_max < tmp_max:
      sum_max = tmp_max
print (sum_max)

Submission status: Runtime Error

Solution code:
import numpy

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

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

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 sys
import random
H,W,M=map(int,input().split())

hlist=[0]*H
wlist=[0]*W
hwset=set()
for _ in range(M):
  h,w=map(int,input().split())
  hlist[h-1]+=1
  wlist[w-1]+=1
  hwset.add((h-1,w-1))
  
hmax=max(hlist)
wmax=max(wlist)

hlist2=[]
for i in range(H):
  if hlist[i]==hmax:
    hlist2.append(i)
hlist2.sort(reverse=True)
random.shuffle(hlist2)

wlist2=[]
for i in range(W):
  if wlist[i]==wmax:
    wlist2.append(i)
wlist2.sort(reverse=True)
random.shuffle(wlist2)

#print(hlist2,wlist2)
H2=len(hlist2)
W2=len(wlist2)

if H2*W2>10**7:
  norm=(H2*W2)//(10**7)
  H2=int(H2/(norm**0.5))
  W2=int(W2/(norm**0.5))

for i in range(H2):
  ii=hlist2[i]
  for j in range(W2):
    jj=wlist2[j]
    if not (ii,jj) in hwset:
      print(hh+ww)
      sys.exit(0)
else:
  print(hmax+wmax-1)

Submission status: Runtime Error

Solution code:
import numpt as np
H,W,M=map(int, input().split())
hl=np.array([0 for i in range(H+1)])
wl=np.array([0 for i in range(W+1)])
ms=[]
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.append([h,w])
a=max(hl)
b=max(wl)
hmax= [i for i, x in enumerate(hl) if x ==a]
wmax=[i for i, x in enumerate(wl) if x ==b]
a=max(hl)
b=max(wl)
bl=False
for x in hmax:
    for y in wmax:
        if [x,y] not in ms:
            bl=True
            break
    if bl:
        break
if bl:
    print(a+b)
else:
    print(a+b-1)

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

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


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 = 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:
import numpy as np
number=list(map(int,input().split()))
H,W,M=number[0],number[1],number[2]
h_count=[0 for i in range(H+1)]
w_count=[0 for i in range(W+1)]
T=[]
ans=[]
flag=0
for i in range(M):
    S=list(map(int,input().split()))
    T.append(S)
    h_count[S[0]]+=1
    w_count[S[1]]+=1
h=max(h_count)
w=max(w_count)
if [h_count.index(h),w_count.index(w)] in T:
    h_count=np.array(h_count)
    w_count=np.array(w_count)
    h_max=[i for i, x in enumerate(h_count) if x == h]
    w_max=[i for i, x in enumerate(w_count) if x == w]
    for i in h_max:
        for j in w_max:
            if [i,j] in T:
                pass
            else:
                print(h+w)
                flag=1
                break
    if flag==0:
        print(h+w-1)
else:
    print(int(h+w))

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys

h, w, m = map(int, sys.stdin.readline().split())
hl = []
wl = []

lst = [[0]*w for _ in range(h)]

for _ in range(m):
    hi, wi = map(int, sys.stdin.readline().split())
    lst[hi-1][wi-1] = 1
    hl.append(hi)
    wl.append(wi)

hc = Counter(hl)
wc = Counter(wl)

maxh = max(hc.values())
maxw = max(wc.values())

seth = []
setw = []

for c,num in hc.most_common():
    if num != maxh:
        break
    seth.append(c)

for c,num in wc.most_common():
    if num != maxw:
        break
    setw.append(c)



ans = 0

for hei in seth:
    for wei in setw:
        temp = hc[hei] + wc[wei]
        if lst[hei-1][wei-1] == 1:
            temp -= 1
        ans = max(ans, temp)

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
if N%9==0:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
mh = [None]*m
mw = [None]*m
bomb = {}
ans = 0
MAX = 0
MAX_key = None

for i in range(m):
    mh[i], mw[i] = map(int, input().split())
    if mh[i] in bomb:
        bomb[mh[i]] += 1
        if MAX < bomb[mh[i]]:
            MAX = bomb[mh[i]]
            MAX_key = mh[i]
    else:
        bomb[mh[i]] = 1

dele = MAX_key
num = MAX
bomb2 = {}
for i in range(m):
    if mh[i] == dele:
        continue
    if mw[i] in bomb2:
        bomb2[mw[i]] += 1
    else:
        bomb2[mw[i]] = 1
max_v = max(bomb2.values())
total = num + max_v
ans = max(ans, total)

print(ans)

Submission status: Runtime Error

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

for i in range(M):
    a, b = map(int, input().split())
    X.append(a)
    Y.append(b)
    A = collections.Counter(X)
    B = collections.Counter(Y)
cnt_x = A.most_common()[0][0]
cnt_y = B.most_common()[0][0]

x = A.most_common()[0][1]
y = B.most_common()[0][1]
print (cnt_x + cnt_y)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(m)]
hlist = [0]*h
wlist = [0]*w
hwlist = [[0]*w for _ in range(h)]
for i in hw:
    hlist[i[0]-1]+=1
    wlist[i[1]-1]+=1
    hwlist[i[0]-1][i[1]-1]+=1

hmax=max(hlist) 
h_index = [n for n, v in enumerate(hlist) if v == hmax]
wmax=max(wlist)
w_index = [n for n, v in enumerate(wlist) if v == wmax]

import sys
for i in h_index:
    for j in w_index:
        if hwlist[i][j]==0:
            print(hlist[i]+wlist[j])
            sys.exit()
else:
    print(hlist[i]+wlist[j]-1)

Submission status: Runtime Error

Solution code:
import sys

H, W, M = map(int, input().split())
d = [[0]*W for _ in range(H)]
for _ in range(M):
    h, w = map(int, input().split())
    h, w = h-1, w-1
    d[h][w] = 1
tate, yoko = [], []
for w in range(W):
    res = 0
    for h in range(H): res += d[h][w]
    tate.append(res)
for h in range(H):
    yoko.append(sum(d[h]))
    
tate_max = max(tate)
yoko_max = max(yoko)

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 d[h][w]!=1:
            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())
S = [[0]*W for _ in range(H)]
dich = {i: 0 for i in range(H)}
dicw = {i: 0 for i in range(W)}
dic = set()
for _ in range(M):
  h, w = map(lambda x: int(x)-1, input().split())
  dich[h] += 1
  dicw[w] += 1
  dic.add((h, w))

sh = sorted(dich.items(), key=lambda x:-x[1])
sw = sorted(dicw.items(), key=lambda x:-x[1])
maxh = max([i for _, i in sh])
maxw = max([i for _, i in sw])
ans = 0
for h, c1 in sh:
  flg = False
  if c1 < maxh:
    break
  for w, c2 in sw:
    if c2 < maxw:
      flg = True
      break
    if (h, w) in dic:
      ans = max(ans, c1+c2-1)
    else:
      ans = max(ans, c1+c2)
  if flg:
    break

print(ans)

Submission status: Runtime Error

Solution code:
import math
import collections
import sys

h, w, m = map(int, input().split())
x = []
y = []
bomb = []
for i in range(m):
  tmp_x, tmp_y = map(int, input().split())
  x.append(tmp_x)
  y.append(tmp_y)
  bomb.append([tmp_x, tmp_y])

c_x = collections.Counter(x)
c_y = collections.Counter(y)
_max_x = c_x.most_common()[0][1]
_max_y = c_y.most_common()[0][1]
ys = c_y.most_common()
count = _max_x + _max_y - 1
      
tansaku_x = []
tansaku_y = []
for x, x_num in c_x.most_common():
  if x_num != _max_x:
    break
  tansaku_x.append(x)
for y, y_num in c_y.most_common():
  if y_num != _max_y:
    break
  tansaku_y.append(y)

for x in tansaku_x:
  for y in tansaku_y:
    if [x, y] not in bomb:
      print(count+1)
      sys.exit()
      
print(_max_bomb)

Submission status: Runtime Error

Solution code:
import random
import time
start=time.time()
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
hh.sort(reverse=1)
t=hh[0][0]
hhh=[]
for x,i in hh:
  if x==t:h.append((x,i))
ans=[]
random.shuffle(w)
for j in w:
  for x,i in hhh:
    if (i,j) in hw:
      ans.append(s+x-1)
    else:
      exit(print(s+x))
  if time.time()-start>=1.7:
    m=ans[0]
    if h-50000<=len(hhh)<=h-random.randint(1,30):m+=1
    exit(print(m))
print(ans[0])

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys

H,W,M,*hw = map(int,open(0).read().split())

h = hw[::2]
w = hw[1::2]

bomb = [[0]*W for _ in range(H)]
for hi,wi in zip(h,w):
    bomb[hi-1][wi-1] = 1


raw_count = Counter(h)
col_count = Counter(w)

raw_max = raw_count.most_common()[0][1]
col_max = col_count.most_common()[0][1]

ans = 0
for hi, rcount in raw_count.most_common():
    if rcount<raw_max:break
    for wi, ccount in col_count.most_common():
        if ccount<col_max: break
        
        if bomb[hi-1][wi-1]==1:
            ans = raw_max + col_max - 1
        else:
            print(raw_max + col_max)
            sys.exit()

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 = list(map(int,input().split()))
        tmp_0 = tmp[0]-1
        tmp_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
    
    if 2 not in HW:
        ans -= 1
    
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
H,W,M = [int(x) for x in input().split()]
hw = []
hNum = [0]*10
wNum = [0]*10

for i in range(M):
    h,w = [int(x) for x in input().split()]
    hw.append([h,w])
    hNum[h]+=1
    wNum[w]+=1

hmax = max(hNum)
hMaxList = []
wmax = max(wNum)
wMaxList = []

for i in range(10):
    if(hmax == hNum[i]):
        hMaxList.append(i)

    if(wmax == wNum[i]):
        wMaxList.append(i)

ans = wmax + hmax
for i in range(10):
    if([i,i] in hw and i in hMaxList and i in wMaxList):
        ans -= 1
if(len(hw) < 10 and (hmax ==  1 or  wmax ==  1 )):
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

H,W,M = map(int,input().split())
target = np.zeros(shape=(M,2))

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

grid = np.zeros(shape=(H,W))

for t in target:
    h = int(t[0])-1
    w = int(t[1])-1
    grid[h,w] = 1


row_sum = grid.sum(axis=1) #行
col_sum = grid.sum(axis=0) #列
i = np.argmax(row_sum)


col_idx = np.where(col_sum==col_sum.max())[0]
j = col_idx[0]
for j_ in col_idx:
    if grid[i,j_]==0:
        j = j_
        break
    
ans = row_sum[i] + col_sum[j]

if grid[i,j]==1:
    ans -=1

print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
H,M,W = map(int,input().split())
stage = np.zeros((H,W))
for w in range(W):
    a,b = map(int,input().split())
    stage[a-1,b-1] = 1
ans = 0
for h in range(H):
    for w in range(W):
        tmp = 0
        tmp += stage[h,:].sum()
        tmp += stage[:,w].sum()
        if stage[h,w] == 1:
          tmp -= 1
        ans = max(ans,tmp)
print(int(ans))

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))
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
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:
import numpy

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

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

for i,j in bomb:
    try:
        x[i-1][j-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:
H,W,M= map(int,input().split())
S = [[0 for i in range(W)] for j in range(H) ]

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

maxcount = 0  
mpcount = 0  

for Pi in range(H):
  for Pj in range(W):
    
    tmpcount = 0
    
    for i in range(H):
      tmpcount = tmpcount + S[i][Pj]
    for j in range(W):
      tmpcount = tmpcount + S[Pi][j]
      
    if maxcount < tmpcount:
      maxcount = tmpcount

Submission status: Runtime Error

Solution code:
import collections
import sys
sys.setrecursionlimit(10**8)

left = []
right = []
position = []

count = 0

H, W, M = map(int, input().split())
for i in range(M):
    l, r = map(int, input().split())
    left.append(l)
    right.append(r)

c_left = collections.Counter(left)
count += c_left.most_common()[0][1]

for i in range(M):
    if left[i] == c_left.most_common()[0][0]:
        position.append(i)

for i in range(c_left.most_common()[0][1]):
    del right[position[i]-i]

c_right = collections.Counter(right)
count += c_right.most_common()[0][1]

print(count)

Submission status: Runtime Error

Solution code:
a, b, c = map(int, input().split())
d = [input().split() for l in range(c)]
counter_x = {}
counter_y = {}
for n in range(c):
    if d[n][0] in counter_x.keys():
        counter_x[d[n][0]] += 1
    else:
        counter_x[d[n][0]] =1
    if d[n][1] in counter_y.keys():
        counter_y[d[n][1]] += 1
    else:
        counter_y[d[n][1]] =1
max_x = max(counter_x, key=counter_x.get)
max_y = max(counter_y, key=counter_y.get)
for l in d:
    if l == [max_x, max_y]:
        u = 1
    else:
        pass
print(int(max(counter_x.values())) + int(max(counter_y.values())) - u)