Problem:


Score : 500 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq h_i \leq H

1 \leq w_i \leq W

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

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

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

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

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

Sample Output 3

6



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


Sample output:
3

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
Map= np.zeros((h,w))
for i in bomb:
    Map[i] = 1
    
bombx = np.count_nonzero(Map,axis=0)
bomby = np.count_nonzero(Map,axis=1)
maxx = max(bombx)
maxy = max(bomby)
maxx_index = np.where(bombx == maxx)
maxy_index = np.where(bomby == maxy)

flag = 0
for i in maxx_index[0]:
    for j in maxy_index[0]:
        if Map[i][j] == 0:
            flag = 1
if flag == 0:
    print(maxx+maxy)
else:
    print(maxx+maxy-1)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
Map= np.zeros((h,w))
for i in bomb:
    Map[i] = 1
print(Map)

bombx = np.count_nonzero(Map,axis=0)
bomby = np.count_nonzero(Map,axis=1)
print(bombx)
maxx = max(bombx)
maxy = max(bomby)

maxx_index = np.where(bombx == maxx)
maxy_index = np.where(bomby == maxy)
flag = 0
print(maxx_index[0],maxy_index[0])
for i in maxx_index[0]:
    for j in maxy_index[0]:
        if Map[i][j] == 0:
            flag = 1
if flag == 0:
    print(maxx+maxy)
else:
    print(maxx+maxy-1)

Submission status: Runtime Error

Solution code:
h,w,m = map(int, input().split())
lw= [0 for i in range(w+1)]
lh= [0 for i in range(h+1)]
lm= list()
for i in range(m):
  l =list(map(int, input().split()))
  lh[l[0]] += 1
  lw[l[1]] += 1
  lm.append(l)
hmax = max(lh)
wmax = max(lw)
ttl=0
for hh in range(1,h+1):
  if lh[hh] == hmax:
    for ww in range(1,h+1):
      if lw[ww] == wmax:
        flg = 0
        for ii in range(len(lm)):
          if lm[ii][0] == hh and lm[ii][1] == ww:
            flg = -1
        if ttl < hmax + wmax + flg:
          ttl = hmax + wmax + flg
print(ttl)

Submission status: Runtime Error

Solution code:
import numpy as np

# H, W, M = 3, 3, 4
# ARR = [
#     [3, 3],
#     [3, 1],
#     [1, 1],
#     [1, 2],
# ]

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

for i in range(M):
    ARR.append(list(map(int,input().split())))

def calculate(h, w, m, arr):
    srr = np.zeros((h, w))

    for i in range(m):
        c0 = arr[i][0] - 1
        c1 = arr[i][1] - 1
        srr[c0][c1] = 1

    res0 = np.sum(srr, axis=0)
    res1 = np.sum(srr, axis=1)

    res0Max = np.max(res0)
    res1Max = np.max(res1)
    res0MaxIndex = np.argwhere(res0 == res0Max)
    res1MaxIndex = np.argwhere(res1 == res1Max)

    result = 0

    for mH in res1MaxIndex:
        for mW in res0MaxIndex:
            result = max(result,res0Max + res1Max - srr[mH[0]][mW[0]])

    print(int(result))

calculate(H, W, M, ARR)

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = []
for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP.append((hh - 1, ww - 1))

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

print(DP)
print(hhh, www)
print(hhhh, wwww)
for i in hhhh:
    for j in wwww:
        if (i, j) not in DP:
            check = 1
            break
print(hhh + www - (1 - check))

Submission status: Runtime Error

Solution code:
import numpy as np

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

hhh = max(h)
www = max(w)
hhhh = []
wwww = []
for i in range(H):
    if h[i] == hhh:
        hhhh.append(i)
for i in range(W):
    if w[i] == www:
        wwww.append(i)
check = 0

for i in hhhh:
    for j in wwww:
        if DP[i][j] == 0:
            check = 1
            break
