Problem:


Score : 500 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq h_i \leq H

1 \leq w_i \leq W

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

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

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

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

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

Sample Output 3

6



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


Sample output:
3

Submission status: Runtime Error

Solution code:
h, w, m = (int(x) for x in input().split())
bomb = [[0]*w for i in range(h)]
bomb_h = [0]*h
bomb_w = [0]*w
for i in range(m):
    hm, wm = (int(x) for x in input().split())
    hm-=1
    wm-=1
    bomb[hm][wm] = 1
    bomb_h[hm]+=1
    bomb_w[wm]+=1
h_kouho = []
w_kouho = []
h_max = max(bomb_h)
w_max = max(bomb_w)
for i in range(h):
    if bomb_h[i]==h_max:
        h_kouho.append(i)
for i in range(w):
    if bomb_w[i]==w_max:
        w_kouho.append(i)
boo = False
for i in h_kouho:
    for j in w_kouho:
        if bomb[i][j]==0:
            break
            boo=True
    else:
        continue
    break
if boo:
    print(h_max+w_max)
else:
    print(h_max+w_max-1)

Submission status: Runtime Error

Solution code:
# [] = list(map(int, input().split()))

import numpy as np

[h, w, m] = list(map(int, input().split()))
hwList = []
for rr in range(m):
    hwList.append(list(map(int, input().split())))

field = np.zeros((h, w), dtype=int)
for ww in hwList:
    field[ww[0] - 1][ww[1] - 1] = 1


def ranges(c):
    i = 0
    while True:
        while i < len(c) and c[i] == "W":
            i += 1
        if i == len(c):
            return
        start = i
        enemies = 0
        while i < len(c) and c[i] != "W":
            if c[i] == 1:
                enemies += 1
            i += 1
        yield range(start, i), enemies


def enemies(c):
    answer = [0] * len(c)
    for r, enemies in ranges(c):
        for i in r:
            answer[i] = enemies
    return answer


def best(grid):
    rows = [enemies(c) for c in grid]
    cols = [enemies(c) for c in zip(*grid)]
    maxi = 0
    mi = 0
    mj = 0
    for i in range(len(grid)):
        for j in range(len(grid[0])):
            temp = rows[i][j] + cols[j][i] if grid[i][j] == 0 else rows[i][j] + cols[j][i] - 1
            if temp > maxi:
                mi = i
                mj = j
                maxi = temp
    return maxi, mi, mj

count = 0
# for i in range(m):
#     [m2, i, j] = list(best(field))
#     for o in field:
#         o[j] = 0
#     for p in range(w):
#         field[i][p] = 0
#     count+=m2


[m2, i, j] = list(best(field))
for o in field:
    o[j] = 0
for p in range(w):
    field[i][p] = 0

print(m2)

Submission status: Runtime Error

Solution code:
import random
import itertools
import sys
def input():
    return sys.stdin.readline()[:-1]
  
H, W, M = map(int, input().split())
Hsum = [0] * H
Wsum = [0] * W
hw = []
for m in range(M):
  h, w = map(int, input().split())
  #h = random.randint(0, H)
  #w = random.randint(0, W)
  Hsum[h-1] += 1
  Wsum[w-1] += 1
  hw.append(str(h-1)+"_"+str(w-1))

hmax_ind = list(map(lambda x: True if x == max(Hsum) else False, Hsum))
hmax_ind = list(itertools.compress(range(len(Hsum)), hmax_ind))
wmax_ind = list(map(lambda x: True if x == max(Wsum) else False, Wsum))
wmax_ind = list(itertools.compress(range(len(Wsum)), wmax_ind))
 
res = []
for n in itertools.product(hmax_ind, wmax_ind):
  res.append(str(n[0])+"_"+str(n[1]))

if len(set(res).intersection(set(hw))) == len(res):
  print(max(Hsum) + max(Wsum)-1)
