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:
def main():
    import collections
    import numpy as np

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

    zahyou = [[0 for i in range(W)] for j in range(H)]
    zahyou_H = [0 for i in range(H)]
    zahyou_W = [0 for i in range(W)]

    np_zahyou = np.array(zahyou)
    np_zahyou_H = np.array(zahyou_H)
    np_zahyou_W = np.array(zahyou_W)
    

    for i in range(M_ko):
        height, width = map(int, input().split())

        zahyou[height - 1][width - 1] = 1
        
        zahyou_H[height - 1] += 1
        zahyou_W[width - 1] += 1

    CTR_H = collections.Counter(zahyou_H)
    CTR_W = collections.Counter(zahyou_W)

    max_h = max(zahyou_H)
    max_w = max(zahyou_W)

    len_h = CTR_H[max_h]
    len_w = CTR_W[max_w]

    index_h = [i for i, x in enumerate(zahyou_H) if x == max_h]
    index_w = [i for i, x in enumerate(zahyou_W) if x == max_w]


    maxi = max_h + max_w
    FLAG = False


    if (len_h == 1 and len_w == 1):    
        maxi -= zahyou[index_h[0]][index_w[0]]


    else:
        for i in range(len_h):        
            for j in range(len_w):
                val = zahyou[index_h[i]][index_w[j]]
                
                if (val == 0):
                    FLAG = True
                    break
        
        if (not FLAG):
            maxi -= 1

    print(maxi)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

h,w,m= map(int,input().split())
a=[0]*h
b=[0]*w
ab=[[0]*w for i in range(h)]

for i in range(m):
    hh,ww= map(int,input().split())
    a[hh-1]+=1
    b[ww-1]+=1
    ab[hh-1][ww-1]+=1
    
mm=0
aa=[]
for i in range(h):
    if a[i]>mm:
        aa=[i]
        mm=a[i]
    elif a[i]==mm:
        aa.append(i)

mmm=0
bb=[]
for i in range(w):
    if b[i]>mmm:
        bb=[i]
        mmm=b[i]
    elif b[i]==mmm:
        bb.append(i)        

ans=False
for i in aa:
    for j in bb:
        if ab[i][j]==0:
            ans=True
if ans:
    print(mm+mmm)
else:
    print(mm+mmm-1)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

Bom = np.asarray(boms)

h_max = np.argmax(np.bincount(Bom[:, 0]))
ind_h = np.where(Bom[:, 0] == h_max)
Bom_h = np.delete(Bom, ind_h, 0)
#print(Bom_h)
w_max = np.argmax(np.bincount(Bom_h[:, 1]))
ind_w = np.where(Bom_h[:, 1] == w_max)

print(len(ind_h[0])+len(ind_w[0]))

Submission status: Runtime Error

Solution code:

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

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

flag=True
for i in tbox:
    for j in ybox:
        if box[i][j]==0:
            flag=False

if flag:
    print(tmax+ymax-1)
else:
    print(tmax + ymax)

Submission status: Runtime Error

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


h, w, m = inpl()
dic1 = [0] * h
dic2 = [0] * w
mine = [[0] * w for _ in range(h)]
for _ in range(m):
    y, x = inpl()
    dic1[y - 1] += 1
    dic2[x - 1] += 1
    mine[y - 1][x - 1] = 1

sub1 = []
tmp = -1
for i in range(h):
    if tmp < dic1[i]:
        sub1 = [i]
        tmp = dic1[i]
    elif tmp == dic1[i]:
        sub1.append(i)
temp = -1
sub2 = []
for i in range(w):
    if temp < dic2[i]:
        sub2 = [i]
        temp = dic2[i]
    elif temp == dic2[i]:
        sub2.append(i)
exit()
ans = -1
FLAG = False
for i in sub1:
    for j in sub2:
        if mine[i][j] == 0:
            ans = 0
            FLAG = True
            break
    if FLAG:
        break
print(ans + tmp + temp)

Submission status: Runtime Error

Solution code:
import sys

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