print(hhh + www - (1 - check))

Submission status: Runtime Error

Solution code:
import numpy as np

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

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

for i in hhhh:
    for j in wwww:
        if DP[i][j] == 0:
            check = 1
            break
print(hhh + www - (1 - check))

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = np.zeros((H+10, W+10))

for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP[hh - 1][ww - 1] = 1

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0


print(hhh + www - (1 - check))

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = np.zeros((H+10, W+10))

for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP[hh - 1][ww - 1] = 1

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

for i in hhhh:
    for j in wwww:
        if DP[i][j] == 0:
            check = 1
            break
print(hhh + www - (1 - check))

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = np.zeros((H, W))

for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP[hh - 1][ww - 1] = 1

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

for i in hhhh:
    for j in wwww:
        if DP[i][j] == 0:
            check = 1
            break
print(hhh + www - (1 - check))

Submission status: Runtime Error

Solution code:
hwm = list(map(int, input().split()))
H, W, M = hwm[0], hwm[1], hwm[2]
ls1 = [[0]*W for _ in range(H)]
ls2 = [[0]*H for _ in range(W)]
hls = []
wls = []
for m in range(M):
  ls = list(map(int, input().split()))
  ls1[ls[0]-1][ls[1]-1] = 1
  ls2[ls[1]-1][ls[0]-1] = 1
for h in range(H):
  hls.append(sum(ls1[h]))
for w in range(W):
  wls.append(sum(ls2[w]))
maxbomb = 0
for h in range(H):
  for w in range(W):
    if ls1[h][w] == 0:
      sumbomb = hls[h] + wls[w]
    else:
      sumbomb = hls[h] + wls[w] - 1
    if maxbomb < sumbomb:
      maxbomb = sumbomb
print(maxbomb)

Submission status: Runtime Error

Solution code:
hwm = list(map(int, input().split()))
H, W, M = hwm[0], hwm[1], hwm[2]
ls1 = [[0]*W for _ in range(H)]
ls2 = [[0]*H for _ in range(W)]
hls = []
wls = []
for m in range(M):
  ls = list(map(int, input().split()))
  ls1[ls[0]-1][ls[1]-1] = 1
  ls2[ls[1]-1][ls[0]-1] = 1
for h in range(H):
  hls.append(sum(ls1[h]))
for w in range(W):
  wls.append(sum(ls2[w]))
max = 0
for h in range(H):
  for w in range(W):
    if ls1[h][w] == 0:
      sumbomb = hls[h] + wls[w]
    else:
      sumbomb = hls[h] + wls[w] - 1
    if max < sumbomb:
      max = sumbomb
print(max)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
targets_map = [[0]*w for _ in range(h)]
targets_count_tate = [0]*w
targets_count_yoko = [0]*h
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_tate[x] += 1
    targets_count_yoko[y] += 1
    targets_map[y][x] = -1

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, targets_count_tate[x] + targets_count_yoko[y] + targets_map[y][x])

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
h, w, m = map(int, input().split())
targets_map = [[0]*w for _ in range(h)]
targets_count_tate = [0]*w
targets_count_yoko = [0]*h
for _ in range(m):
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    targets_count_tate[x] += 1
    targets_count_yoko[y] += 1
    targets_map[y][x] = 1


max_line = max(targets_count_yoko)
max_row = max(targets_count_tate)
yoko_idx = []
tate_idx = []
for i in range(h):
    if targets_count_yoko[i] == max_line:
        yoko_idx.append(i)
for i in range(w):
    if targets_count_tate[i] == max_row:
        tate_idx.append(i)

ans = max_line + max_row - 1
flag = True
for y in yoko_idx:
    for x in tate_idx:
        if targets_map[y][x] != 1:
            flag = False
            break
    else:
        continue
    break

if flag:
    print(ans)
else:
    print(ans+1)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()


