Problem:


Score : 500 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq h_i \leq H

1 \leq w_i \leq W

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

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

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

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

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

Sample Output 3

6



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


Sample output:
3

Submission status: Runtime Error

Solution code:
from collections import Counter

pas = 0

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

hcnt = Counter(hn)
wcnt = Counter(wn)

ha, cha = zip(*hcnt.most_common())
wa, cwa = zip(*wcnt.most_common())

hli = [int(ha[0])]
wli = [int(wa[0])]
for i in range(len(cha)-1):
    if cha[i] == cha[i+1]:
        hli.append(int(ha[i+1]))
    else:
        break
for i in range(len(cha)-1):
    if cwa[i] == cwa[i+1]:
        wli.append(int(wa[i+1]))
    else:
        break

for i in range(len(hli)):
    if pas == 1:
        break
    for k in range(len(wli)):
        if [hli[i], wli[k]] not in tli:
            ans = cha[i] + cwa[k]
            pas = 1
            break

if pas == 0:
    print(cha[0] + cwa[0] - 1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = []
for i in range(H):
   object += copy.deepcopy(width)
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object[h-1][w-1] = 1
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max - 1
p = len(cand_h)*len(cand_w)
if M > p:
   for i in range(len(cand_h)):
      for j in range(len(cand_w)):
         if object[cand_h[i]][cand_w[j]] == 0:
            ans += 1
else:
   ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy
h,w,m=map(int,input().split())
data=numpy.zeros((h,w),dtype=np.int64)
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:
import numpy as np

h, w, m= map(int, input().split())
ans=np.zeros((h, w), dtype=int)
for i in range(0,m):
  hi, wi = map(int, input().split())
  ans[hi-1,wi-1]=1

colm=np.sum(ans, axis=0)
line=np.sum(ans, axis=1)

colmarg=np.argsort(-colm,kind='quicksort')
linearg=np.argsort(-line,kind='quicksort')

hhh=int(h/10)+1
www=int(w/10)+1
if (h < 10): hhh=h
if (w < 10): www=w

ataimax=0
for ih in linearg[0:hhh]:
  for iw in colmarg[0:www]:
    atai=colm[iw]+line[ih]-ans[ih,iw]
    if (atai >= ataimax): ataimax=atai

print (ataimax)

Submission status: Runtime Error

Solution code:
import sys
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
            sys.exit()
if flag == 0:
    print(maxh + maxw - 1)

Submission status: Runtime Error

Solution code:

def main():
    h, w, m = map(int, input().split())
    blis = []
    xdic = dict()
    ydic = dict()

    for _ in range(m):
        a, b = map(int, input().split())
        blis.append([a,b])
        if a in xdic:
            xdic[a] += 1
        else:
            xdic[a] = 1
        if b in ydic:
            ydic[b] += 1
        else:
            ydic[b] = 1
    xdic = sorted(xdic.items())
    ydic = sorted(ydic.items())
    
    xsaidai = xdic[0][1] 
    ysaidai = ydic[0][1]

    ans = 0

    if xsaidai >= ysaidai:
        for i in range(w):
            for j in range(min(h, 10**2)):
                x = xdic[j][0]
                tmp = 0
                y = i + 1
                for bomb in blis:
                    if bomb[1] == y or bomb[0] == x:
                        tmp += 1
                if ans < tmp:
                    ans = tmp
    else:
        for i in range(min(w, 10**2)):
            for j in range(h):
                y = ydic[i][1]
                tmp = 0
                x = j + 1
                for bomb in blis:
                    if bomb[1] == y or bomb[0] == x:
                        tmp += 1
                if ans < tmp:
                    ans = tmp
    print(ans)
            


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
H, W, M = list(map(int, input().split()))
row = np.zeros(H)
col = np.zeros(W)
maps = np.zeros((H, W))
sys.exit()

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)
nh = len(hind)
nw = len(wind)
flag = 0
for i in hind:
    if flag == 1:
        break
    for j in wind:
        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:
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

x,y,n,=I()
arr=[[0]*y for _ in range(x)]
while n:
    n-=1
    a,b,=I()
    arr[a-1][b-1]+=-1
    arr[a-1]=[i+1 for i in arr[a-1]]
    for i in range(x):
        arr[i][b-1]+=1