else:
  print(max(Hsum) + max(Wsum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

H, W, M= map(int,input().split(' '))
X = []
Y = []
for i in range(M):
  x, y = map(int,input().split(' '))
  X.append(x)
  Y.append(y)

xc = Counter(X)
xmode = xc.most_common(1)

ans = []
for i in xmode:
  a = i[0]
  a2 = i[1]
  index_list = [k for k, x2 in enumerate(X) if x2a == a]
  list.sort(index_list, reverse=True)
  Ytmp = Y
  for j in index_list:
    Ytmp.pop(j)
  
  yc = Counter(Ytmp)
  ymode = yc.most_common(1)
  ans.append(a2 + ymode[0][1])

print(max(ans))

Submission status: Runtime Error

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


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

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

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

Submission status: Runtime Error

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

from collections import defaultdict
counter_h = defaultdict(int)
counter_w = defaultdict(int)

for i in range(M):
    h[i],w[i] = map(int, input().split())
    counter_h[h[i]] += 1
    counter_w[w[i]] += 1
    
MAX_h = max(counter_h.values())
h_list = [k for k, v in counter_h.items() if v == MAX_h]
MAX_w = max(counter_w.values())
w_list = [k for k, v in counter_w.items() if v == MAX_w]

import itertools
X = list(itertools.product(h_list, w_list))

ans = MAX_h+MAX_w
check = 0

if lenX<3*10**5:
    for i in range(M):
        if (h[i],w[i]) in X:
            check += 1

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

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
hl = {}
wl = {}
boms = [[h, w] for i in range(M) h, w = map(int, input().split()) hl{h}+=1, wl{w}+=1]
max_h = max(hl.items(), key=lambda x: x[1])
max_w = max(wl.items(), key=lambda x: x[1])

ans = max(hl.values()) + max(wl.values())

c = 0
for i in max_h:
  for j in max_w:
    if [i, j] in boms:
      c += 1
    else:
      break
if(c == len(max_h)+len(max_w)):
  print(ans - 1)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


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


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = H[0][1] + W[0][1]
    if (H[0][0], W[0][0]) in bom:
        ans -= 1
    try:
        ans2 = H[1][1] + W[0][1]
        if (H[1][0], W[0][0]) in bom:
        ans2 -= 1
    except:
        ans2 = -1
    try:
        ans3 = H[0][1] + W[1][1]
        if (H[0][0], W[1][0]) in bom:
            ans3 -= 1
    except:
        ans3 = -1
    print(max(ans, ans2, ans3))

    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

hlist = [0] * h
wlist = [0] * w
hwlist= [[0] * w for i in range(h)]
hyou=[]
num_list = []
for i in range(z):
    num_list.append(list(map(int,input().split())))
    hlist[num_list[i][0]-1]+=1
    wlist[num_list[i][1]-1]+=1
    hwlist[num_list[i][0]-1][num_list[i][1]-1]=1
wmax_i=[i for i, v in enumerate(wlist) if v == max(wlist)]

flag=0

for i in wmax_i:
    if sum(hwlist[i])==h:
        flag=1
        break
if flag==1:
    print(max(hlist)+max(wlist))
else:
    print(max(hlist)+max(wlist)-1)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

print(max(l))

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=np.int64)

for _ in range(M):
    h, w = map(int, input().split())
    d[h-1, w-1] = 1
print(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 not d[h, w]:
            print(tate_max+yoko_max)
            sys.exit()
print(tate_max+yoko_max-1)

Submission status: Runtime Error

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

column = [0] * H
row = [0] * W

for item in P:
  column[item[0] -1] += 1
  row[item[1] -1] += 1
  
co_max = sorted(column, reverse=True)[0]
ro_max = sorted(row, reverse=True)[0]

if co_max == 1 and ro_max == 1 and sorted(column, reverse=True)[1] == 1 and sorted(row, reverse=True)[1] == 1:
  print(2)
else:
  column_max = [i for i, x in enumerate(column) if x == co_max]
  row_max = [i for i, x in enumerate(row) if x == ro_max]

  flag = 0
  for i in column_max:
    for j in row_max:
      if [i+1, j+1] not in P:
        flag = 1
        break
  if flag == 1:
    print(max(column) + max(row))
  elif flag == 0:
    print(max(column) + max(row) -1)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

most_col = Counter(h).most_common()[0][0]
col_count = Counter(h).most_common()[0][1]

c_index = [i for i, x in enumerate(h) if x == most_col]
new_w = [v for k, v in enumerate(w) if k not in c_index]

row_count = Counter(new_w).most_common()[0][1]

ans = col_count + row_count

print(ans)

Submission status: Runtime Error

Solution code:
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


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


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = H[0][1] + W[0][1]
    if (H[0][0], W[0][0]) in bom:
        ans -= 1

    ans2 = H[1][1] + W[0][1]
    if (H[1][0], W[0][0]) in bom:
        ans2 -= 1
    ans3 = H[0][1] + W[1][1]
    if (H[0][0], W[1][0]) in bom:
        ans3 -= 1

    print(max(ans, ans2, ans3))

    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

h_list=[0]*H
w_list=[0]*W
bomb=[]
place=[[0]*W for _ in range(H)]
for i in range(M):
    h,w=map(int,input().split())
    h-=1
    w-=1
    place[h][w]+=1
    h_list[h]+=1
    w_list[w]+=1

h_mx=max(h_list)
w_mx=max(w_list)
ans=h_mx+w_mx-1
h_idx=[i for i, x in enumerate(h_list) if x == h_mx]
w_idx=[i for i, x in enumerate(w_list) if x == w_mx]

lst=list(itertools.product(h_idx,w_idx))
for i in lst:
    if place[i[0]][i[1]]==0:
        ans+=1
        break
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, N = list(map(int, input().rstrip().split(' ')))

dist = np.zeros([H, W])

for _ in range(N):
    h, w = list(map(int, input().rstrip().split(' ')))
    dist[h - 1, w - 1] = 1


ans = 0

for h in range(H):
    for w in range(W):
        _sum = dist[h].sum() + dist[:, w].sum() - dist[h, w]
    
        ans = max(ans, _sum)

print(int(ans))

Submission status: Runtime Error

Solution code:
"""
task statement
==============

H \times W マスの二次元グリッドがあります。この中には M 個の爆破対象があります。 i 個目の爆破対象の位置は \left(h_i, w_i \right)です。
高橋君は 1 つのマスを選び、そのマスに爆弾を設置し、起爆します。爆弾と同じ行または同じ列に存在する爆破対象が爆破されます。爆破対象が存在するマスに爆弾を設置することも出来ます。
高橋君は、爆破する爆破対象の数を最大化しようとしています。最大でいくつの爆破対象を爆破出来るか答えてください。

io_style
-------
H W M
h_1 w_1
\vdots
h_M w_M
"""
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


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


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = H[0][1] + W[0][1]
    if (H[0][0], W[0][0]) in bom:
        ans -= 1

    ans2 = H[1][1] + W[0][1]
    if (H[1][0], W[0][0]) in bom:
        ans2 -= 1
    ans3 = H[0][1] + W[1][1]
    if (H[0][0], W[1][0]) in bom:
        ans3 -= 1

    print(max(ans, ans2, ans3))

    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import numpy as np

h, w, m = map(int, input().split())
a = np.zeros((h, w), dtype=np.int64)
b = [[*map(lambda x: int(x) - 1, input().split())] for _ in range(m)]
for x, y in b:
    a[x, :] += 1
    a[:, y] += 1
    a[x][y] -= 1
print(np.max(a))

Submission status: Runtime Error

Solution code:
import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1))
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)