hw = [[0] * (W+1) for _ in range(H+1)]

w = [0] * (W+1)
h = [0] * (H+1)


for i in range(M):
    h_i, w_j = list(map(int, input().split()))
    hw[h_i][w_j] = 1
    h[h_i] += 1
    w[w_j] += 1

a = 0
for i in [i for i, x in enumerate(h) if x == max(h)]:
    for j in [j for j, y in enumerate(w) if y == max(w)]:
        d = hw[i][j]
        a = max(a, h[i]+w[j]-d)
print(a)

Submission status: Runtime Error

Solution code:
def main():
    h, w, m = map(int, input().split())
    L = [list(map(int,input().split())) for _ in range(m)]
    table = [[0] * w for _ in range(h)]
    for a, b in L:
        table[a-1][b-1] = 1
    col = [0] * w
    row = [0] * h
    for i in range(w):
        col[i] = sum([T[i] for T in table])
    for j in range(h):
        row[j] = sum(table[j])
    mxCol = [i for i, v in enumerate(col) if v == max(col)]
    mxRow = [i for i, v in enumerate(row) if v == max(row)]
    ans = max(col) + max(row)
    for c in mxCol:
        for r in mxRow:
            if not table[r][c]:
                print(ans)
                return
    print(ans-1)
    
main()

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, list(input().split()))
hw = [list(map(int, list(input().split()))) for i in range(M)]
hw = np.array(hw) - 1

sh = [0] * H
sw = [0] * W
bomb = np.zeros((H, W), dtype=int)
for i in range(M):
    sh[hw[i, 0]] += 1
    sw[hw[i, 1]] += 1
    bomb[hw[i, 0], hw[i, 1]] = 1

h_list = [i for i, x in enumerate(sh) if x == max(sh)]
w_list = [i for i, x in enumerate(sw) if x == max(sw)]
    
print(6)

Submission status: Runtime Error

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

for _ in range(m):
  i, j = map(int, input().split())
  graph[i-1][j-1] = 1
  
graph_t = list(zip(*graph))

max_row = 0
ri = []
for i in range(h):
  tmp = sum(graph[i])
  if tmp > max_row:
    max_row = tmp
    ri = [i]
  elif tmp == max_row:
    ri += [i]
max_col = 0
ci = []
for i in range(w):
  tmp = sum(graph_t[i])
  if tmp > max_col:
    max_col = tmp
    ci = [i]
  elif tmp == max_col:
    ci += [i]

result = max_row+max_col
for i in ri:
  for j in ci:
    if graph[i][j] == 0:
      print(result)
      exit()
print(result-1)

Submission status: Runtime Error

Solution code:

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

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

flag=True
for i in tbox:
    for j in ybox:
        if box[i][j]==0:
            flag=False

if flag:
    print(tmax+ymax-1)
else:
    print(tmax + ymax)

Submission status: Runtime Error

Solution code:
import pandas as pd
import numpy as np
import collections

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

count = 0

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

c_left = collections.Counter(left)

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

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

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

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

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, M = map(int, input().split())
m = np.zeros((H, W), dtype=int)

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

h_m = np.sum(m, axis=0)
w_m = np.sum(m, axis=1)
x = np.where(w_m == w_m.max())
y = np.where(h_m == h_m.max())
kumi = np.stack(np.meshgrid(x, y), -1).reshape(-1, 2)
saidai = 0
for a, b in kumi:
    s = 0
    if m[a, b] == 1:
        s  = h_m[b]+w_m[a]-1
    else:
        s = h_m[b]+w_m[a]
    if saidai < s:
        saidai = s
    else:
        continue
print(saidai)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
t = [[0 for i in range(w)] for j in range(h)]
Hs = [0] * m
Ws = [0] * m
for i in range(m):
  _h, _w = map(int, input().split())
  t[_h-1][_w-1] = 1
  Hs[_h - 1] += 1
  Ws[_w - 1] += 1