from collections import deque
h, w = map(int, input().split())
a, b = map(int, input().split())
c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = [list(input()) for i in range(h)]
now = 0
dd = [(-1, 0), (1, 0), (0, 1), (0, -1)]

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            de = deque([(i, j)])
            s[i][j] = now
            while de:
                x, y = de.popleft()
                for p, q in dd:
                    if 0 <= x + p < h and 0 <= y + q < w and s[x + p][y + q] == ".":
                        s[x + p][y + q] = now
                        de.append((x + p, y + q))
            now += 1
st = s[a][b]
en = s[c][d]
es = [set() for i in range(now)]
for i in range(h):
    for j in range(w):
        if s[i][j] != "#":
            for p in range(-2, 3):
                for q in range(-2, 3):
                    if 0 <= i + p < h and 0 <= j + q < w and s[i + p][j + q] != "#":
                        es[s[i][j]].add(s[i + p][j + q])
                        es[s[i + p][j + q]].add(s[i][j])
from heapq import heappush, heapify, heappop


def dijkstra(s):
    INF = 1 << 32
    d = [INF] * now  # 頂点sからの最短距離
    v = -1
    que = [(0, s)]
    heapify(que)
    d[s] = 0
    while que:
        p = heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for e in es[v]:
            if d[e] > d[v] + 1:
                d[e] = d[v] + 1
                heappush(que, (d[e], e))
    return d[en] if d[en] < INF else -1


print(dijkstra(st))

Submission status: Runtime Error

Solution code:
2 3 3
2 2
1 1
1 3

Submission status: Runtime Error

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

for i in range(m):
    hb[hw[i][0]-1] += 1
    wb[hw[i][1]-1] += 1
    M[hw[i][0]-1][hw[i][1]-1] = -1

max_h = max(hb)
max_w = max(wb)
ans = max_h + max_w

max_h_list = []
for i in range(h):
    if hb[i] == max_h:
        max_h_list.append(i)
max_w_list = []
for i in range(h):
    if wb[i] == max_w:
        max_w_list.append(i)

count = 0
flg = 0
for i in range(len(max_h_list)):
    for j in range(len(max_w_list)):
        if M[max_h_list[i]][max_w_list[j]] == -1:
            count += 1
        else:
            flg = 1
            break
    if flg == 1:
        break
if count == len(max_h_list) * len(max_w_list):
    ans -= 1

print(ans)

Submission status: Runtime Error

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

for i in range(m):
    hb[hw[i][0]-1] += 1
    wb[hw[i][1]-1] += 1
    M[hw[i][0]-1][hw[i][1]-1] = -1

max_h = max(hb)
max_w = max(wb)
ans = max_h + max_w

max_h_list = []
for i in range(h):
    if hb[i] == max_h:
        max_h_list.append(i)
max_w_list = []
for i in range(h):
    if wb[i] == max_w:
        max_w_list.append(i)

count = 0
for i in range(len(max_h_list)):
    for j in range(len(max_w_list)):
        if M[max_h_list[i]][max_w_list[j]] == 0:
            break
        else:
            count += 1
            if count >= m or(i == len(max_h_list)-1 and j == len(max_w_list)-1):
                ans -= 1
                break

print(ans)

Submission status: Runtime Error

Solution code:
import copy

line1 = input()
aryLine1 = line1.split()
H = int(aryLine1[0]);
W = int(aryLine1[1]);
M = int(aryLine1[2]);

bomb = [[0 for j in range(W)] for i in range(H)]

#print(bomb)
hbomb = [0] * H
wbomb = [0] * W

maxhbomb = 0
maxwbomb = 0

for i in range(0, M):
    line = input()
    aryLine = line.split()
    h = int(aryLine[0]);
    w = int(aryLine[1]);
    bomb[h-1][w-1] = 1
    hbomb[h-1] = hbomb[h-1] + 1
    wbomb[w-1] = wbomb[w-1] + 1
    if hbomb[h-1] > maxhbomb:
        maxhbomb = hbomb[h-1]
    if wbomb[h-1] > maxwbomb:
        maxwbomb = wbomb[h-1]

