Problem:


Score : 500 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq h_i \leq H

1 \leq w_i \leq W

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

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

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

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

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

Sample Output 3

6



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


Sample output:
3

Submission status: Runtime Error

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

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    H,W,M = LI()
    t = [LI() for _ in range(M)]

    hmax = [0] * (M+1)
    wmax = [0] * (M+1)

    for x,y in t:
        hmax[x] += 1
        wmax[y] += 1

    ans = 0
    for x,y in t:
        ans = max(ans,hmax[x] + wmax[y] - 1)

    hm = max(hmax)
    wm = max(wmax)

    for i in range(H):
        if hmax[i] == hm:
            for j in range(W):
                if wmax[j] == wm:
                    if [i,j] not in t:
                        print(hm+wm)
                        return
    print(hm+wm-1)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque
h, w, m = map(int, input().split())
hl=[0]*h
wl=[0]*w
mh=0
mw=0
mhi=deque([])
dic = {}
mwi=deque([])
#ans =[[0]*w for i in range(h)]
s = [list(map(int, input().split())) for i in range(m)]
 
for i in range(m):
  a, b = s[i]
  a-=1
  b-=1
  if not a in dic:
    #dic[a] = deque([b])
    dic[a] = [0]*w
    dic[a][b]=1
    
  else:
    dic[a][b]=1
 
  hl[a]+=1
  if hl[a]>mh:
    mh=hl[a]
    mhi = [a]
  elif hl[a]==mh:
    mhi.append(a)
  
  wl[b]+=1
  if wl[b]>mw:
    mw=wl[b]
    mwi=[b]
  elif wl[b]==mw:
    mwi.append(b)
 
  #ans[a][b]+=1 
for i in mhi:
  for j in mwi:
    if dic[i][j]==0:
      print(mh+mw)
      quit()
      
print(mh+mw-1)

Submission status: Runtime Error

Solution code:

import glob
import os
import numpy as np

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:
    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index - 1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        H, W, M = map(int, self.input_data().split())
        B = [None for i in range(M)]

        bombs = [[0 for j in range(W+1)] for i in range(H+1)]
        for i in range(M):
            B[i] = list(map(int, self.input_data().split()))
            tmp1 = B[i][0]
            tmp2 = B[i][1]
            bombs[B[i][0]][B[i][1]] = 1

        B_np = np.array(bombs)

        ver_num = np.sum(B_np, axis=0) # 列ごとの合計(行分ある)
        hol_num = np.sum(B_np, axis=1) # 行ごとの合計(列分ある)

        ver_max = np.max(ver_num)
        hol_max = np.max(hol_num)

        max_columns = []
        max_rows = []

        for i in range(W):
            if ver_max == ver_num[i]:
                max_columns.append(i)
        for i in range(H):
            if hol_max == hol_num[i]:
                max_rows.append(i)

        result = ver_max + hol_max - 1
        for c in max_columns:
            for r in max_rows:
                if bombs[c][r] == 0:
                    result = ver_max + hol_max
                else:
                    pass

        print(str(result))

solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)

cnt=[[False]*(w+1) for i in range(h+1)]
for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt[a][b]=True
  
hcnt,wcnt=0,0
for i in range(1,h+1):
  hcnt=max(hcnt,hlist[i])
  
for i in range(1,w+1):
  wcnt=max(wcnt,wlist[i])

hh,ww=[],[]

for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,h+1):
  if wlist[i]==wcnt:
    ww+=[i]

ans=0

for i in hh:
  for j in ww:
    if cnt[i][j]==False:
      print(hcnt+wcnt)
      exit()
  
