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:
from collections import deque
#import sys
#sys.setrecursionlimit(6000)

def dfs(start_h, start_w, S, H, W):
    path = deque()
    path.append((start_h, start_w))
    visited = set()
    #DFS
    while path:
        p = path.pop()
        if p in visited:
            continue
        visited.add(p)
        x, y = p
        for xx, yy in [(x,y+1), (x, y-1), (x+1, y), (x-1, y)]:
            if xx<0 or yy<0 or xx>H or yy>W:
                #print("Not exist:", xx, yy)
                continue
            #print(f"xx, yy={xx},{yy}")
            if S[yy][xx]:
                path.append((xx, yy))
    return visited

def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    S = [[False]*(W+1)]  #S[w][h]でアクセス すなわちy,x
    for _ in range(W):
        S.append([False] + [True if x=='.' else False for x in input()])
    #DFS
    total_visited = set()
    visited = dfs(Ch, Cw, S, H, W)
    total_visited = total_visited.union(visited)
    if (Dh, Dw) in total_visited:
        print(0)
        exit()

    ans = 0
    while True:
        new_dist = set()
        for p in visited:
            x, y = p
            for xx, yy in [(x,y+2), (x, y-2), (x+2, y), (x-2, y)]:
                if xx<0 or yy<0 or xx>H or yy>W:
                    #print("Not exist:", xx, yy)
                    continue
                if (xx, yy) in total_visited:
                    continue
                if S[yy][xx]:
                    new_dist.add((xx, yy))
        #print(total_visited)
        #print(new_dist)
        kono = set()
        for dist in new_dist:
            x, y = dist
            if dist in total_visited:
                continue
            #print(f'new dist={x},{y}')
            new_visited = dfs(x, y, S, H, W)
            #print(f'new_visited={new_visited}')
            if new_visited:
                total_visited = total_visited.union(new_visited)
                ans += 1
                kono = kono.union(new_visited)
        if not kono:
            break
    if (Dh, Dw) in total_visited:
        print(ans)
    else:
        print(-1)




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
h = [0] * (H+1)
w = [0] * (W+1)
l = [[0]*W for i in range(H)]
for i in range(M):
  x, y = map(int, input().split())
  h[x] += 1
  w[y] += 1
  l[x-1][y-1] = 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-1][t-1] == 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 sys
input = sys.stdin.buffer.readline

h, w, m = map(int, input().split())
mapa = [[0]*w for i in range(h)]
strings = [[0, i+1] for i in range(h)]
rows = [[0, i+1] 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]-1][rows[j][1]-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())
#map_ = np.zeros((H, W))
map_ = [[0 for _ in range(H)] for _ in range(W)]

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

y_score = np.sum(map_, axis=1)
x_score = np.sum(map_, axis=0)

y_arg = np.argmax(y_score)
y_args = np.where(y_score==y_score[y_arg])[0]
x_arg = np.argmax(x_score)
x_args = np.where(x_score==x_score[x_arg])[0]


def score(x, y):
    return sum([map_[h][x] for h in range(H)])+sum(map_[y])-map_[y][x]

max_score = 0
for x_arg in x_args:
    for y_arg in y_args:
        current_score = score(x_arg,y_arg)
        if max_score<current_score:
            max_score = current_score
print(int(max_score))

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,:] += 1
  f[:,w-1] += 1

print(np.max(f))

Submission status: Runtime Error

Solution code:
#abc176-e
import sys,math,collections,itertools
import numpy as np
from numba import jit
input = sys.stdin.readline
H,W,M=list(map(int,input().split()))
@jit
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)

Submission status: Runtime Error

Solution code:
import numpy as np

H,W,M = map(int,input().split())
number = np.zeros((H,W))
#print(number)
for i in range(M):
    y,x = input().split()
    y = int(y)-1
    x = int(x)-1
    number[y,x] = 1

ans = 0
for y in range(H):
    for x in range(W):
        count = np.count_nonzero(number == 1, axis=1)[y] + np.count_nonzero(number == 1, axis=0)[x] -number[y,x]
        if(ans<count):
            ans = count