#print("maxhbomb", maxhbomb)
#print("maxwbomb", maxwbomb)

ans = maxhbomb + maxwbomb - 1

for i in range(0, H):
    if hbomb[i] != maxhbomb:
        continue
    for j in range(0, W):
        if wbomb[j] != maxwbomb:
            continue
        if bomb[i][j] == 0:
            ans = ans + 1
            break
    if ans == maxhbomb + maxwbomb + 1:
        break

print(ans)

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
row = [0]*H
column = [0]*W
dp = [0]*(H*W)

for _ in range(M):
  h, w = map(int, input().split())
  row[h-1] += 1
  column[w-1] += 1
  dp[(h-1)*H + (w-1)] += 1
max_row = max(row)
max_column = max(column)
max_row_index = [i for i, x in enumerate(row) if x == max_row]
max_column_index = [i for i, x in enumerate(column) if x == max_column]
ans = 0
for i in max_row_index:
  for j in max_column_index:
    ans = max(ans, max_row + max_column -dp[i*H+j])
print(ans)

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
list1 =[[0] * h for i in range(w)]
list=[]
for i in range(m):
  list.append(input().split())
  for t in range(len(list[i])):
    list[i][t]=int(list[i][t])-1
  u=list[i][0]
  list[i][0]=list[i][1]
  list[i][1]=u
for y in range(m):
  for i in range(h):
    list1[list[y][0]][i]+=1
  for t in range(w):
    list1[t][list[y][1]]+=1
  list1[list[y][0]][list[y][1]]-=1
val1=max(list1)
ind1=list1.index(val1)
val2=max(list1[ind1])
print(val2)

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
row = [0]*H
column = [0]*W
dp = [[0]*W for _ in range(H)]

for _ in range(M):
  h, w = map(int, input().split())
  row[h-1] += 1
  column[w-1] += 1
  dp[h-1][w-1] += 1
max_row = max(row)
max_column = max(column)
max_row_index = [i for i, x in enumerate(row) if x == max_row]
max_column_index = [i for i, x in enumerate(column) if x == max_column]
ans = 0
for i in max_row_index:
  for j in max_column_index:
    ans = max(ans, max_row + max_column -dp[i][j])
print(ans)

Submission status: Runtime Error

Solution code:
import collections

a = list(map(int,input().split()))
c = []
d = []
for i in range(a[2]):
    b = list(map(int,input().split()))
    c.append(b[0])
    d.append(b[1])

ans1 = 0
ans2 = 0

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

ans1 += gc
ans2 += hc

for i in range(a[0]):
    if c[i] == g:
        c[i] = -1
    if d[i] == h:
        d[i] = -1    

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

if g == '-1':
    if gc == h:
        gc = 0
    else:
        g = e.most_common()[1][0]
        gc = e.most_common()[1][1]
if h == '-1':
    if hc == h:
        hc = 0
    else:
        h = f.most_common()[1][0]
        hc = f.most_common()[1][1]

ans1 += gc
ans2 += hc

if ans1 > ans2:
    print(str(ans1))
else:
    print(str(ans2))

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
bombs = []
rows = [[]for _ in range(H)]
cols = [[]for _ in range(W)]
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    bombs.append((h, w))
    rows[h].append(w)
    cols[w].append(h)

max_row = 0
for i, row in enumerate(rows):
    if max_row < len(row):
        max_row = len(row)
        row_idx = {i}
        continue
    elif max_row == len(row):
        row_idx.add(i)

max_col = 0
for i, col in enumerate(cols):
    if max_col < len(col):
        max_col = len(col)
        col_idx = {i}
        continue
    elif max_col == len(col):
        col_idx.add(i)