maxi=max(arr[0])
for i in range(1,x):
    temp=max(arr[i])
    if temp>maxi:
        maxi=temp

print(maxi)

Submission status: Runtime Error

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

lh = []
lw = []

for i in range(m):
  h1,w1 = map(int, input().split())
  lh.append(h1)
  lw.append(w1)

from collections import Counter as co
c=co(lh).most_common()

ans1 = c[0][1]
ans2 = 0
i = 0
while c[i][1] == c[0][1]:
  tmp = c[i][0]
  lh_c = [j for j, x in enumerate(lh) if x == tmp]
  tmp_lw = lw[:]
  for k in sorted(lh_c, reverse=True):
    tmp_lw.pop(k)
  cw = co(tmp_lw).most_common()
  ans2 = max(ans2, cw[0][1])
  i += 1
  if i >= len(c)-1:
    break
  
print(ans1+ans2)

Submission status: Runtime Error

Solution code:
import collections

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

h_counter = collections.Counter(h)
w_counter = collections.Counter(w)
h_common0 = h_counter.most_common()[0][0]
w_common0 = w_counter.most_common()[0][0]
h_common1 = h_counter.most_common()[1][0]
w_common1 = w_counter.most_common()[1][0]

ans0=0
for i in range(M):
    if h[i] == h_common0 or w[i] == w_common0:
        ans0 = ans0 +1

ans1=0
for i in range(M):
    if h[i] == h_common1 or w[i] == w_common0:
        ans1= ans1 +1
ans2=0
for i in range(M):
    if h[i] == h_common0 or w[i] == w_common1:
        ans2 = ans2 +1

print(max(ans0, ans1, ans2))

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
            return 0
if flag == 0:
    print(maxh + maxw - 1)

Submission status: Runtime Error

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

def main():
    H, W, M = map(int, readline().rstrip().split())
    HW = [[0] * (W + 1) for _ in range(H + 1)]
    HB = [0] * (H + 1)
    HS = set()
    WB = [0] * (W + 1)
    WS = set()
    for _ in range(M):
        h, w = map(int, readline().rstrip().split())
        HW[h][w] = 1
        HB[h] += 1
        HS.add(h)
        WB[w] += 1
        WS.add(w)
    ans = 0
    for h in HS:
        for w in WS:
            tmp = HB[h] + WB[w]
            if HW[h][w] == 1:
                tmp -= 1
            ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input(split()))
if H==1 and W == 1:
  print(1)
  exit()
else:
  hwlist = []
  a = []
  b = []
  for h in range(H):
      a.append(0)
  for w in range(W):
      b.append(0)
  for m in range(M):
    append.list = (list(map(int, input().split())))
    hwlist.append(append_list)
    a[append_list[0]-1] += 1
    b[append_list[1]-1] += 1
  max_a = max(a)
  a_max_id = [i for i, v in enumerate(a) if v == max_a]
  max_b = max(b)
  b_max_id = [i for i, v in enumerate(b) if v == max_b]
  for i in range(len(a_max_id)):
    for j in range(len(a_max_id)):
      if not [a_max_id, b_max_id] in hwlist:
        print(max_a + max_b)
        exit()
  print(max_a + max_b - 1)

Submission status: Runtime Error

Solution code:
import numpy as np

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

for x in range(H):
  MX[x]=sum(MA[x,:])

for y in range(W):
  MY[y]=sum(MA[:,y])

print(MA)
xmax=max(MX)
ymax=max(MY)
ix=[x[0] for x in enumerate(MX) if x[1]==xmax]
iy=[x[0] for x in enumerate(MX) if x[1]==ymax]

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

print(int(xmax+ymax-ii))

Submission status: Runtime Error

Solution code:
import numpy as np

h, w, m= map(int, input().split())
ans=np.zeros((h, w), dtype=int)
for i in range(0,m):
  hi, wi = map(int, input().split())
  ans[hi-1,wi-1]=1

colm=np.sum(ans, axis=0)
line=np.sum(ans, axis=1)

colmarg=np.argsort(-colm,kind='quicksort')
linearg=np.argsort(-line,kind='quicksort')