Hmax = max(Hs)
Hcount = Hs.count(Hmax)
Wmax = max(Ws)
Wcount = Ws.count(Wmax)
Hindexs = [0] * Hcount
Windexs = [0] * Wcount
hcount = 0
wcount = 0
for i in range(m):
  if Hs[i] == Hmax:
    Hindexs[hcount] = i
    hcount += 1
  if Ws[i] == Wmax:
    Windexs[wcount] = i
    wcount += 1
for hind in Hindexs:
  for wind in Windexs:
    if t[hind][wind] == 0:
      print(Hmax + Wmax)
      exit()
print(Hmax + Wmax - 1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w, m = LI()
cnt = [[0] * w for _ in range(h)]
cnt_h = [0] * h
cnt_w = [0] * w
for _ in range(m):
    H, W = LI()
    cnt[H-1][W-1] += 1
    cnt_h[H-1] += 1
    cnt_w[W-1] += 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, cnt_h[i] + cnt_w[j] - cnt[i][j])
print(ans)

Submission status: Runtime Error

Solution code:
def index_Multi(List,liter):
    #Listはリスト本体・literは検索したい文字
    index_L = []
    for val in range(0,len(List)):
        if liter == List[val]:
            index_L.append(val)
    return index_L
  
h,w,m = map(int, input().split(" "))
hb=[0 for i in range(h+1)]
wb=[0 for i in range(m+1)]
baku = [list(map(int, input().split(" "))) for i in range(m)]

#print(baku, hb)
for i in range(m):
  hb[baku[i][0]] +=1
  wb[baku[i][1]] += 1
maxh = index_Multi(hb, max(hb))
maxw = index_Multi(wb, max(wb))
ans = max(hb) + max(wb)
#print(hb, wb)
#print(maxh, maxw)
#print(baku)
check = False
for i in maxh:
  for j in maxw:
    #print(i, j)
    if [i, j] not in baku:
      check = True
  else:
    continue
print(ans) if check else print(ans - 1)

Submission status: Runtime Error

Solution code:
def main():
  h, w, m =  map(int, input().split())
  H = [0]*h
  W = [0]*w
  grid = [[0]*w for _ in range(h)]
  for i in range(m):
    a, b = map(int, input().split())
    H[a-1] += 1
    W[b-1] += 1
    grid[a-1][b-1] += 1
  h_max = max(H)
  w_max = max(W)
  h_sec = [i for i, x in enumerate(H) if x == h_max]
  w_sec = [i for i, x in enumerate(W) if x == w_max]
  ans = h_max + w_max
  flag = True
  for i in h_sec:
    for j in w_sec:
      if grid[i][j] == 0:
        flag = False
        break
    if not flag:
      break
  if flag:
    print(ans-1)
  else:
    print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, M = list(map(int, input().split()))
row = np.zeros(H)
col = np.zeros(W)
maps = np.zeros((H, W))
for i in range(M):
    h, w =list(map(int, input().split()))
    row[h-1] += 1
    col[w-1] += 1
    maps[h-1][w-1] = 1

rowMax = row.max()
colMax = col.max()
rowMaxs = np.where(row == rowMax)
colMaxs = np.where(col == colMax)
d = 1
for i in rowMaxs[0]:
    for j in colMaxs[0]:
        if maps[i][j] == 0:
            d = 0
            break
    if d == 0:
        break

print(int(rowMax + colMax - d))

Submission status: Runtime Error

Solution code:
from collections import Counter
x=0
H,W,M = map(int,input().split())
h = [0]*M
w = [0]*M
for i in range(0,M):
  h[i],w[i] = map(int,input().split())
a = Counter(h).most_common()
b = Counter(w).most_commom()
x = a[0][1]+b[0][1]
for i in range(0,M):
  if h[i],w[i] == a[0][0],b[0][0]:
    x = x-1
print(x)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

# 別変数の整数複数個
H, W, M = [int(x) for x in input().strip().split(" ")]

G = np.zeros((H, W), int)
for _ in range(M):
    h, w = [int(x) for x in input().strip().split(" ")]
    G[h-1][w-1] = 1