flag = 1
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 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,W))
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:

def solution(matrix, r, c):
    mc = float("-inf")
    for i in range(r):
        for j in range(c):
            # sum row i
            sri = sum(matrix[i])
            scj = 0
            for x in matrix:
                scj += x[j]
            if matrix[i][j] == 1:
                mc = max(mc, sri + scj -1)
            else:
                mc = max(mc, sri + scj)
    return mc

r,c,m = list(map(int, input().split()))
matrix = [[0]*c for _ in range(r)]
for _ in range(m):
    r1,c1 = list(map(int, input().split()))
    matrix[r1-1][c1-1] = 1

print(solution(matrix, r, c))

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)
mxw = []
mxw_v = 0
mxh = []
mxh_v = 0


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
    if mxw_v < w[w_j]:
        mxw_v = w[w_j]
        mxw = [w_j]
    elif mxw_v == w[w_j]:
        mxw.append(w_j)

    if mxh_v < h[h_i]:
        mxh_v = h[h_i]
        mxh = [h_i]
    elif mxh_v == h[h_i]:
        mxh.append(h_i)

a = 0
for i in mxh:
    for j in mxw:
        d = hw[i][j]
        a = max(a, h[i]+w[j]-d)
print(a)

Submission status: Runtime Error

Solution code:
import numpy as np

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

check = np.zeros((h, w))

for i,j in li:
    check[i-1, :] += 1
    check[:, j-1] += 1
    check[i-1, j-1] -= 1

print(int(np.max(check)))