hhh=int(h/2)
www=int(w/2)
if (h < 10): hhh=h
if (w < 10): www=w

ataimax=0
for ih in linearg[0:hhh]:
  for iw in colmarg[0:www]:
    atai=colm[iw]+line[ih]-ans[ih,iw]
    if (atai >= ataimax): ataimax=atai

print (ataimax)

Submission status: Runtime Error

Solution code:
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:
def main():
    h, w, m = map(int, input().split())    
    h_w = []
    for i in range(m):
        h_w.append(list(map(int, input().split())))

    x = [0]*h
    y = [0]*w

    for p in h_w:
        x[p[0]-1] += 1
        y[p[1]-1] += 1
    
    if max(x) == 1 and max(y) == 1 and m > 1:
        pritn(2)
        return 0
    
    y = [0]*w
    idx = [i for i, v in enumerate(x) if v == max(x)]

    maxv = 0
    for i in idx:
        for p in h_w:
            if p[0]-1 == i:
                continue
            else:
                y[p[1]-1] += 1
        
        if maxv < max(x) + max(y):
            maxv = max(x) + max(y)
        
        y = [0]*w
        
        
    print(maxv)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys

d = [int(s) for s in stdin.readline().rstrip().split()]
h = d[0]
w = d[1]
m = d[2]
hCount = [0]*h
wCount = [0]*w
poss = [[0] * w for i in range(h)]
for el in range(m):
    pos = [int(s) for s in stdin.readline().rstrip().split()]
    hCount[pos[0]-1] += 1
    wCount[pos[1]-1] += 1
    poss[pos[0]-1][pos[1]-1] = 1
hPos = -1
value = -1
count = 0
for el in hCount:
    if value < el:
        value = el
        hPos = count
    count += 1
wPos = -1
count = 0
for el in wCount:
    if value < el:
        value = el
        wPos = count
    count += 1
if wPos != -1:
    line = []
    for el in poss:
        line.append(el[wPos])
    hValue = 0
    hPos = 0
    count = 0
    for el in wCount:
        if hValue < el:
            hValue = el
            hPos = count
        count += 1
    print(value+hValue)
else:
    line = poss[hPos]
    count = 0
    for el in line:
        wCount[count] -= el
        count += 1
    wValue = 0
    wPos = 0
    count = 0
    for el in wCount:
        if wValue < el:
            wValue = el
            wPos = count
        count += 1
    print(value+wValue)

Submission status: Runtime Error

Solution code:
h,w,m=input().split(" ")
h=int(h)
w=int(w)
m=int(m)
arr=[]
row=[0]*(h+1)

aa=[]

for i in range(m):
    bb=[]
    a,b=input().split(" ")
    a=int(a)
    b=int(b)
    d=row[a]
    row[a]=d+1
    
    bb.append(a)
    bb.append(b)
    aa.append(bb)
cc1=max(row)
cc=row.index(cc1)

c1=[]
for j in range(len(aa)):
    if aa[j][0]!=cc:
        c1.append(aa[j][1])
count=0    
xx=max(c1)
for k in range(len(aa)):
    if aa[k][0]==cc or aa[k][1]==xx:
        count=count+1
    
print(count)

Submission status: Runtime Error

Solution code:
H,W,M = [int(x) for x in input().split()]
hw = []
hNum = [0]*10
wNum = [0]*10

for i in range(M):
    h,w = [int(x) for x in input().split()]
    hw.append([h,w])
    hNum[h]+=1
    wNum[w]+=1
hmax = -1
hMaxList = []
wmax = -1
wMaxList = []
for i in range(10):
    if(hmax <= hNum[i]):
        if(hmax == hNum[i]):
            hMaxList.append(i)
        else:
            hMaxList = [i]
        hmax = hNum[i]

    if(wmax <= wNum[i]):
        if(wmax == wNum[i]):
            wMaxList.append(i)
        else:
            wMaxList = [i]
        wmax = wNum[i]

ans = wmax + hmax
# print(ans)
for i in range(10):
    if([i,i] in hw and i in hMaxList and i in wMaxList):
        ans -= 1