ans = max_row+max_col
points = len(row_idx)*len(col_idx)
if M < points:
    print(ans)
else:
    for i, j in bombs:
        if i in row_idx and j in col_idx:
            points -= 1
    if points == 0:
        print(ans-1)
    else:
        print(ans)

Submission status: Runtime Error

Solution code:
import collections

a = list(map(int,input().split()))
c = []
d = []
for i in range(a[2]):
    b = list(map(int,input().split()))
    c.append(b[0])
    d.append(b[1])

ans1 = 0
ans2 = 0

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

ans1 += gc
ans2 += hc

for i in range(a[0]):
    if c[i] == g:
        c[i] = -1
    if d[i] == h:
        d[i] = -1    

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

if g == '-1':
    g = e.most_common()[1][0]
    gc = e.most_common()[1][1]
if h == '-1':
    h = f.most_common()[1][0]
    hc = f.most_common()[1][1]

ans1 += gc
ans2 += hc

if ans1 > ans2:
    print(str(ans1))
else:
    print(str(ans2))

Submission status: Runtime Error

Solution code:
import collections

a = list(map(int,input().split()))
c = []
d = []
for i in range(a[2]):
    b = list(map(int,input().split()))
    c.append(b[0])
    d.append(b[1])

ans1 = 0
ans2 = 0

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

ans1 += gc
ans2 += hc

for i in range(a[0]):
    if g[i] == g:
        h[i] = -1
    if h[i] == h:
        g[i] = -1    

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

if g == '-1':
    g = e.most_common()[1][0]
    gc = e.most_common()[1][1]
if h == '-1':
    h = f.most_common()[1][0]
    hc = f.most_common()[1][1]

ans1 += gc
ans2 += hc

if ans1 > ans2:
    print(str(ans1))
else:
    print(str(ans2))

Submission status: Runtime Error

Solution code:
import collections
H,W,M=map(int,input().split())
hh=[]
ww=[]
cord=[]
for i in range(M):
    h,w=map(int,input().split())
    hh.append(h)
    ww.append(w)
    cord.append([h,w])

cch=collections.Counter(hh)
ccw=collections.Counter(ww)

countinglisth=cch.most_common()
countinglistw=ccw.most_common()

naxh=countinglisth[0][1]
naxw=countinglistw[0][1]

for i in range(len(countinglisth)):
    for j in range(len(countinglisth)):
        if countinglisth[i][1]==naxh and countinglistw[j][1]==naxw:
            temp=[countinglisth[i][0],countinglistw[j][0]]
            if not( temp in cord):
                print(naxh+naxw)
                exit()
print(naxh+naxw-1)

Submission status: Runtime Error

Solution code:
from collections import Counter
import numpy as np

h, w, m = map(int, input().split())
bomb_list = []
bomb_cnt = 0

for i in range(m):
    bomb_list.append(list(map(int, input().split())))

freq = Counter(np.array(bomb_list).T[0]).most_common()[0][0]

bomb_list = [i for i in bomb_list if i[0] != freq]

freq = Counter(np.array(bomb_list).T[1]).most_common()[0][0]

bomb_list = [i for i in bomb_list if i[1] != freq]

print(m - len(bomb_list))

Submission status: Runtime Error

Solution code:
from collections import Counter
import numpy as np


h, w, m = map(int, input().split())
bomb_list = []
bomb_cnt = 0

for i in range(m):
    bomb_list.append(list(map(int, input().split())))

freq = Counter(np.array(bomb_list).T[0]).most_common()[0][0]

bomb_list = [i for i in bomb_list if i[0] != freq]

freq = Counter(np.array(bomb_list).T[1]).most_common()[0][0]

bomb_list = [i for i in bomb_list if i[1] != freq]

print(m - len(bomb_list))

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = 5, 5, 10
ARR = [
    [2, 5],
    [4, 3],
    [2, 3],
    [5, 5],
    [2, 2],
    [5, 4],
    [5, 3],
    [5, 1],
    [3, 5],
    [1, 4]
]

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