#ans = int(np.max(number))

print(int(ans))

Submission status: Runtime Error

Solution code:
import sys
H, W, M = map(int, input().split())
Hb = [0] * H
Wb = [0] * W
B = [[0] * W for _ in range(H)]
for _ in range(M):
    h, w = map(int, input().split())
    Hb[h - 1] += 1
    Wb[w - 1] += 1
    B[h - 1][w - 1] = 1
HB = max(Hb)
WB = max(Wb)
BB = [0] * W
for i in range(H):
    if Hb[i] == HB:
        for j in range(W):
            if B[i][j] == 1:
                BB[j] = 1
for i in range(W):
    if Wb[i] == WB:
        if BB[i] == 0:
            print(HB + WB)
            sys.exit()
print(HB + WB - 1)

Submission status: Runtime Error

Solution code:
import numpy as np


h,w,m = map(int,input().split())
yp = np.zeros((h,2),dtype=np.int)
yp[:,1] = np.arange(h)
xp = np.zeros((w,2),dtype=np.int)
xp[:,1] = np.arange(w)

b = np.zeros((h,w),dtype=np.int)


for i in range(m):
    hi,wi = map(int,input().split())
    b[hi-1,wi-1] += 1
    yp[hi-1,0] += 1
    xp[wi-1,0] += 1
yps = np.argsort(yp[:,0])[::-1]
ypmax = yp[yps[0]]
#print(ypmax)
#print(b)
ans = 0
for i in range(h):
    a = xp[i,0]+ypmax[0]
    if b[yps[0],i] == 1:
        a -= 1
    ans = max(ans,a)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read

h, w, m = map(int, input().split())
hw = np.array(read().split(), dtype=np.int64)
H = hw[::2]
W = hw[1::2]

a = np.zeros((h+2,w+2),dtype=np.int64)
for i, j in zip(H,W):
    a[i,0] += 1
    a[i+1,0] -= 1
    a[i,1] -= 1
    a[i+1,1] += 1
    a[0,j+1] -= 1
    a[1,j] -= 1
    a[1,j+1] += 1
    a[0,j] += 1
    a[i,j] -= 1
    a[i+1,j] += 1
    a[i,j+1] += 1
    a[i+1,j+1] -=1
a = np.cumsum(a,axis=1)
a = np.cumsum(a,axis=0)
ans = np.max(a)
print(ans)

Submission status: Runtime Error

Solution code:
# 初期入力
import sys
from collections import defaultdict
import numpy as np
input = sys.stdin.readline  #文字列では使わない
H,W,M = map(int, input().split())
bomb =np.zeros(H+1,W+1)
posision =defaultdict(int)

for i in range(M):
    h,w = map(int, input().split())
    bomb[h,:] +=1
    bomb[:,w] +=1
    posision[(h,w)] =1

index =np.unravel_index(np.argmax(bomb), bomb.shape)
bom_max =np.max(bomb)
ans =0
if posision[index] ==1:
    ans =bom_max -1
else:
    ans =bom_max
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
    
    if 2 not in HW:
        ans -= 1
    
    print(ans)
    