h_sums = np.sum(G, axis=1)
w_sums = np.sum(G, axis=0)
h_sum_max = max(h_sums)
w_sum_max = max(w_sums)

for h, hv in enumerate(h_sums):
    if hv != h_sum_max:
        continue
    for w, wv in enumerate(w_sums):
        if wv != w_sum_max:
            continue
        if G[h][w] == 0:
            print(h_sum_max + w_sum_max)
            import sys; sys.exit(0)
print(h_sum_max + w_sum_max - 1)

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 i in range(M):
    h,w = map(int, input().split())
    bomb[h-1][w-1] = 1
    lis_h[h-1] += 1
    lis_w[w-1] += 1
  ans = 0
  for h in range(H):
    for w in range(W):
      ans = max(ans, lis_h[h]+lis_w[w]-bomb[h][w])
  return ans
print(solve())

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
H, W, M = map(int, input().split())
d = np.zeros((H, W), dtype=int)
for _ in range(M):
    h, w = map(int, input().split())
    h, w = h-1, w-1
    d[h, w] = 1
tate = np.sum(d, axis=0)
yoko = np.sum(d, axis=1)
tate_max = tate.max()
yoko_max = yoko.max()

ans_tate, ans_yoko = [], []
for i in range(W):
    if tate[i] == tate_max:
        ans_tate.append(i)
for i in range(H):
    if yoko[i] == yoko_max:
        ans_yoko.append(i)

for h in ans_yoko:
    for w in ans_tate:
        if d[h, w] != 1:
            print(tate_max+yoko_max)
            sys.exit()
print(tate_max+yoko_max-1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

H_list = [0] * (H + 1)
W_list = [0] * (W + 1)


G = [[0] * (W + 1) for _ in range(H + 1)]


for _ in range(M):
    a, b = map(int, input().split())
    G[a][b] = 1
    H_list[a] += 1
    W_list[b] += 1

ans = 0
for h in range(1, H + 1):
    for w in range(1, W + 1):
        tmp = H_list[h] + W_list[w] - G[h][w]
        ans = max(ans, tmp)

print (ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
import numpy as np
from pprint import pprint

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

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

for i in range(m):
    grid[hw[i][1]-1][hw[i][0]-1] = 1


cnt_grid = []
for i in range(w):
    cnt_grid.append(Counter(grid[i]))


cnt_grid_h = 0
max_h = 0
for i in range(w):
    if cnt_grid_h < cnt_grid[i][1]:
        cnt_grid_h = cnt_grid[i][1]
        max_h = i
grid = np.rot90(grid)
grid = grid.tolist()
cnt_grid = []
for i in range(h):
    cnt_grid.append(Counter(grid[i]))

cnt_grid_w = 0
max_w = 0
for i in range(h):
    if cnt_grid_w < cnt_grid[i][1]:
        cnt_grid_w = cnt_grid[i][1]
        max_w = i
max_w = h - max_w - 1

if grid[max_h][max_w] == 1:
    print(cnt_grid_h + cnt_grid_w - 1)
else:
    print(cnt_grid_h + cnt_grid_w)

Submission status: Runtime Error

Solution code:
import time
from bisect import bisect_left
t = time.time()
H,W,m = map(int,input().split())
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1] for i in range(H+1)]
for i in range(m):
    a,b = map(int,input().split())
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in range(H+1):
    c[i].sort()
# print(hkouho)
# print(wkouho)
for i in hkouho:
    for j in wkouho:
        # print(i,j,bisect_left(c[i],j))
        if c[i][bisect_left(c[i],j)] != j:
        # if j not in c[i]:
            print(mh+mw)
            exit()
        if time.time()-t > 2.7:
            print(mh+mw-1)
            exit()
print(mh+mw-1)

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for _ in range(m)]
a=[0 for i in range(h+1)]
b=[0 for _ in range(w+1)]
for i in range(m):
    a[bomb[i][0]]+=1
    b[bomb[i][1]]+=1
