Problem:


Score : 500 points

Problem Statement

We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).

Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.

Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Constraints

All values in input are integers.

1 \leq H, W \leq 3 \times 10^5

1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)

1 \leq h_i \leq H

1 \leq w_i \leq W

\left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

We can destroy all the targets by placing the bomb at \left(1, 2\right).

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4

Sample Output 3

6



Sample input:
2 3 3
2 2
1 1
1 3


Sample output:
3

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import 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-1, w-1] = 1

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

boms_h = boms.copy()
boms_h[h_max, :] = 0
w_max = np.argmax(np.sum(boms_h, axis=0))
maxw = np.max(np.sum(boms_h, axis=0))
print(int(maxh+maxw))

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input.split())
hwlist = [list(map(int, input().split())) for i in range(M)]
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:
#abc176-e
import sys,math,collections,itertools
import numpy as np


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)
row_bom = []
for rb in point_bom:
    row_bom.append(sum(rb))
col_bom = [sum(x) for x in zip(*point_bom)]
    
max_row = max(row_bom)
max_col = max(col_bom)

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)

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W, M = MAP()
L = [LIST() for i in range(M)]

yoko = [0] * W
tate = [0] * H
Map = [[0] * W for i in range(H)]

for h, w in L:
    Map[h-1][w-1] = 1

for h in range(H):
    tate[h] = sum(Map[h])

for w in range(W):
    for h in range(H):
        yoko[w] += Map[h][w]

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

ma = 0
for h in range(H):
    for w in range(W):
        if Map[h][w] == 1:
            Map2[h][w] = 0
        else:
            Map2[h][w] = yoko[w] + tate[h]
            ma = max(Map2[h][w], ma)
print(ma)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

def pd(s):
    #print(s)
    pass


# input
H, W, M = map(int, input().split())
ms = [
    [int(i) for i in input().split()]
    for m in range(M)
]
pd(f"{H=} {W=} {M=}")
pd(f"{ms=}")

rows = [0]*(H+1)
cols = [0]*(W+1)
bombs = np.zeros((H+1,W+1))

def get_total(row, col):
    total = 0
    for m in ms:
        if (m[0] == row) or (m[1] == col):
            total += 1
            pd(f"o:{m[0]=} {m[1]=}")
        else:
            pd(f"x:{m[0]=} {m[1]=}")
    return total

for m in ms:
    pd(f"{m=}")
    rows[m[0]] += 1
    cols[m[1]] += 1
    bombs[m[0]][m[1]] += 1

rows = np.array(rows)
max_rows = np.where(rows == rows.max())[0].tolist()
pd(f"{max_rows=}")

cols = np.array(cols)
max_cols = np.where(cols == cols.max())[0].tolist()
pd(f"{max_cols=}")

max_total = 0
kabu_flg = False
p = itertools.product(max_rows, max_cols)
for v in p:
    h = v[0]
    w = v[1]
    pd(f"{h=} {w=} {bombs[h][w]=}")
    if bombs[h][w] > 0:
        if kabu_flg is False:
            max_total = get_total(h,w)
            kabu_flg = True
    else:
        max_total = get_total(h,w)
        break


print(max_total)

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=np.sum(B[i])+np.sum(BT[j])-B[i][j]
        if maxmax<sumsum:
            maxmax=sumsum
print(int(maxmax))

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

@njit
def main(counter_h,counter_w,h,w,M):
    MAX_h = max(counter_h.values())
    h_list = [k for k, v in counter_h.items() if v == MAX_h]
    MAX_w = max(counter_w.values())
    w_list = [k for k, v in counter_w.items() if v == MAX_w]

    import itertools

    ans = MAX_h+MAX_w

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


        check = 0


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

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

    print(ans)
    
main(counter_h,counter_w,h,w,M)

Submission status: Runtime Error

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