if(len(hw) < 10 and (hmax ==  1 or  wmax ==  1 )):
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
import collections
import sys

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
tansaku_x = []
tansaku_y = []
for x, x_num in c_x.most_common():
  if x_num != _max_x:
    break
  tansaku_x.append(x)
for y, y_num in c_y.most_common():
  if y_num != _max_y:
    break
  tansaku_y.append(y)

for x in tansaku_x:
  for y in tansaku_y:
    if bomb[x][y] == 0:
      print(count+1)
      sys.exit()
        
print(count)

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:
H, W, M = map(int, input().split())
map_ = [[False]*W for i in range(H)]
num_col = [0] * W
num_row = [0] * H
for i in range(M):
    h, w = map(int, input().split())
    map_[h-1][w-1] = True
    num_row[h-1] += 1
    num_col[w-1] += 1

row_max = max(num_row)
col_max = max(num_col)
tmp_row = [i for i, v in enumerate(num_row) if v == row_max]
tmp_col = [i for i, v in enumerate(num_col) if v == col_max]

for i in tmp_row:
    for j in tmp_col:
        if map_[i][j] is False:
            print(row_max + col_max)
            break
    if map_[i][j] is False:
        break
else:
    print(row_max + col_max - 1)

Submission status: Runtime Error

Solution code:
import numpy as np

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

ans = int(np.max(number))

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
H , W ,M= map(int , input().split())
count = np.zeros((H,W))
for i in range(M):
  y,x = map(int,input().split())
  
  count[y-1,:] +=1
  count[:,x-1] +=1
  count[y-1,x-1]-=1
  
  
print(int(np.max(count)))

Submission status: Runtime Error

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def array(size, init=0):
    return [[init for j in range(size[1])] for i in range(size[0])]


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


def II():
    return int(input())


directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def permutate(x, A):
    n = len(x)
    res = [-1]*n
    for i in range(n):

        res[i] = x[A[i]]
    return res


def generate_bin(digit):
    for b in range(2**digit):
        b = bin(b)
        tmp = b[2:].zfill(digit)
        yield list(map(int, tmp))
        # b=list(map(int,list(b[2:].zfill(digit))))
        # yield b


def search(x, count):
    #print("top", x, count)

    for d in directions:
        nx = d+x
        # print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)

    return count


H, W, M = acinput()

Bh = [[0, i] for i in range(H+1)]
Bw = [[0, i] for i in range(W+1)]
B = {}
for i in range(M):
    h, w = acinput()
    Bh[h][0] += 1
    Bw[w][0] += 1
    B[(h, w)] = 1

Bh = sorted(Bh,  reverse=True)
Bw = sorted(Bw,  reverse=True)

Hidx = []
Widx = []
k = 0
while True:
    Hidx.append(k)
    if Bh[k][0] > Bh[k+1][0]:
        break
    k += 1

k = 0
while True:
    Widx.append(k)
    if Bw[k][0] > Bw[k+1][0]:
        break
    k += 1

for hi in Hidx:
    h = Bh[k][1]
    for wi in Widx:
        w = Bw[k][1]
        if not((h, w) in B):
            res = Bh[h][0]+Bw[w][0]
            print(res)
            sys.exit()


print(Bh[0][0]+Bw[0][0]-1)

Submission status: Runtime Error

Solution code:
import numpy as np
def main():
  H,W,m=map(int,input().split())
  h=np.zeros(H)
  w=np.zeros(W)
  hw=np.zeros((H, W))
  for i in range(m):
    hi,wi=map(int,input().split())
    h[hi-1]+=1
    w[wi-1]+=1
    hw[hi-1,wi-1]+=1
  yn=1
  hm=np.max(h)
  wm=np.max(w)
  for j in range(H):
    if h[j]==hm:
      for k in range(W):
        if w[k]==wm:
          if hw[j,k]==0:
            yn=0
  print(int(hm+wm-yn))
main()

Submission status: Runtime Error

Solution code:
import sys
H, W, M = map(int, sys.stdin.readline().split())
hlst = [0]*(H+1)
wlst = [0]*(M+1)
hwlst = []

for i in range(M):
    h, w = map(int, sys.stdin.readline().split())
    hlst[h] += 1
    wlst[w] += 1
    hwlst.append([h,w])