# H, W, M = 2, 3, 3
# ARR = [
#     [2, 2],
#     [1, 1],
#     [1, 3]
# ]


def calculate(h, w, m, arr):
    srr = np.zeros((h,w))

    for ar in arr:
        h = ar[0] - 1
        w = ar[1] - 1
        srr[h][w] = 1

    res1 = np.sum(srr, axis=1)

    largestHIndex = np.argmax(res1)

    res2 = np.sum(srr, axis=0)
    trr = res2 - srr[largestHIndex]

    largestWIndex = np.argmax(trr)
    print(int(trr[largestWIndex] + res1[largestHIndex]))

calculate(H, W, M, ARR)

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
h = [0] * (H + 1)
w = [0] * (W + 1)
bombs = [[] for i in range(H + 1)]
hmax = 0
wmax = 0
hsrch = []
wsrch = []
for i in range(M):
    x, y = map(int, input().split())
    h[x] += 1
    if h[x] > hmax:
        hmax = h[x]
        hsrch = [x]
    elif h[x] == hmax:
        hsrch.append(x)

    w[y] += 1
    if w[y] > wmax:
        wmax = w[y]
        wsrch = [y]
    elif w[x] == wmax:
        wsrch.append(y)
        
    bombs[x].append(y)

ans = 0
max = 0
for x in hsrch:
    for y in wsrch: 
        ans = h[x] + w[y]
        if ans > max:
            max = ans - 1 if y in bombs[x] else ans

print(max)

Submission status: Runtime Error

Solution code:
from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1

counth = deque(counth)
countw = deque(countw)

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)

if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  B = bomb.popleft()
  K = kouho.popleft()
  while True:
    if B > K:
      ans += 1
      break
    elif B == K:
      if len(kouho) == 0:
        break
      else:
        K = kouho.popleft()
    else:
      if len(bomb) == 0:
        ans += 1
        break
      else:
        B = bomb.popleft()
print(ans)

Submission status: Runtime Error

Solution code:
def solve():
  H, W, M = map(int, input().split())
  bomb = [[0]*W for _ in range(H)]
  lis_h = [0]*H
  lis_w = [0]*W
  for _ in range(M):
    h,w = map(int, input().split())
    h -= 1
    w -= 1
    bomb[h][w] = 1
    lis_h[h] += 1
    lis_w[w] += 1
  m_h = max(lis_h)
  m_w = max(lis_w)
  m_h_lis = []
  m_w_lis = []
  for i in range(H):
    if lis_h[i]==m_h:
      m_h_lis.append(i)
  for i in range(W):
    if lis_w[i]==m_w:
      m_w_lis.append(i)
  ans = 0
  for h in m_h_lis:
    for w in m_w_lis:
      if bomb[h][w]==0:
        return m_h+m_w
  return m_h+m_w-1
print(solve())

Submission status: Runtime Error

Solution code:
from collections import deque
H, W, M = map(int, input().split())
grid = [[0 for _ in range(W)] for _ in range(H)]
counth = deque([0 for k in range(H)])
countw = deque([0 for k in range(W)])
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  grid[h][w] = 1
  counth[h] += 1 
  countw[w] += 1

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = deque([])
k = 0
while k < H:
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
  k += 1
k = 0
while k < W:
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)
  k += 1
ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)
if lenh*lenw > M:
  ans += 1
else:  
  for _ in range(lenh)
    h = index_h.pop()
    for _ in range(lenw):
      w = index_w.pop()
      if grid[h][w] == 0:
        ans += 1
        break
    else:
      continue
    break
print(ans)

Submission status: Runtime Error

Solution code:
h,w,m = list(map(int,input().split()))
bomb = [[0]*w for _ in range(h)]
place = [None]*m
for i in range(m):
    x,y = list(map(int,input().split()))
    x -= 1; y -= 1
    bomb[x][y] = 1
    place[i] = [x,y]