B = [list(map(int, input().split())) for _ in range(M)]

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0]] == row_max and bombs_col[b[1]] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=map(int, input().split())
    h.append(hi)
    w.append(wi)
    B.append((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)

Submission status: Runtime Error

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

hmax = max(hNum)
wmax = max(wNum)
ans = hmax + wmax
if bom[hNum.index(hmax)][wNum.index(wmax)] == 1:
  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
    
    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:
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:
import collections
H,W,M=map(int,input().split())
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=map(int,input().split())
c1=collections.Counter(h)
c2=collections.Counter(w)
for x in range(M):
    flag=True
    if h[x]==c1.most_common()[i][0] and w[x]==c2.most_common()[j][0]:
        print(c1.most_common()[i][1]+c2.most_common()[j][1]-1)
        exit()
print(c1.most_common()[i][1]+c2.most_common()[j][1])

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = np.zeros((H, W))
ans = 0
'''
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
print(int(ans))

Submission status: Runtime Error

Solution code:
H,W,M=map(int,input().split())
Y=[0 for i in range(H+1)]
X=[0 for i in range(W+1)]
HW=[]
for i in range(M):
    h,w=map(int,input().split())
    Y[h]+=1
    X[w]+=1
    HW.append([h,w])

LY=[]
LX=[]
MY=max(Y)
MX=max(X)
for i in range(H+1):
    if Y[i]==MY:
        LY.append(i)
for i in range(W+1):
    if X[i]==MX:
        LX.append(i)

import sys
for i in range(M):
    if HW[i][0] not in MY or HW[i][1] not in MX:
        print(MY+MX)
        sys.exit()

print(MY+MX-1)

Submission status: Runtime Error

Solution code:
H, W, m = map(int, input().split())
hs = [0] * (H+1)
ws = [0] * (W+1)
fs = [[0]*(W+1) for i in range(H+1)]
for i in range(m):
    hi,wi = map(int, input().split())
    hs[hi-1] += 1
    ws[wi-1] += 1
    fs[hi-1][wi-1] += 1

N = 10**6
Hs = [h*N+i for i,h in enumerate(hs)]
Ws = [w*N+i for i,w in enumerate(ws)]
Hs.sort(reverse=True)
Ws.sort(reverse=True)

mx = 0
cnt = 0
for h_ in Hs:
    nh, ih = divmod(h_,N)
    for w_ in Ws:
        nw, iw = divmod(w_,N)
        mx = max(mx,nh+nw-fs[ih][iw])
        cnt += 1
        if cnt > m:
            print(mx)
            exit()
print(mx)

Submission status: Runtime Error

Solution code:
import collections

h,w,m = map(int,input().split())
l=[]
x=[]
y=[]
for i in range(m):
    hw=list(map(int,input().split()))
    l.append(hw)
    y.append(hw[0])
    x.append(hw[1])

xc = collections.Counter(x)
yc = collections.Counter(y)

tuplex = xc.most_common()[0]
tupley = yc.most_common()[0]

mostx=tuplex[0]
mosty=tupley[0]

if tuplex[1]>tupley[1]:
    y=[]
    for i in range(m):
        if l[i][1]!=mostx:
            y.append(l[i][0])
    yc = collections.Counter(y)
    tupley = yc.most_common()[0]
    mosty=tupley[0]
    ans=0
    for j in range(m):
        if l[j][0] == mosty or l[j][1] == mostx:
            ans+=1
    print(ans)

elif tuplex[1]<tupley[1]:
    x=[]
    for i in range(m):
        if l[i][0]!=mosty:
            x.append(l[i][1])
    xc = collections.Counter(x)
    tuplex = xc.most_common()[0]
    mostx=tuplex[0]
    ans=0
    for j in range(m):
        if l[j][0] == mosty or l[j][1] == mostx:
            ans+=1
    print(ans)

else:
    #y基準
    ans1=0
    x1=[]
    for i in range(m):
        if l[i][0]!=mosty:
            x1.append(l[i][1])
    x1c = collections.Counter(x1)
    tuplex1 = x1c.most_common()[0]
    mostx1=tuplex1[0]
    for j in range(m):
        if l[j][0] == mosty or l[j][1] == mostx1:
            ans1+=1
    #x基準
    ans2=0
    y1=[]
    for i in range(m):
        if l[i][1]!=mostx:
            y1.append(l[i][0])
    y1c =collections.Counter(y1)
    tupley1 = y1c.most_common()[0]
    mosty1=tupley1[0]
    for j in range(m):
        if l[j][0] == mosty1 or l[j][1] == mostx:
            ans2+=1
    print(max(ans1,ans2))

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)

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

    print(int(Maxw+Maxh))
else:
    print(int(Sumw))

Submission status: Runtime Error

Solution code:
h, w, m=(int(x) for x in input().split())
hm = [0] * (h + 1)
wm = [0] * (w + 1)

area = [[0] * (w + 1) for i in range(h + 1)]
for i in range(m):
  hi, wi = (int(x) for x in input().split())
  hm[hi] += 1
  wm[wi] += 1
  area[hi][wi] = 1

max_x = [i for i, v in enumerate(wm) if v == max(wm)]
max_y = [i for i, v in enumerate(hm) if v == max(hm)]

for i in range(len(max_x)):
  for j in range(len(max_y)):
    if (area[max_y[j]][max_x[i]] == 0):
      print(hm[max_y[j]] + wm[max_x[i]])
      quit()

print(wm[max_x[0]] + hm[max_y[0]] - 1)

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
while w[k % W][1] == w[0][1] and k < W:
    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:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros((H))
w = np.zeros((W))
m = np.zeros((H, W))
ans = 0
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

'''
h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
print(int(ans))

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input(split()))
hwlist = [list(map(int, input().split())) for i in range(5)]
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 sys
input = sys.stdin.readline
import numpy as np
import itertools

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