Submission status: Runtime Error

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    H, W, M = il()
    grid = [[0] * W for _ in range(H)]
    wc = [0] * W
    for m in range(M):
        h, w = il()
        grid[h - 1][w - 1] += 1
        wc[w - 1] += 1

    ret = 0
    for h in range(H):
        tmp = sum(grid[h])
        for w in range(W):
            if grid[h][w] == 1:
                ret = max(ret, tmp + wc[w] - 1)
            else:
                ret = max(ret, tmp + wc[w])

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
bomb=[[0]*w for _ in range(h)]
for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    bomb[hr-1][wr-1]=1
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0
for i in cu:
    for j in cl:
        if bomb[i][j]==1:
            res=l[j]+u[i]-1
        else:
            res=l[j]+u[i]
        ans=max(res,ans)
print(ans)

Submission status: Runtime Error

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

M = min(M, H*W)

import numpy as np

area = np.zeros((H, W), int)

for _ in range(M):
    y, x = map(int, input().split(" "))
    area[y-1][x-1] = 1
    
W_sum_ = area.sum(axis = 1)
H_sum_ = area.sum(axis = 0)

y_index = np.where(W_sum_ == W_sum_.max())[0]
x_index = np.where(H_sum_ == H_sum_.max())[0]

max_sum = 0
x_max = y_max = 0

for y in y_index:
    for x in x_index:
        sum_ = H_sum_[x] + W_sum_[y]
        if area[y][x] == 1:
            sum_ -= 1
        if sum_ > max_sum:
            max_sum = sum_
            x_max = x
            y_max = y
            
print(max_sum)

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

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys

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


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

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

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

seth = []
setw = []

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

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

ans = 0

if h == len(seth) and w == len(setw):
    print(2)
    exit()


def cnt(r, c):
    for j in range(m):
        if hl[j] == r and wl[j] == c:

            return -1
    return


for hei in seth:
    for wei in setw:
        ans = max(ans, hc[hei]+wc[wei]+cnt(hei, wei))

print(ans)

Submission status: Runtime Error

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

maxh=maxw=0
qh=[]
qw=[]
for i in range(H):
  maxh=max(maxh, sumh[i])
for i in range(H):
  if maxh==sumh[i]:
    qh.append(i)

for i in range(W):
  maxw=max(maxw, sumw[i])
for i in range(W):
  if maxw==sumw[i]:
    qw.append(i)

for i in qh:
  for j in qw:
    if s[i][j]==0:
      print(maxh+maxw)
      exit()

print(maxh+maxw-1)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
H,W,M = map(int,input().split())
hh = defaultdict(int)
ww = defaultdict(int)
HW = [[0]*W for _ in range(H)]
for _ in range(M):
    h,w = map(int,input().split())
    hh[h] += 1
    ww[w] += 1
    HW[h-1][w-1] = 1
hmax = 0
wmax = 0
for i in range(1,H+1):
    hmax = max(hmax,hh[i])
for j in range(1,W+1):
    wmax = max(wmax,ww[j])
hind = []
wind = []
for i in range(1,H+1):
    if hh[i] == hmax:
        hind.append(i)
for i in range(1,W+1):
    if ww[i] == wmax:
        wind.append(i)
flag = 0
for i in hind:
    if flag == 1:
        break
    for j in wind:
        if i-1 < 0 or j-1 < 0 or i-1 > H or j-1 > W:
            continue
        if HW[i-1][j-1] == 0:
            flag = 1
            print(hmax+wmax)
            break
if flag == 0:
    print(hmax+wmax-1)

Submission status: Runtime Error

Solution code:
h1, w1, m = map(int, input().split())
sw = []
sh = []
l1 = [[0] * w1 for _ in range(h1)]
l2 = [[0] * h1 for _ in range(w1)]
ww = []
hh = []
for _ in range(m):
    h, w = map(int, input().split())
    h, w = h-1, w-1
    l1[h][w] = 1
    l2[w][h] = 1
for i in l1:
    hh.append(sum(i))
for j in l2:
    ww.append(sum(j))
#print(hh)
#print(ww)
m = 0
for i in range(h1):
    for j in range(w1):
        k = hh[i] + ww[j]
        k -= l1[i][j]
        #print(k)
        m = max(k, m)
print(m)

Submission status: Runtime Error

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

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

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

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

m1=max(t1)
m2=max(t2)

i1=t1.index(m1)
i2=t2.index(m2)

if arr[i1][i2]==-1:
    print(m1+m2-1)
else:
    print(m1+m2)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m=map(int,input().split())
l=[]
 
lh,lw=[],[]
 