hmax = max(hlst)
wmax = max(wlst)
ans = hmax + wmax -1
c = False
i = 0
for i in range(H+1):
    if hlst[i] == hmax:
        for j in range(W+1):
            if wlst[j] == wmax:
                if [i, j] not in hwlst:
                    ans += 1
                    c = True
            if c:
                break
    if c:
        break

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

h,w,m = (int(x) for x in input().split())

a = np.zeros( (h,w) )
for i in range(m):
    hi,wi = (int(x) for x in input().split())
    a[hi-1][wi-1] = 1

Hs = []
greatH = 0
gHs = []
for i in range(h):
    x = int(np.sum( a[i,:] ))
    Hs.append(x)
    if x > greatH:
        greatH = x
for i in range(h):
    if math.isclose(Hs[i] , greatH):
        gHs.append(i)
Ws = []
greatW = 0
gWs = []
for i in range(w):
    x = int(np.sum( a[:,i] ))
    Ws.append(x)
    if x > greatW:
        greatW = x
for i in range(w):
    if math.isclose(Ws[i] , greatW):
        gWs.append(i)

great = greatH + greatW

flag = 1
for i in range( len(gHs) ):
    x = gHs[i]
    for j in range( len(gWs) ):
        y = gWs[j]
        if math.isclose(a[x][y] , 0):
            flag = 0

print( int(great - flag) )

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
h, w, m = map(int, input().split())
row = [0 for _ in range(h)]
col = [0 for _ in range(w)]
info = dict()
tmpx = [-1, -1]
tmpy = [-1, -1]
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if x not in info:
        info[x] = set()
    info[x].add(y)
    row[x] += 1
    if row[x] > tmpx[0]:
        tmpx[0] = row[x]
        tmpx[1] = x
    col[y] += 1
    if col[y] > tmpy[0]:
        tmpy[0] = col[y]
        tmpy[1] = y
    print(col, tmpy)


res = tmpx[0]+tmpy[0]
if tmpx[1] in info and tmpy[1] in info[tmpx[1]]:
    res -= 1
print(res)

Submission status: Runtime Error

Solution code:
H,W,M = list(map(int,input().split()))
import numpy as np
Target = np.zeros((H,W))
for i in range(M):
    l,r = list(map(int,input().split()))
    Target[l-1,r-1] = 1
hvec = np.dot(Target,np.ones(W))
hmax = max(hvec)
wvec = np.dot(Target.T,np.ones(H))
wmax = max(wvec)
res = 0
for h in range(H):
    if hvec[h] == hmax:
        for w in range(W):
            if wvec[w] == wmax:
                if Target[h][w] == 1:
                    res = max(res,hmax + wmax -1)
                else:
                    res = hmax + wmax
print(int(res))

Submission status: Runtime Error

Solution code:
#n = int(input())
#a = list(map(int, input().split()))
h, w, m = map(int, input().split())
listh = [0] * m
listw = [0] * m
lista = [0] * (m+1)
listb = [0] * (m+1)
import collections

for i in range(m):
    listh[i], listw[i] = map(int, input().split())

for i in range(1,h+1):
  lista[i] = listh.count(i)

for i in range(1,w+1):
  listb[i] = listw.count(i)
p = max(lista)
q = max(listb)
ans = 1
r = [i for i, v in enumerate(lista) if v == p]
s = [i for i, v in enumerate(listb) if v == q]
for i in range(len(r)):
  for j in range(len(s)):
    for k in range(m):
      if listh[k] == r[i] and listw[k] == s[j]:
        break
      if k == m-1:
        ans = 0