am=max(a)
bm=max(b)
aa=[i for i, x in enumerate(a) if x==am]
bb=[i for i, x in enumerate(b) if x==bm]
for i in aa:
    for j in bb:
        if not [i,j] in set(bomb):
            continue
        else:
            print(am+bm)
            exit()
print(am+bm-1)

Submission status: Runtime Error

Solution code:
H,W,M = map(int,input().split())
L = [[0 for _ in range(W)] for _ in range(H)]
for i in range(M):
    h,w = map(int,input().split())
    L[h-1][w-1] += 1
y = 0
yy = 0
yl = []
t = 0
tt = 0
tl = []
for i in range(H):
    a = sum(L[i])
    if a > y:
        y = a
        yy = i
        yl = [i]
    elif a == y:
        yl.append(i)
R = list(zip(*L))
for i in range(W):
    b = sum(R[i])
    if b > t:
        t = b
        tt = i
        tl = [i]
    elif b == t:
        tl.append(i)
if len(yl) == 1 and len(tl) != 1:
    for i in range(len(tl)):
        if L[yy][tl[i]] == 0:
            tt = tl[i]
            break
elif len(tl) == 1 and len(yl) != 1:
    for i in range(len(yl)):
        if L[yl[i]][tt] == 0:
            yy = yl[i]
s = True
elif len(yl) != 1 and len(tl) != 1:
    for i in range(len(yl)):
        if s:
            for j in range(len(tl)):
                if L[yl[i]][tl[j]] == 0:
                    yy = yl[i]
                    tt = tl[j]
                    s = False
                    break
if L[yy][tt] == 1:
    print(y + t - 1)
else:
    print(y + t)

Submission status: Runtime Error

Solution code:
import time
from bisect import bisect_left
t = time.time()
H,W,m = map(int,input().split())
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1] for i in range(H+1)]
for i in range(m):
    a,b = map(int,input().split())
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in range(H+1):
    c[i].sort()
# print(hkouho)
# print(wkouho)
for i in hkouho:
    for j in wkouho:
        print(i,j,bisect_left(c[i],j))
        if c[i][bisect_left(c[i],j)] != j:
        # if j not in c[i]:
            print(mh+mw)
            exit()
        if time.time()-t > 2.7:
            print(mh+mw-1)
            exit()
print(mh+mw-1)

Submission status: Runtime Error

Solution code:
import numpy

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

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

for i,j in bomb:
    x[i-1][j-1] = 1


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

        for n in range(h):
            if x[n][j] == 1:
                temp += 1
        for m in range(w):
            if x[i][m] == 1:
                temp += 1
        if x[i][j] == 1:
            temp -= 1
        ans = max(ans,temp)
            
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

# 別変数の整数複数個
H, W, M = [int(x) for x in input().strip().split(" ")]

G = np.zeros((H, W), int)
for _ in range(M):
    h, w = [int(x) for x in input().strip().split(" ")]
    G[h-1][w-1] = 1


h_sums = np.sum(G, axis=1)
w_sums = np.sum(G, axis=0)
h_sum_max = max(h_sums)
w_sum_max = max(w_sums)

for h, hv in enumerate(h_sums):
    if hv != h_sum_max:
        continue
    for w, wv in enumerate(w_sums):
        if wb != w_sum_max:
            continue
        if G[h][w] == 0:
            print(h_sum_max + w_sum_max)
            import sys; sys.exit(0)
print(h_sum_max + w_sum_max - 1)

Submission status: Runtime Error

Solution code:
h,w,m=list(map(int,input().split()))
b=[]
r=[0]*(10**5+1)
c=[0]*(10**5+1)
for i in range(m):
    h,w=list(map(int,input().split()))
    r[h]=r[h]+1
    c[w]=c[w]+1
    b.append([h,w])
if max(r)>max(c):
    j=r.index(max(r))
    for i in range(len(b)):
        if b[i][0]==j:
            c[b[i][1]]=c[b[i][1]]-1
    i=c.index(max(c))