for i in range(m):
    y, x = map(int, input().split())
    Bombs[y-1][x-1] = 1

s_row = np.sum(Bombs, axis = 1)

s_column = np.sum(Bombs, axis = 0)

row_max = max(s_row)
col_max = max(s_column)
fullbomb = np.ones(w)

max_w = np.where(s_row==row_max)
max_h = np.where(s_column==col_max)

c = False

for KK in list(itertools.product(max_w[0], max_h[0])):
    ww = KK[0]
    hh = KK[1]
    if Bombs[ww][hh]==0:
        print(int(row_max+col_max))
        c = True
        break
    else:
        pass
if c:
    pass
else:
    print(int(row_max+col_max-1))

Submission status: Runtime Error

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

map_ = [[0]*W for i in range(H)]
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] 
import numpy as np
map_T = (np.array(map_).T).tolist()
#print(map_T)
for w in range(W):
  cnt_h[w] = sum(map_T[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
import math
for i in range(max((len(h_max_index) // 2), 1)):
  for j in range(max((len(w_max_index) // 2), 1)):
    #print(i, len(w_max_index) - 1 - i)
    #print(j, len(w_max_index) - 1 - j)
    if map_[w_max_index[j]][h_max_index[i]] == 0\
      or map_[w_max_index[len(w_max_index) - 1 - j]][h_max_index[len(w_max_index) - 1 - i]] == 0:
      flg = not flg
      break
  else:
      continue
  break
if flg:
  print(ans)
else:
  print(ans - 1)

Submission status: Runtime Error

Solution code:
from collections import defaultdict as dd
h, w, m = map(int, input().split())

#dic[row, col] -> set(ids)
h_dic = dd(set)
w_dic = dd(set)
spot = set()

for i in range(m):
    h_c, w_c = map(int, input().split())
    h_dic[h_c].add(i)
    w_dic[w_c].add(i)
    spot.add((h_c, w_c))
#print(h_dic, w_dic)

#H_lis -> [i, num_spot(int)]
max_h_num = 0
H_lis = []
for key, val in h_dic.items():
    H_lis.append([key, len(val)])
    max_h_num = max(max_h_num, len(val))
max_w_num = W_lis[0][1]
W_lis = []
for key, val in w_dic.items():
    W_lis.append([key, len(val)])
    max_w_num = max(max_w_num, len(val))


#print(H_lis, W_lis)
#print(max_h)

ans = 0
max_h_lis = [val[0] for val in H_lis if val[1] == max_h_num]
max_w_lis = [val[0] for val in W_lis if val[1] == max_w_num]
for i in max_h_lis:
    for j in max_w_lis:
        count = max_h_num + max_w_num
        if (i, j) in spot:
            count -= 1
        ans = max(ans, count)
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
    
    print(1)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# coding: utf-8

def main():
    h, w, m = map(int, input().split())
    
    matrix = [[0] * w for _ in range(h)]
    
    for i in range(m):
        x, y = map(int, input().split())
        matrix[x-1][y-1] = 1
    # print(matrix)
    
    sum_row = [sum(x) for x in matrix]
    ans_matrix = list(zip(*matrix))
    sum_col = [sum(x) for x in matrix]
    
    # print(sum_row)
    # print(sum_col)
    
    ans_matrix = [sum_col for _ in range(h)]
    ans_matrix = list(zip(*ans_matrix))
    ans_matrix = list(map(lambda x, y: list(map(lambda a,b: a+b, x, y)), ans_matrix, [sum_row for _ in range(w)]))
    
    ans_matrix = list(zip(*ans_matrix))
    ans_matrix = list(map(lambda x, y: list(map(lambda a,b: a-b, x, y)), ans_matrix, matrix))
    
    print(max(max(ans_matrix)))
 
main()

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] == smc):
            h1[i] = 'boom' 

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

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
mapa = [[0]*w for i in range(h)]
strings = [[0, i] for i in range(h)]
rows = [[0, i] for i in range(w)]
maxs = 0
maxr = 0
for i in range(m):
    h1, w1 = map(int, input().split())
    mapa[h1-1][w1-1] = 1
    strings[h1-1][0] += 1
    rows[w1-1][0] += 1
    if strings[h1-1][0] > maxs:
        maxs = strings[h1-1][0]
    if rows[w1-1][0] > maxr:
        maxr = rows[h1-1][0]
summa = maxs + maxr - 1
for i in range(h):
    if strings[i][0] == maxs:
        for j in range(w):
            if rows[j][0] == maxr:
                x = maxs + maxr
                if mapa[strings[i][1]][rows[j][1]] == 1:
                    x -= 1
                if x > summa:
                    summa = x
                    print(summa)
                    exit()
print(summa)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
f = np.zeros([H, W])

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

print(np.max(f))

Submission status: Runtime Error

Solution code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

# def
def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(map(int,input().split())))
    return x

def str_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return x

def int_map():
    return map(int,input().split())

def int_list():
    return list(map(int,input().split()))

def print_space(l):
    return print(" ".join([str(x) for x in l]))

# import
import numpy as np
import statistics
import math
import collections

# main code
H,W,M = int_map()
hw = int_mtx(M)

h = []
w = []
for hhww in hw:
    h.append(hhww[0])
    w.append(hhww[1])

ch = collections.Counter(h)
cw = collections.Counter(w)
a = ch.most_common()[0][1]
b = cw.most_common()[0][1]

if a < b:
    bb = cw.most_common()[0][0]
    hw1 = [i for i in hw if not i[1] == bb]
    
    h1 = []
    for hhww in hw1:
        h1.append(hhww[0])

    ch1 = collections.Counter(h1)
    a1 = ch1.most_common()[0][1]

    print(b+a1)
    exit()
else:
    aa = ch.most_common()[0][0]
    hw1 = [i for i in hw if not i[0] == aa]
    
    w1 = []
    for hhww in hw1:
        w1.append(hhww[1])

    cw1 = collections.Counter(w1)
    b1 = cw1.most_common()[0][1]

    print(a+b1)
    exit()

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, np.max([H,W])+1))
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(int(max_))

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

Submission status: Runtime Error

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

# l = np.array([0]*(h*w))
l = [0]*(h*w)

for _ in range(m):
    h_input, w_input = map(int, input().split())
    # print((h_input-1)*w+w)
    # print(list(map(lambda x: x+1, l[(h_input-1)*w:(h_input-1)+w])))

    l[(h_input-1)*w:(h_input-1)*w+w] = list(map(lambda x: x+1, l[(h_input-1)*w:(h_input-1)*w+w]))

    # l = list(map(lambda a,b: x + z, x,y))
#     l[(h_input-1)*w:(h_input-1)*w+w] += 1
    l[w_input-1::w] =  list(map(lambda x: x+1, l[w_input-1::w]))
    l[(h_input-1)*w+w_input-1] -= 1
print(max(l))

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][1]
    max_w = w[0][1]
    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:
import numpy as np

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

# l = np.array([0]*(h*w))
l = [0]*(h*w)

for _ in range(m):
    h_input, w_input = map(int, input().split())
    # print((h_input-1)*w+w)
    # print(list(map(lambda x: x+1, l[(h_input-1)*w:(h_input-1)+w])))

    l[(h_input-1)*w:(h_input-1)*w+w] = list(map(lambda x: x+1, l[(h_input-1)*w:(h_input-1)*w+w]))

    # l = list(map(lambda a,b: x + z, x,y))
#     l[(h_input-1)*w:(h_input-1)*w+w] += 1
    l[w_input-1::w] =  list(map(lambda x: x+1, l[w_input-1::w]))
    l[(h_input-1)*w+w_input-1] -= 1
print(max(l))

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:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros((H))
w = np.zeros((W))
m = np.zeros((H, W))
ans = 0
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

'''
for i in h_max_index:
    for j in w_max_index:
        if m[i[0]][j[0]] == 1.:
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp
'''
print(int(ans))

Submission status: Runtime Error

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

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

for i in range(f(a)):
    for j in range(f(b)):
        if [a[i][0],b[j][0]] not in c:
            count+=1
            break
    else:
        continue
print(count)

Submission status: Runtime Error

Solution code:
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
while w[k % W][1] == k[0][1] and k < W:
    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:
import collections
import numpy as np

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

table = np.zeros((h, w))
t_bomb = []

for i in range(m):
    table[a[i][0]-1][a[i][1]-1]=1
arr_t = np.array(table).T

h_list = []
for i in range(h):
    c = collections.Counter(table[i])
    count = c[1]
    h_list.append(count)
w_list = []
for j in range(w):
    c_t = collections.Counter(arr_t[j])
    count_t = c_t[1]
    w_list.append(count_t)

for i in range(h):
    for j in range(w):
        if table[i][j]==1:
            t_bomb.append(h_list[i] + w_list[j] - 1)
        else:
            t_bomb.append(h_list[i] + w_list[j])

# print(table)
# print(arr_t)
# print(t_bomb)
print(max(t_bomb))

Submission status: Runtime Error

Solution code:
H,W,M=list(map(int, input().split()))
h = [0] * M
w = [0] * M
R_B = [[0] * W for i in range(H)]
R_B_T = [[0] * H for i in range(W)]
A_B = [[0] * W for i in range(H)]
for i in range(M):
    h[i], w[i] = map(int, input().split())
    R_B[h[i]-1][w[i]-1]=1
    R_B_T[w[i]-1][h[i]-1]=1
for hei in range(H):
    for wid in range(W):
        A_B[hei][wid]=R_B[hei][:].count(1)+R_B_T[wid][:].count(1)-R_B[hei][wid]
print(max(max(A_B)))