print(hcnt+wcnt-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 = 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 = 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 and npBombs[x,y] == 0:
      answer = Hmax + Wmax

print(int(answer))

Submission status: Runtime Error

Solution code:
import collections
H, M, W = map(int, input().split())
X = []
Y = []

for i in range(M):
    a, b = map(int, input().split())
    X.append(a)
    Y.append(b)
    A = collections.Counter(X)
    B = collections.Counter(Y)
cnt_x = A.most_common()[0][0]
cnt_y = B.most_common()[0][0]

x = A.most_common()[0][1]
y = B.most_common()[0][1]
if 
print (cnt_x + cnt_y)

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
h_=[0]*(h+1)
w_=[0]*(w+1)
plot=[[0]*(w+1) for _ in range(h+1)]
for _ in range(m):
    x,y=map(int,input().split())
    h_[x]+=1
    w_[y]+=1
    plot[x][y]+=1
x=max(h_)
y=max(w_)
a=[i for i,v in enumerate(h_) if v==x]
b=[j for j,q in enumerate(w_) if q==y]
u=0
c=0
for i in a:
    for j in b:
        if plot[i][j]==1:
            u+=1
        c+=1
ans=x+y
if u==c:
    print(ans-1)
else:
    print(ans)

Submission status: Runtime Error

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

ans = 0
for i in range(H):
  for j in range(W):
    if bom[i][j] == 1:
      ans = max(ans, hNum[i]+wNum[j]-1)
    else:
      ans = max(ans, hNum[i]+wNum[j])

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

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

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

print(int(xmax+ymax-ii))

Submission status: Runtime Error

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


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

rui1=[[0]*W for _ in range(H)]
rui2=[[0]*W for _ in range(H)]

for h in range(H):
    for w in range(W):
        if h==0 and w==0:
            rui1[h][w]=L[h][w]
            rui2[-1-h][-1-w]=L[-1-h][-1-w]
        elif h==0:
            rui1[h][w]=L[h][w]+rui1[h][w-1]
            rui2[-1-h][-1-w]=L[-1-h][-1-w]+rui2[-1-h][-w]
        elif w==0:
            rui1[h][w]=L[h][w]+rui1[h-1][w]
            rui2[-1-h][-1-w]=L[-1-h][-1-w]+rui2[-h][-1-w]

        else:
            rui1[h][w]=L[h][w]+rui1[h-1][w]+rui1[h][w-1]-rui1[h-1][w-1]
            rui2[-1-h][-1-w]=L[-1-h][-1-w]+rui2[-h][-1-w]+rui2[-1-h][-w]-rui2[-h][-w]

ans=0
for h in range(H):
    for w in range(W):
        now=rui1[h][w]+rui2[h][w]-L[h][w]
        if h!=0 and w!=0:
            now-=rui1[h-1][w-1]
        if h!=H-1 and w!=W-1:

            now-=rui2[h+1][w+1]

        ans=max(ans, now)
print(ans)
#print(rui1)
#print(rui2)

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys

H,W,M,*hw = map(int,open(0).read().split())

h = hw[::2]
w = hw[1::2]

bomb = [[0]*W for _ in range(H)]
for hi,wi in zip(h,w):
    bomb[hi-1][wi-1] = 1


raw_count = Counter(h)
col_count = Counter(w)

raw_max = raw_count.most_common()[0][1]
col_max = col_count.most_common()[0][1]

ans = 0
for hi, rcount in raw_count.most_common():
    if rcount<raw_max:break
    for wi, ccount in col_count.most_common():
        if ccount<col_max: break
        
        if bomb[hi-1,wi-1]==1:
            ans = raw_max + col_max - 1
        else:
            print(raw_max + col_max)
            sys.exit()

print(ans)

Submission status: Runtime Error

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


def compress(arr1):
    from bisect import bisect_left
    vals = []
    for i in range(len(arr1)):
        for d in range(2):
            v1 = arr1[i] + d
            vals.append(v1)
    unique_elems = sorted(set(vals))
    for i in range(len(arr1)):
        arr1[i] = bisect_left(unique_elems, arr1[i])
    return unique_elems


def main():
    all_x = compress(x)
    all_y = compress(y)
    matrix = [[0] * len(all_x) for _ in range(len(all_y))]
    for i in range(m):
        matrix[x[i]][y[i]] += 1
    lr = len(matrix)
    lc = len(matrix[0])
    r_cnt = [0] * lr
    c_cnt = [0] * lc
    for r in range(lr):
        for c in range(lc):
            if matrix[r][c] == 1:
                r_cnt[r] += 1
                c_cnt[c] += 1
    ans = 0
    for r in range(lr):
        for c in range(lc):
            temp = r_cnt[r] + c_cnt[c]
            if matrix[r][c] == 1:
                temp -= 1
            ans = max(ans, temp)
    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), dtype=int)
sys.exit()

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
l=[0]*n
d=[0]*m
p=[]
for i in range(n):
    t=[]
    for j in range(m):
        t.append(0)
    p.append(t)
for u in range(k):
    x,y=map(int,input().split())
    l[x-1]+=1
    d[y-1]+=1
    p[x-1][y-1]=1
x=max(l)
y=max(d)
xx,yy=[],[]
for i in range(n):
    if(l[i]==x):
        xx.append(i)
for j in range(m):
    if(d[j]==y):
        yy.append(j)
f=0
for i in range(len(xx)):
    for j in range(len(yy)):
        if(p[xx[i]][yy[i]]==0):
            f=1
            break
if(f==0):
    print(x+y-1)