else:
    i=c.index(max(c))
    for j in range(len(b)):
        if b[j][1]==i:
            r[b[j][0]]=r[b[j][0]]-1
    j=r.index(max(r))
print(r[j]+c[i])

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,M = map(int,input().split())
data = [[0]*W for i in range(H)]
data = np.array(data)
for i in range(M):
    CH,CW = map(int,input().split())
    data[CH-1][CW-1] = 1

tate = np.sum(data, axis=0)
yoko = np.sum(data, axis=1)

for i in range(H):
    for k in range(W):
        if data[i][k] == 0:
            data[i][k] =  yoko[i] + tate[k]
        else:
            data[i][k] =  yoko[i] + tate[k] -1
print(np.max(data))

Submission status: Runtime Error

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

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 = np.array([[int(b) for b in input().split()] for l in range(M)])

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

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

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

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

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

print(int(answer))

Submission status: Runtime Error

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

h_max=0
arg_h=0
w_max=0
arg_w=0
bom_max=0
for _ in range(m):
  x,y=map(lambda x:int(x)-1, input().split())
  h_bom[x]+=1
  w_bom[y]+=1
  cord[x][y]=1
  
  bom_max=max(bom_max, h_bom[x]+w_bom[y]-cord[x][y])
  
  if h_bom[x]>h_max:
    arg_h=x
    h_max=h_bom[x]
  
  if w_bom[y]>w_max:
    arg_w=y
    w_max=w_bom[y]
    
for i in range(h):
  bom_max = max(bom_max, h_bom[i] + w_max - cord[i][arg_w])
for j in range(w):
  bom_max = max(bom_max, w_bom[j] + h_max - cord[arg_h][j])
  
print(bom_max)

Submission status: Runtime Error

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


h, w, m = inpl()
dic1 = [0] * h
dic2 = [0] * w
mine = [[0] * w for _ in range(h)]
for _ in range(m):
    y, x = inpl()
    dic1[y - 1] += 1
    dic2[x - 1] += 1
    mine[y - 1][x - 1] = 1

sub1 = []
tmp = -1
for i in range(h):
    if tmp < dic1[i]:
        sub1 = [i]
        tmp = dic1[i]
    elif tmp == dic1[i]:
        sub1.append(i)
temp = -1
sub2 = []
for i in range(w):
    if temp < dic2[i]:
        sub2 = [i]
        temp = dic2[i]
    elif temp == dic2[i]:
        sub2.append(i)
ans = -1
FLAG = False
for i in sub1:
    for j in sub2:
        if mine[i][j] == 0:
            ans = 0
            FLAG = True
            break
    if FLAG:
        break
print(ans + tmp + temp)

Submission status: Runtime Error