for i in range(h):
    lh.append(0)
for i in range(w):
    lw.append(0)

for i in range(m):
    l1=list(map(int,input().split()))
    lh[l[0]-1]+=1
    lw[l[1]-1]+=1
    l.append(l1)

lhm=max(lh)
lhml=[i for i, x in enumerate(lh) if x == lhm]
lwm=max(lw)
lwml=[i for i, x in enumerate(lw) if x == lwm]

for i in range(len(lhml)):
    for j in range(len(lwml)):
        k=[]
        k.append(lhml[i]+1)
        k.append(lwml[j]+1)
        l.append(k)

l_arr = np.unique(l, axis=0)
if len(l_arr)==m:print(lhm+lwm-1)
else:print(lhm+lwm)

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)]
    
    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:
import numpy
import sys #追加
sys.setrecursionlimit(500*500) #追加

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

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

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

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

Submission status: Runtime Error

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

for i in range(M):
    h, w = map(int, input().split())
    glt[h-1][w-1] = 1
    
max_bomb = 0
retsu = np.sum(glt, axis=0)
gyo = np.sum(glt, axis=1)


for i in range(H-1):
    for j in range(W-1):
        if retsu[i+1] + gyo[j+1] > retsu[i] + gyo[j]:
            max_bomb = retsu[i+1] + gyo[j+1]
            
print(int(max_bomb))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

H, W, M= map(int,input().split(' '))
X = []
Y = []
for i in range(M):
  x, y = map(int,input().split(' '))
  X.append(x)
  Y.append(y)

xc = Counter(X)
xmode = xc.most_common(1)

ans = []
for i in xmode:
  a = i[0]
  a2 = i[1]
  index_list = [i for i, x in enumerate(X) if x == a]
  list.sort(index_list, reverse=True)
  Ytmp = Y
  for j in index_list:
    Ytmp.pop(j)
  
  yc = Counter(Ytmp)
  ymode = yc.most_common(1)
  ans.append(a2 + ymode[0][1])

print(max(ans))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import numpy as np

h, w, m = map(int, input().split())
a = np.zeros((h, w), dtype=np.int64)
b = [[*map(lambda x: int(x) - 1, input().split())] for _ in range(m)]
for x, y in b:
    c = np.zeros((h, w), dtype=np.int64)
    c[x, :] = 1
    c[:, y] = 1
    a = a + c
print(np.max(a))

Submission status: Runtime Error

Solution code:
import numpy as np

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

maximum = 0
for h in range(H):
    for w in range(W):
        tmp = np.sum(S[h-1, :]) + np.sum(S[:, w-1])
        if S[h-1, w-1] == 1:
            tmp -= 1
        if maximum < tmp:
            maximum = tmp

print(int(maximum))

Submission status: Runtime Error

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

for _ in range(m):
  i, j = map(int, input().split())
  graph[i-1][j-1] = 1
  row_sum[i-1] += 1
  col_sum[j-1] += 1

max_row = max(row_sum)
max_col = max(col_sum)

result = max_row+max_col

ris = [i for i, x in enumerate(row_sum) if x == max_row]
cis = [i for i, x in enumerate(col_sum) if x == max_col]

for ri in ris:
  for ci in cis:
    if graph[ri][ci] == 0:
      print(result)
      exit()
print(result-1)

Submission status: Runtime Error

Solution code:
H, W, m = map(int, input().split())
hs = [0] * H
ws = [0] * W
fs = [[0]*W for i in range(H)]
ps = []
for i in range(m):
    hi,wi  = map(int, input().split())
    hs[hi-1] += 1
    ws[wi-1] += 1
    fs[hi-1][wi-1] += 1
    ps.append((hi-1,wi-1))
mx = 0
Hs = [(h,i) for i,h in enumerate(hs)]
Ws = [(w,i) for i,w in enumerate(ws)]
Hs.sort(reverse=True)
Ws.sort(reverse=True)
cnt = 0
hmx = Hs[0][0]
wmx = Ws[0][0]
# for r in fs:
#     print(*r)
mx = 0
for nh, ih in Hs:
    for nw, iw in Ws:
        if nh < hmx and nw < wmx: continue
        if fs[ih][iw] == 0:
            mx = max(mx, nh+nw)
        if fs[ih][iw] == 1:
            mx = max(mx, nh+nw-1)
        cnt += 1
        if cnt >= m:
            print(mx)
            exit()
print(mx)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

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

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