if __name__ == '__main__':
    main()

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()))
    hw[0]-=1
    hw[1]-=1
    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[i][0] == mosty or l[i][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[i][0] == mosty or l[i][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[i][0] == mosty or l[i][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[i][0] == mosty1 or l[i][1] == mostx:
            ans2+=1
    print(max(ans1,ans2))

Submission status: Runtime Error

Solution code:
from collections import Counter
H, W, M = map(int, input().split())
h_lst = []
w_lst = []
for i in range(M):
    h, w = map(int, input().split())
    h_lst.append(h)
    if h != 1:
        w_lst.append(w)
c1 = Counter(h_lst)
c2 = Counter(w_lst)
print(c1.most_common(1)[0][1] + c2.most_common(1)[0][1])

Submission status: Runtime Error

Solution code:
h,w,m = map(int,input().split())
h = []
w = []
for i in range(m):
    h_,w_ = map(int,input().split())
    h.append(h_)
    w.append(w_)
print(h.most_common()[0][1] + w.most_common()[0][1])

Submission status: Runtime Error

Solution code:
import collections
H, W, M = map(int,input().split())
xy = [map(int, input().split()) for j in range(M)]
x, y = [list(i) for i in zip(*xy)]
x_d = collections.Counter(x)
x_max = x_d.most_common()[0][1]
a = x_d.most_common()[0][0]

new_y = [i for i in y if i == a]
y_d = collections.Counter(new_y)
y_max = y_d.most_common()[0][1]

ans = x_max+y_max

print(ans)

Submission status: Runtime Error

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

targets = set()
row = [0]*H
col = [0]*W
bomb = [[0]*W for _ in range(H)]

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

r_max = max(row)
c_max = max(col)
ans = 0
# print([h for h in range(H) if row[h] == r_max])
# print([w for w in range(W) if col[w] == c_max])
for h in [h for h in range(H) if row[h] == r_max]:
    for w in [w for w in range(W) if col[w] == c_max]:
        # print(r_max + c_max - 1 if (h, w) in targets else 0)
        if bomb[h][w]:
            ans = max(ans, r_max + c_max - 1)
        else:
            ans = max(ans, r_max + c_max)
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:
from numba import njit

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

arr = []
for _ in range(M):
    h, w = map(int, input().split())
    arr.append((h, w))


@njit
def solve(arr):
    ans = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            tmp = max(ans, sum([x == i or y == j for (x, y) in arr]))
            if ans < tmp:
                ans = tmp
    return ans


print(solve(arr))

Submission status: Runtime Error

Solution code:
H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
counth = [0]*H
countw = [0]*W
ans = 0
for i in P:
    counth[i[0]-1] += 1 
for i in P:
    countw[i[1]-1] += 1 
maxh = 0
for i in counth:
    maxh = max(maxh,i)
h = counth.index(maxh)
ans += maxh
maxw = 0
for i in countw:
    maxw = max(maxw,i)
w = counth.index(maxw)
if [h+1,w+1] in P:
    ans -= 1
ans += maxw
print(ans)

Submission status: Runtime Error

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    INF = 10**7
    h, w = [int(i) for i in input().split()]
    c_h, c_w = [int(i) for i in input().split()]
    d_h, d_w = [int(i) for i in input().split()]
    grid = [["#"] * (w + 2)]
    for _ in range(h):
        line = ["#"] + list(input()) + ["#"]
        grid.append(line)
    grid.append(["#"] * (w + 2))
    warp_count = [[INF] * (w + 2) for _ in range(h + 2)]
    directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
    warps = []
    for x in range(-2, 3):
        for y in range(-2, 3):
            if x == 0 and y == 0:
                continue
            if (x, y) not in directions:
                warps.append((x, y))

    stack = []
    warp_count[c_h][c_w] = 0
    stack.append((c_h, c_w, 0))

    while stack:
        _h, _w, warp = stack.pop()
        warp_count[_h][_w] = warp

        cnt = 0
        # walk
        for _a, _b in directions:
            if grid[_h + _a][_w + _b] != "#" and warp_count[_h + _a][_w + _b] > warp:
                cnt += 1
                stack.append((_h + _a, _w + _b, warp))

        if cnt == 4:  # 4方向行けるときにワープは不要
            continue

        # warp
        for x, y in warps:
            if _h + x < 0 or _h + x > h or _w + y < 0 or _w + y > w:
                continue
            elif grid[_h + x][_w + y] == "#":
                continue

            if warp_count[_h + x][_w + y] > warp + 1:
                stack.append((_h + x, _w + y, warp + 1))

    if warp_count[d_h][d_w] == INF:
        print(-1)
    else:
        print(warp_count[d_h][d_w])
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import collections

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

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

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

Submission status: Runtime Error

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

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

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

w_list = []
h_list = []
for i in range(M):
    if w[i] == w_max:
        w_list.append(i)
    if h[i] == h_max:
        h_list.append(i)

for y in h_list:
    for x in w_list:
        if mine[y][x] == 0:
            print(w_max + h_max)
            sys.exit()

print(w_max+h_max-1)

Submission status: Runtime Error

Solution code:
h, w, n = [int(i) for i in input().split()]
import numpy as np
maps = np.zeros((h, w))
for _ in range(n):
    tmp = [(int(i) -1) for i in input().split()]
    maps[tmp[0], tmp[1]] = 1
sum_row = [np.sum(maps[i, :]) for i in range(h)]
arg_max = np.argmax(sum_row)
col_max = 0
for i in range(w):
    tmp = np.sum(maps[:, i])
    if int(maps[arg_max, i]) == 1:
        tmp -= 1
    if col_max < tmp:
        col_max = tmp
print(int(max(sum_row) + int(col_max)))

Submission status: Runtime Error

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

tate = [0]*(w+1)
yoko = [0]*(h+1)

for i in range(m):
    yoko[hw[i][0]] += 1
    tate[hw[i][1]] += 1
    
ans = 0

t_max = -1


for i in range(1,w+1):
    if t_max < tate[i]:
        t_max = tate[i]
        t_max_idx = []
        t_max_idx.append(i)
    elif t_max == tate[i]:
        t_max_idx.append(i)

y_max = -1

for i in range(1,h+1):
    if y_max < yoko[i]:
        y_max = yoko[i]
        y_max_idx = []
        y_max_idx.append(i)
    elif y_max == yoko[i]:
        y_max_idx.append(i)
        
#s_y = set(y_max_idx)
#s_t = set(t_max_idx)

if len(y_max_idx)*len(t_max_idx) > m:
    print(t_max+y_max)
else:
    ans = 0
    for i in range(m):
        if hw[i][0] in s_y and hw[i][1] in s_t:
            ans += 1
    if ans < len(y_max_idx)*len(t_max_idx):
        print(t_max+y_max)
    else:
        print(t_max+y_max-1)

Submission status: Runtime Error

Solution code:

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


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



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

        for a,b in bomp:
            if a == i or b == j:
                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:
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())
mt = []
for i in range(H):
  mt.append([0]*W)
# print(mt)
for i in range(M):
  h, w = map(int, input().split())
  mt[h-1][w-1] = 1
# print(mt)

# 転置
mt_t = [list(x) for x in zip(*mt)]
# print(mt_t)

# 手当たりしだい爆弾を置くことで、合計値を求める
maxt = 0
# 行列の合計値

a = []
b = []
for i in range(H):
  a.append(sum(mt[i]))
for j in range(W):
  b.append(sum(mt_t[j]))

maxk = 0
for i in range(H):
  for j in range(W):
    if maxk < a[i] + b[j]:
      maxk = a[i] + b[j]
print(maxk)

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import Counter

H, W, M = [int(n) for n in input().split()]
h = []
w = []
table = np.zeros((H, W))
for m in range(M):
    tmp = [int(n) for n in input().split()]
    h.append(tmp[0])
    w.append(tmp[1])
    table[tmp[0]-1][tmp[1]-1] = 1

h_counter = Counter(h)
w_counter = Counter(w)

most_common_h_list = []
most_common_w_list = []

most_common_h_count = 0
for k, v in h_counter.most_common():
    if v < most_common_h_count:
        break
    most_common_h_list.append(k)
    most_common_h_count = v

most_common_w_count = 0
for k, v in w_counter.most_common():
    if v < most_common_w_count:
        break
    most_common_w_list.append(k)
    most_common_w_count = v

ans = 0
finished = False
for hh in most_common_h_list:
    if finished:
        break
    for ww in most_common_w_list:
        if table[hh-1][ww-1] == 1:
            tt = most_common_h_count + most_common_w_count - 1
            if tt > ans:
                ans = tt
        else:
            tt = most_common_h_count + most_common_w_count
            if tt > ans:
                ans = tt
            break
            finished = True
            break

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

MX=np.sum(MA,axis=1)
MY=np.sum(MA,axis=0)
# print(MA)
# print(MX)
# print(MY)
xmax=max(MX)
ymax=max(MY)
ix=[x[0] for x in enumerate(MX) if x[1]==xmax]
iy=[x[0] for x in enumerate(MY) if x[1]==ymax]

ii=min([MA[x,y] for x in ix for y in iy])

print(int(xmax+ymax-ii))

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):
    # for w in range(W):
        # yoko[i] += L[h][W]
    tate[h] = sum(Map[h])

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

# print(tate)
# print(yoko)


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

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

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

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

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

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

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

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

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

print(answer)

Submission status: Runtime Error

Solution code:
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)a
r_sum=arr.sum(axis=1)
c_sum.sort()
l_sum.sort()