print(p+q-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 i 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
  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:
# E-Bomber
h,w,m = map(int,input().split())
grid = [[0] * (w+1) for i in range(h+1)]
#print(grid)
for i in range(m):
    x,y = map(int,input().split())
    grid[x][y] = 1
    grid[x][0] += 1
    grid[0][y] += 1

max_w = 0
max_j = []
for j in range(1,w+1):
    if max_w < grid[0][j]:
        max_w = grid[0][j]
        max_j = []
        max_j.append(j)
    elif max_w == grid[0][j]:
        max_j.append(j)

max_h = 0
max_i = []
for i in range(1,h+1):
    if max_h < grid[i][0]:
        max_h = grid[i][0]
        max_i = []
        max_i.append(i)
    elif max_h == grid[i][0]:
        max_i.append(i)

ans = 1
for i in max_i:
    for j in max_j:
        if grid[i][j]==0:
            ans = 0
            break

#for i in range(h+1):
#    print(grid[i])
#print(max_i,max_j)
#print(max_h,max_w)
print(max_h+max_w-ans)

Submission status: Runtime Error

Solution code:
n,m,tar=map(int,input().split())
mat=[]
for i in range(n):
  temp=[0]*m
  mat.append(temp)
row=[0]*n
col=[0]*m
for i in range(tar):
  li=list(map(int,input().split()))
  row[li[0]-1]+=1
  col[li[1]-1]+=1
  mat[li[0]-1][li[1]-1]=1
  

ans=0
for i in range(n):
  for j in range(m):
    temp_ans=row[i]+col[j]
    if mat[i][j]==1:
      temp_ans-=1
    ans=max(temp_ans,ans)
print(ans)

Submission status: Runtime Error

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

sumh.sort(reverse=True, key=lambda x:x[1])
sumw.sort(reverse=True, key=lambda x:x[1])

maxh=sumh[0][1]
maxw=sumw[0][1]

flg=s[sumh[0][0]][sumw[0][0]]
for i in range(H):
  if sumh[i][1]<maxh:
    print(maxh+maxw-flg)
    exit()
  for j in range(W):
    if sumw[j][1]<maxw:
      j=W-1
    else:
      flg=min(flg,s[sumh[i][0]][sumw[j][0]])
#      print("###",i,j,sumh[i],sumw[j])


print(maxh+maxw-flg)

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

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

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

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

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

        if table[i][j]==1:
            t_bomb.append(count + count_t - 1)
        else:
            t_bomb.append(count + count_t)

# print(t_bomb)
print(max(t_bomb))

Submission status: Runtime Error

Solution code:
import sys
H, W, M = map(int, input().split())
lis =[]
Hlis = [0]*H
Mlis = [0]*M
for _ in range(M):
    Ch, Cm = map(int, input().split())
    Hlis[Ch-1] += 1
    Mlis[Cm-1] += 1
    lis.append([Ch, Cm])

Hmax = max(Hlis)
Hidx = [i+1 for i, v in enumerate(Hlis) if v == Hmax]
Mmax = max(Mlis)
Midx = [i+1 for i, v in enumerate(Mlis) if v == Mmax]

for i in range(len(Hidx)):
    for j in range(len(Midx)):
        if [[Hidx, Midx]] not in lis:
            print(Hmax+Mmax)
            sys.exit()
else:
    print(Hmax + Mmax -1)

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, M = map(int, input(split()))
hwlist = []
a = []
b = []
for h in range(H):
    a.append(0)
for w in range(W):
    b.append(0)
for m in range(M):
  append.list = (list(map(int, input().split())))
  hwlist.append(append_list)
  a[append_list[0]-1] += 1
  b[append_list[1]-1] += 1
max_a = max(a)
a_max_id = [i for i, v in enumerate(a) if v == max_a]
max_b = max(b)
b_max_id = [i for i, v in enumerate(b) if v == max_b]
for i in range(len(a_max_id)):
  for j in range(len(a_max_id)):
    if not [a_max_id, b_max_id] in hwlist:
      print(max_a + max_b)
      exit()
print(max_a + max_b - 1)

Submission status: Runtime Error

Solution code:
import 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
        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())
G = np.array([[0 for i in range(W)] for j in range(H)])
for i in range(M):
    h,w = map(int,input().split())
    G[h-1][w-1] = 1

h_max = 0
for i in range(H):
    if sum(G[i]) > h_max:
        h_max = sum(G[i])
        y = i

G = G.T
w_max = 0
for j in range(W):
    if sum(G[j]) > w_max:
        w_max = sum(G[i])
        x = j

if G[x][y] == 1:
    print(h_max + w_max - 1)
else:
    print(h_max + w_max)