Solution code:
# cook your dish here
import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from time import clock
a=clock()
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(s, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if s[mid] == val:return mid
        elif s[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,s):
    for i in range(1,n):s[i]+=s[i-1]
    return s;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;
# code start from here-

r,w,m=iia()
arr = [[0]*w for i in range(r)]
for i in range(m):
    a,b=iia()
    a-=1
    b-=1
    arr[a][b]=1
# [print(arr[i])for i in range(r)]
# print('----')
rowsum=[[0]*w for i in range(r)]

for i in range(r):
    s=0
    for j in range(w):
        s+=arr[i][j]
    rowsum[i][-1]=s
# [print(rowsum[i])for i in range(r)]
# print('---')
colsum=[[0]*w for i in range(r)]
for i in range(w):
    s=0
    for j in range(r):
        s+=arr[j][i]
    colsum[-1][i]=s
# [print(colsum[i])for i in range(r)]
ans=0
for i in range(r):
    for j in range(w):
        ans=max(ans,rowsum[i][-1]+colsum[-1][j]-arr[i][j])
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, M = map(int, input().split())
hw = np.zeros((H,W))
for i in range(M):
  j, k = map(int, input().split())
  hw[j-1][k-1] = 1
#print(hw)
w_line, h_line = [], []
h_line = np.sum(hw, axis=0)
w_line = np.sum(hw, axis=1)

#print(h_line)
#print(w_line)

h_max_idx = np.where(h_line == np.max(h_line))
w_max_idx = np.where(w_line == np.max(w_line))
#print(h_max_idx)
#print(w_max_idx)

ans = 0
for i in range(len(h_max_idx[0])):
  for j in range(len(w_max_idx[0])):
    h_idx = h_max_idx[0][i]
    w_idx = w_max_idx[0][j]
    #print(h_idx, w_idx)
    tmp = h_line[h_idx] + w_line[w_idx]
    if hw[w_idx][h_idx] == 1:
      tmp -= 1
    ans = max(ans, tmp)
"""    
for i in range(len(w_max_idx[0])):
  for j in range(len(h_max_idx[0])):
    w_idx = w_max_idx[0][i]
    h_idx = h_max_idx[0][j]
    tmp = w_line[w_idx] + h_line[h_idx]
    print(h_idx, w_idx)
    if hw[h_idx][w_idx] == 1:
      tmp -= 1
    ans = max(ans, tmp)
"""
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m=map(int,input().split())
data=np.zeros((h,w))
for i in range(m):
    x,y=map(int,input().split())
    data[x-1][y-1]+=1
ans=0
print(0)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
hlist = [0] * h
wlist = [0] * w
hwlist = [[0] * w for i in [1] * h]
for i in range(m):
    hi, wi = map(int, input().split())
    hlist[hi - 1] += 1
    wlist[wi - 1] += 1
    hwlist[hi - 1][wi - 1] = 1
maxh = max(hlist)
maxw = max(wlist)

hindex_num = [n for n, v in enumerate(hlist) if v == maxh]
windex_num = [n for n, v in enumerate(wlist) if v == maxw]

flag = 0
for hi in hindex_num:
    for wi in windex_num:
        if hwlist[hi][wi] == 0:
            print(maxh + maxw)
            flag = 1

if flag == 0:
    print(maxh + maxw - 1)

Submission status: Runtime Error

Solution code:
H, W, M = map(int,input().rstrip().split())
l = [[0 for i in range(H)] for j in range(W)]
r = [0]*H
c = [0]*W
max_r = 0
max_c = 0
r_i = []
c_j = []
for i in range(M):
    h, w = map(int,input().rstrip().split())
    l[w-1][h-1] = 1
    r[h-1] += 1
    if r[h-1]>max_r:
        max_r = r[h-1]
        r_i = [h-1]
    elif r[h-1]==max_r:
        r_i.append(h-1)
    c[w-1] += 1
    if c[w-1]>max_c:
        max_c = c[w-1]
        c_j = [w-1]
    elif c[h-1]==max_c:
        c_j.append(w-1)
ans = max_r+max_c-1
for i in r_i:
    for j in c_j:
        if l[j][i] == 0:
            ans = max_r+max_c
            break
    else:
        continue
    break
print(ans)

Submission status: Runtime Error

Solution code:
H,W,M = map(int,input().split())
h = []
w = []

for i in range(M):
    tmp1,tmp2 = map(int,input().split())
    h.append(tmp1)
    w.append(tmp2)

dic1 = {}
dic2 = {}

for i in h:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1

val1 = max(dic1,key=dic1.get)
ans = 0
ans +=dic1[val1]
for j in range(M):
    if h[j] != val1:
        if w[j] not in dic2:
            dic2[w[j]] = 1
        else:
            dic2[w[j]] +=1

val2 = max(dic2,key=dic2.get)
ans +=dic2[val2]
print(ans)

Submission status: Runtime Error

Solution code:
import math
import collections

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

c_x = collections.Counter(x)
c_y = collections.Counter(y)
_max_x = c_x.most_common()[0][1]
_max_y = c_y.most_common()[0][1]
ys = c_y.most_common()
count = _max_x + _max_y - 1

for x, x_num in c_x.most_common():
  if x_num != _max_x:
    break
  for y, y_num in ys:
    if y_num != _max_y:
      break
    else:
      if bomb[x][y] == 0:
        count += 1
        break
        
print(count)