else:
    print(x+y)

Submission status: Runtime Error

Solution code:
h, w, m = input().split()
h,w,m =int(h),int(w),int(m)
r = [0 for _ in range(h+1)]
c = [0 for i in range(w+1)]
ma = [[0 for _ in range(w+1)] for _ in range(m+1)]
for i in range(m):
    a, b =input().split()
    a,b =int(a),int(b)
    r[a]= r[a]+1
    c[b]= c[b]+1
    ma[a][b] = 1
aa = max(r)
bb = max(c)
print(aa,bb)
result = aa + bb
if(ma[r.index(aa)][c.index(bb)]==1):
    result = result -1
print(r.index(aa),c.index(bb))
print(result)

Submission status: Runtime Error

Solution code:
h1,w1,m=map(int,input().split())
r=[0 for i in range(m)]
c=[0 for i in range(m)]
mpr={}
mpc={}
for i in range(m):
    h,w=map(int,input().split())
    r[i]=h
    c[i]=w
    try:
        mpr[h]+=1
    except:
        mpr[h]=1
    try:
        mpc[w]+=1
    except:
        mpc[w]=1
l1=list(mpr.keys())
l2=list(mpc.keys())
maxl1=l1[0]
maxl2=l2[0]
cc=0
for i in range(len(l1)):
    if mpr[l1[i]]>mpr[maxl1]:
        maxl1=l1[i]
for i in range(len(l2)):
    if mpc[l2[i]]>mpc[maxl2]:
        maxl2=l1[i]
for i in range(m):
    if r[i]==maxl1:
        cc+=1
        continue
    # if r[i]==maxl2:
    #     cc+=1
    #     continue
    # if c[i]==maxl1:
    #     cc+=1
    #     continue
    if c[i]==maxl2:
        cc+=1
        continue
print(cc)

Submission status: Runtime Error

Solution code:
import numpy as np

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

ans = int(np.max(number))

print(ans)

Submission status: Runtime Error

Solution code:
H,W,M = map(int,input().split())
S = [["."]*W for i in range(H)]
for i in range(M):
  h, w = map(int,input().split())
  S[h-1][w-1] = "#"


rs = [[0]*W for i in range(H)]
ls = [[0]*W for i in range(H)]
ds = [[0]*W for i in range(H)]
us = [[0]*W for i in range(H)]

for i in range(H):
    tmp = 0
    for j in range(W):
        if S[i][j] == '#':
            tmp += 1
            rs[i][j] = tmp
        else:
            tmp += 0
    tmp = 0
    for j in reversed(range(W)):
        if S[i][j] == '#':
            tmp += 1
            ls[i][j] = tmp
        else:
            tmp += 0

for j in range(W):
    tmp = 0
    for i in range(H):
        if S[i][j] == '#':
            tmp += 1
            ds[i][j] = tmp
        else:
            tmp += 0
    tmp = 0
    for i in reversed(range(H)):
        if S[i][j] == '#':
            tmp += 1
            us[i][j] = tmp
        else:
            tmp += 0

ans = 0
for i in range(H):
    for j in range(W):
        tmp = rs[i][j] + ls[i][j] + ds[i][j] + us[i][j] - 3
        ans = max(ans, tmp)
print(ans)

Submission status: Runtime Error

Solution code:
def solve():
  H, W, M = map(int, input().split())
  bomb = [[0]*W for _ in range(H)]
  lis1 = [0]*H
  lis2 = [0]*W
  for _ in range(M):
    h,w = map(int, input().split())
    h -= 1
    w -= 1
    bomb[h][w] = 1
    lis1[h] += 1
    lis2[w] += 1
  ans = 0
  for h in range(H):
    cnt = lis1[h]
    for w in range(W):
      ans = max(ans, cnt+lis2[w]-bomb[h][w])
  return ans
print(solve())

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)

cnt=[[False]*(w+1) for i in range(h+1)]
for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt[a][b]=True
  
hcnt,wcnt=0,0
for i in range(1,h+1):
  hcnt=max(hcnt,hlist[i])
  
for i in range(1,w+1):
  wcnt=max(wcnt,wlist[i])

hh,ww=[],[]

for i in range(1,h+1):
  if hlist[i]==hcnt:
    hh+=[i]

for i in range(1,h+1):
  if wlist[i]==wcnt:
    ww+=[i]

ans=0

for i in hh:
  for j in ww:
    if cnt[i][j]==True:
      print(hcnt+wcnt-1)
      exit()
  
print(hcnt+wcnt)

Submission status: Runtime Error

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

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