print(int(c_sum[-1]+l_sum[-1]))

Submission status: Runtime Error

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

hlist = [0 for i in range(M)]
wlist = [0 for i in range(M)]
s = [["-" for i in range(W)]for i in range(H)]

for i in range(M):
    h[i],w[i] = map(int, input().split())
    s[h[i]-1][w[i]-1] = "o"
    hlist[h[i]-1] += 1
    wlist[w[i]-1] += 1

hmax = max(hlist)
wmax = max(wlist)

argh = [i for i, v in enumerate(hlist) if v == hmax]
argw = [i for i, v in enumerate(wlist) if v == wmax]
flag = False
for i in argh:
    for j in argw:
        if s[i][j] == "-":
            flag = True
            break

if flag:
    print(hmax+wmax)
else:
    print(hmax+wmax-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 sys
import numpy as np
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    H, W, M = map(int, input().split())
    mm = []
    l = np.zeros((H, W))
    for i in range(M):
        a, b = map(int, input().split())
        mm.append([a, b])
        l[a-1][b-1] = 1
    row_max = 0
    row_num = 0
    col_max = 0
    col_num = 0

    r = np.count_nonzero(l == 1, axis=1)
    row_max = max(r)
    row_num = np.argmax(r)

    c = np.count_nonzero(l == 1, axis=0)
    col_max = max(c)
    col_num = np.argmax(c)

    a = np.count_nonzero(c == col_max)
    if [row_num+1, col_num+1] in mm:
        print(row_max + col_max - 1)
    else:
        print(row_max + col_max)
        
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter


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

l_p = []
l_h = []
l_w = []

for i in range(M) :
    p = input().split()
    l_p.append(p)
    l_h.append(p[0])
    l_w.append(p[1])


ans_max = 0
for h in Counter(l_h).keys():
    ans = 0
    ans = ans + l_h.count(h)

    l_w_2 = [x[1] for x in l_p if x[0] != h]
    ans = ans + max(Counter(l_w_2).values())

    if ans > ans_max :
        ans_max = ans


print(ans_max)

Submission status: Runtime Error

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
ans=0
mass=[[0 for i in range(10**6)] for j in range(10**6)]
for i in range(M):
    h,w=nm()
    mass[h][w]=1
    r[h]+=1
    c[w]+=1

inds1=list(range(10**6))
inds1.sort(key=lambda x: r[x])

inds2=list(range(10**6))
inds2.sort(key=lambda x: c[x])

r.sort(reverse=True)
l.sort(reverse=True)

r1=0
l1=0

while(1):
    if(r[r1+1]==r[r1])
        r1+=1
    else:
        break

while(1):
    if(l[l1+1]==l[l1])
        l1+=1
    else:
        break

flag=False
for i in range(r1+1):
    for j in range(l1+1):
        if(mass[inds1[i]][inds2[j]]==0):
            flag=True
        
if(flag==True):
    print(r[0]+l[0])
else:
    print(r[0]+l[0]-1)

Submission status: Runtime Error

Solution code:
# E
H, W, M = map(int, input().split())
B = []
h = []
w = []
for x in range(M):
    a, b = map(int, input().split())
    B.append([a, b])
    h.append(a)
    w.append(b)
c = {}
d = {}
for x in range(1, H):
    c[x] = h.count(x)
for x in range(1, W):
    d[x] = w.count(x)
Mc = max(c.values())
Md = max(d.values())
Kc = [k for k, v in c.items() if v == Mc]
Kd = [k for k, v in d.items() if v == Md]
if [Kc[0], Kd[0]] in B:
    print(Mc + Md -1)
else:
    print(Mc + Md)