hsum = [sum(i) for i in bomb]
wsum = [sum([bomb[j][i] for j in range(h)]) for i in range(w)]
hmax = max(hsum); wmax = max(wsum); ans = hmax+wmax

hsearch = set(); wsearch = set()
for i in range(m):
    x,y = place[i]
    if hsum[x] == hmax: hsearch.add(x)
    if wsum[y] == wmax: wsearch.add(y)

if m < len(hsearch)*len(wsearch):
    flag = True
else:
    search_table = [[True if i in hsearch and j in wsearch else False for j in range(w)] for i in range(h)]
    for i in range(m):
        x,y = place[i]
        search_table[x][y] = False

    flags = [True if sum(i)>0 else False for i in search_table]
    flag = any(flags)

print(ans if flag else ans-1)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,M = map(int,input().split())
stage = np.zeros((H,W),dtype=np.int32)
for m in range(M):
    h,w = map(int,input().split())
    stage[h-1,w-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(ans)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
HW = [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)]

# print(h,w,m)
HW.sort()
# print(*HW,sep='\n')
# print('---')

sum_h = [[0,0] for _ in range(h)] # [sum, index]
sum_w = [[0,0] for _ in range(w)]


for i in range(m):
    # print(h,w)
    h,w = HW[i]
    sum_h[h][0] += 1
    sum_w[w][0] += 1
    sum_h[h][1] = h
    sum_w[w][1] = w

# # print('---')
# # print(sum_h)
# # print(sum_w)
# # print('---')
sum_h.sort(reverse=True)
sum_w.sort(reverse=True)
# print(sum_h)
# print(sum_w)
# print('---')

from bisect import *

# print(HW)

max_bombs = 0
if sum_h[0][0] > sum_w[0][0]:
    h_bombs, h_index = sum_h[0]
    for w_bombs, w_index in sum_w:
        bombs = h_bombs + w_bombs
        ix = bisect_left(HW, [h_index, w_index])
        # print('ix {}'.format(ix))
        # if [h_index, w_index] in HW:
        if [h_index, w_index] ==  HW[ix]:
            bombs -= 1
        if max_bombs < bombs:
            max_bombs = bombs

else:
    for h_bombs, h_index in sum_h:
        bombs = sum_w[0][0] + h_bombs
        if [h_index, sum_w[0][1]] in HW:
            bombs -= 1
        if max_bombs < bombs:
            max_bombs = bombs

print(max_bombs)

Submission status: Runtime Error

Solution code:
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

    hlst=[(0,i) for i in range(h)]    
    wlst=[(0,i) for i in range(w)]
    dic={}
    for i in range(m):
        hh,ww=hw[i]
        hlst[hh-1][0]-=1
        wlst[ww-1][0]-=1
        dic[(hh-1,ww-1)]=1

    hlst.sort()
    wlst.sort()
    hkouho=[]
    wkouho=[]
    mi=0
    for i in range(h):
        if mi<hlst[i][0]:
            break
        hkouho.append(hlst[i][1])
        mi=hlst[i][0]
    mi=0
    for i in range(w):
        if mi<wlst[i][0]:
            break
        wkouho.append(wlst[i][1])
        mi=wlst[i][0]
    # print(hkouho)
    # print(wkouho)
    # print(hlst)
    for i in range(len(hkouho)):
        for j in range(len(wkouho)):
            if not (hkouho[i],wkouho[j]) in dic:
                print(-hlst[0][0]-wlst[0][0])
                exit()
    print(-hlst[0][0]-wlst[0][0]-1)
    # print(hkouho[0],wkouho[0])
main()

Submission status: Runtime Error

Solution code:
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))
 
maxh=max(sumh)
maxw=max(sumw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==len(qh)*len(qw):
  print(maxh+maxw-1)
else:
  print(maxh+maxw)