H_list = [[0, i] for i in range(H + 1)] 
W_list = [[0, i] for i in range(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][0] += 1
    W_list[b][0] += 1

ans = 0
H_list.sort(reverse=True)
W_list.sort(reverse=True)

tmp_H = H_list[0][0]
tmp_W = W_list[0][0]

for h in range(H):
    if H_list[h][0] + 2 < tmp_H:
        continue
    h_ = H_list[h][1]
    for w in range(W):
        if W_list[w][0] + 2 < tmp_W:
            break
        w_ = W_list[w][1]
        tmp = H_list[h][0] + W_list[w][0] - G[h_][w_]
        ans = max(ans, tmp)

print (ans)

Submission status: Runtime Error

Solution code:
#n=int(input())
import collections
from collections import defaultdict
h,w,m=[int(x) for x in input().split()] 
rows=[0]*(h+1)
col=[0]*(w+1)
a=[]
for _ in range(h):
   a.append([0]*w)
#print(a)

for i in range(m):
   r,c=[int(x) for x in input().split()]
   rows[r]+=1  
   col[c]+=1
   a[r-1][c-1]=1
#print(a)
ans=0
#print(rows)
#print(col)
for i in range(1,h+1):
     for j in range(1,w+1):

         if a[i-1][j-1]==1:
             ans=max(ans, rows[i]+col[j]-1)
         else:
             ans=max(ans, rows[i]+col[j])

print(ans)

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:
from collections import Counter
import numpy as np
H, W, M = map(int, input().split())
h_list = []
w_list = []
ans = 0
for _ in range(M):
  h, w = map(int, input().split())
  h_list.append(h)
  w_list.append(w)
h_list = np.array(h_list)
w_list = np.array(w_list)

c_w = Counter(w_list)
w_most_common, w_most_common_count = c_w.most_common()[0]

c_h = Counter(h_list[w_list != w_most_common])

h_most_common, h_most_common_count = c_h.most_common()[0]
ans += h_most_common_count

ans += w_most_common_count
print(ans)

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 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=0
for i in range(x):
    temp=max(arr[i])
    if temp>maxi:
        maxi=temp
        
print(maxi)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h, w, m = (int(x) for x in input().split())
S = [[0] * w for _ in range(h)]
H = [0] * h
W = [0] * w
for _ in range(m):
    h_, w_ = (int(x) - 1 for x in input().split())
    S[h_][w_] = 1
    H[h_] += 1
    W[w_] += 1

hmax = max(H)
wmax = max(W)
ans = hmax + wmax - 1
for y in range(h):
    if H[y] != hmax:
        continue
    for x in range(w):
        if W[x] != wmax:
            continue
        if S[y][x] == 0:
            ans = hmax + wmax

print(ans)

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


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

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


for i in range(m):
    hi,wi = map(int,input().split())
    b[hi-1,wi-1] += 1
    yp[hi-1,0] += 1
    xp[wi-1,0] += 1
xp[:,0] -= 1
yps = np.argsort(yp[:,0])[::-1]
xps = np.argsort(xp[:,0])[::-1]

#print(xp)
#print(yp)
#print(yps)
#print(xps)

#print(xp)
#print(yp)
#print(b)
ans = yp[yps[0],0]
a = xp[xps[0],0]
ans += a
ans += a==0
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    mw = mh = -1
    iw = ih = -1
    for rep in range(max(w,h)):
        tmp = 0
        if rep<w:
            for i in range(h):
                tmp += fa[i][rep]
            if tmp<mh:
                break
            if tmp==mh:
                if ih!=-1 and rep==iw:
                    break
            mh = tmp
            ih = rep
        if rep<h:
            tmp = 0
            for i in range(w):
                tmp += fa[rep][i]
            if tmp<mw:
                break
            if tmp==mw:
                if iw!=-1 and rep==ih:
                    break
            mw = tmp
            iw = rep
    print(mw+mh-fa[ih][iw])
    return

if __name__=='__main__':
    h,w,m = IL()
    fa = [[0]*w for _ in range(h)]
    for _ in range(m):
        th,tw = IL()
        fa[th-1][tw-1] = 1
    solve()

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[i], Midx[j]] not in lis:
            print(Hmax+Mmax)
            sys.exit()
else:
    print(Hmax + Mmax -1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import threading 
from collections import defaultdict,Counter
from math import factorial as fac

def main():
  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)

BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import deque

def main():
	h,w,m=MI()
	A=[0]*(h+1)
	B=[0]*(w+1)
	C=[[] for _ in range(h+1)]

	for _ in range(m):
		hh,ww=MI()
		A[hh]+=1
		B[ww]+=1
		C[hh].append(ww)


	for i in range(h+1):
		C[i].sort()

	AA=max(A)
	BB=max(B)

	x=[]
	y=[]

	for i,v in enumerate(A):
		if v==AA:
			x.append(i)

	for i,v in enumerate(B):
		if v==BB:
			y.append(i)

	#print(x,y,AA,BB)
	ans=0

	for i in x:
		#print("a")
		#print(C[i])
		#print(y)
		a=0
		for j in y:
			while True:
				if j==C[i][a]:
					a+=1
					break
				elif j<C[i][a]:
					print(AA+BB)
					exit()
				else:
					break

	print(AA+BB-1)
















if __name__ == "__main__":
	main()

Submission status: Runtime Error

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

erea=[[0] * W for i in range(H)]

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



import collections
hlis=collections.Counter(h).most_common()
wlis=collections.Counter(w).most_common()

maxh=hlis[0][1]
maxw=wlis[0][1]

c=0

for he in hlis:
    if(he[1]!=maxh):
        break

    for we in wlis:
        if(we[1]!=maxw):
            break
        
        if erea[he[0]-1][we[0]-1] != 0:
            tmp=he[1]+we[1]-1
        else:
            tmp=he[1]+we[1]
        
        if tmp > c :
            c = tmp
        
print(c)

Submission status: Runtime Error

Solution code:
import numpy

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

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

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

c = max(h)
d = max(w)
a = [i for i, x in enumerate(h) if x == c]
b = [i for i, x in enumerate(w) if x == d]

flag = False
for s in a:
  for t in b:
    if l[s][t] == 0:
      flag = True
      break
if flag:
  ans = c+d
else:
  ans = c+d-1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

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:
h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(m)]
hlist = [0]*h
wlist = [0]*w
hwlist = [[0]*w for _ in range(h)]
for i in hw:
    hlist[i[0]-1]+=1
    wlist[i[1]-1]+=1
    hwlist[i[0]-1][i[1]-1]+=1

h_index = [n for n, v in enumerate(hlist) if v == max(hlist)]

w_index = [n for n, v in enumerate(wlist) if v == max(wlist)]

li = []
for i in h_index:
    for j in w_index:
        li += [hlist[i]+wlist[j]-int(hwlist[i][j]==1)]
print(max(li))

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())
ch = collections.Counter(h).most_common()
mh = [ch[0][0]]
mnh = ch[0][1]
for i in range(1,len(ch)):
    if mnh == ch[i][1]:
        mh.append(ch[i][0])
        continue
    else:
        break
    break
cw = collections.Counter(w).most_common()
mw = [cw[0][0]]
mnw = cw[0][1]
for i in range(1,len(mh)):
    if mnw == cw[i][1]:
        mw.append(cw[i][0])
        continue
    else:
        break
    break
for h1 in mh:
    for w1 in mw:
        if (h1,w1) not in zip(h,w):
            print(mnh+mnw)
            exit()
print(mnh+mnw-1)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
mh = [None]*m
mw = [None]*m
bomb = {}
ans = 0

for i in range(m):
    mh[i], mw[i] = map(int, input().split())
    if mh[i] in bomb:
        bomb[mh[i]] += 1
    else:
        bomb[mh[i]] = 1

dele = max(bomb, key=bomb.get)
num = bomb[dele]
bomb2 = {}
for i in range(m):
    if mh[i] == dele:
        continue
    if mw[i] in bomb2:
        bomb2[mw[i]] += 1
    else:
        bomb2[mw[i]] = 1
max_v = max(bomb2.values())
total = num + max_v
ans = max(ans, total)

print(ans)

Submission status: Runtime Error

Solution code:
import collections
a = list(map(int,input().split()))
h = a[0]
w = a[1]
m = a[2]
ch = 0

xy = [map(int, input().split()) for _ in range(m)]
x, y = [list(i) for i in zip(*xy)]
xc=collections.Counter(x)
yc=collections.Counter(y)
x_m = xc.most_common()[0]
y_m = yc.most_common()[0]

xd = x_m[0]
yd = y_m[0]

if x_m[1]==xc.most_common()[1][1]:
  xd = xc.most_common()[0][0]
  ch=1

if y_m[1]==yc.most_common()[1][1]:
  yd = yc.most_common()[0][0]    
  ch=1
    
if ch == 0:
  wa = x_m[1]+y_m[1]
else:
  wa = x.count(xd)+y.count(yd)

for i in  range(m):
  if x[i]==xd and y[i]==yd:
    wa=wa-1
    
print(wa)