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(e) for e in input().split()]

htotal = [0] * h
wtotal = [0] * w


hmax = 0
wmax = 0

s = set()
hl = []
wl = []

for i in range(m):
    hi, wi = [int(e) for e in input().split()]
    hi -= 1
    wi -= 1

    s.add((hi, wi))
    htotal[hi] += 1
    wtotal[wi] += 1

    if htotal[hi] > hmax:
        hmax = htotal[hi]
        hl = [hi]
    elif htotal[hi] == hmax:
        hl.append(hi)

    if wtotal[hi] > wmax:
        wmax = wtotal[wi]
        wl = [hi]
    elif wtotal[wi] == wmax:
        wl.append(wi)

m = hmax + wmax - 1
for he in hl:
    if m == hmax + wmax:
        break
    for we in wl:
        if m == hmax + wmax:
            break
        if not (he, we) in s:
            m += 1

print(m)

Submission status: Runtime Error

Solution code:
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
# mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file = 1




    
def solve():

    
    # for _ in range(ii()):

        h,w,m=mi()
        row=[0]*h
        col=[0]*w
        vis=[[0]*w for i in range(h)]
        for i in range(m):
            x,y=mi()
            x -= 1
            y -= 1
            row[x] +=1
            col[y] +=1
            vis[x][y]=1
        ans = 0
        for i in range(h):
            for j in range(w):
                if vis[x][y]==0:
                    ans = max(ans,row[i]+col[j])
                else:
                    ans = max(ans,(row[i]+col[j]-1))
        print(ans)












        
if __name__ =="__main__":

    if(file):

        if path.exists('input.txt'):
            sys.stdin=open('input.txt', 'r')
            sys.stdout=open('output.txt','w')
        else:
            input=sys.stdin.readline
    solve()

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m=map(int,input().split())
data=np.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
for i in range(h):
    for j in range(w):
        cnt=0
        for a in range(h):
            for b in range(w):
                if i==a or j==b:
                    cnt+=data[a][b]
        ans=max(ans,cnt)
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

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

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



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

for h in range(H):
    if h_sums[h] < h_sum_max:
        continue
    for w in range(W):
        if w_sums[w] < w_sum_max:
            continue
        if G[h][w] == 0:
            print(int(h_sum_max + w_sum_max))
            import sys; sys.exit(0)
print(int(h_sum_max + w_sum_max - 1))

Submission status: Runtime Error

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

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

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1
    board[h][w] = 1

h_mx = max(h_cnt)
w_mx = max(w_cnt)

cnt = h_cnt.count(h_mx) * w_cnt.count(w_mx)
for h, w in hw:
    val = h_cnt[h] + w_cnt[w]
    if val == h_mx + w_mx:
        cnt -= 1

if cnt:
    ans = h_mx + w_mx
else:
    ans = h_mx + w_mx - 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys

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

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

w = [0] * W
h = [0] * H

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

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

Submission status: Runtime Error

Solution code:
import numpy

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

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

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


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

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

Submission status: Runtime Error

Solution code:
H, W, M = (int(i) for i in input().split())

hw = [0] * (H * W)
hh = [0] * H
ww = [0] * W

for i in range(M):
    ht , wt = (int(i) for i in input().split())
    hw[(ht-1) * W + wt - 1] = 1
    hh[ht-1] += 1
    ww[wt-1] += 1

hhh = max(hh)
ih = [i for i, x in enumerate(hh) if x == hhh]

www = max(ww)
iw = [i for i, x in enumerate(ww) if x == www]

minus = 1
for iih in ih:
    for iiw in iw:
        if hw[iih * W + iiw] == 0:
            minus = 0


print(hhh + www - minus)

Submission status: Runtime Error

Solution code:
h,w,m = map(int,input().split())
pos = [tuple(map(int,input().split())) for _ in range(m)]
posh = np.zeros(h)
posw = np.zeros(w)
for hh,ww in pos:
    hh -= 1
    ww -= 1
    posh[hh]+= 1
    posw[ww] += 1
puth = np.argmax(posh)
putw = np.argmax(posw)
ans = (max(posh)+max(posw))
if (puth+1,putw+1) in pos:
    print(int(ans-1))
else:
    print(int(ans))

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
A = [[] for _ in range(W+1)]
H_max = [0 for _ in range(H+1)]
W_max = [0 for _ in range(W+1)]
for _ in range(M):
    i, k = map(int, input().split())
    A[i].append(k)
    H_max[i] += 1
    W_max[k] += 1
saidai_H = max(H_max)
possible_H = ([i for i, x in enumerate(H_max) if x == saidai_H])
saidai_W = max(W_max)
possible_W = ([i for i, x in enumerate(W_max) if x == saidai_W])
ans = True
for h in possible_H:
    for w in possible_W:
        if w in A[h]:
            continue
        else:
            ans = False
            break
if ans:
    print(saidai_H+saidai_W-1)
else:
    print(saidai_H+saidai_W)

Submission status: Runtime Error

Solution code:
#e
h,w,m=map(int,input().split())
hw=[]
hh=set()
ww=set()
hhh=[0]*h
www=[0]*w
for i in range(m):
    hi,wi=map(int,input().split())
    hi-=1
    wi-=1
    hh.add(hi)
    ww.add(wi)
    hhh[hi]+=1
    www[wi]+=1
    hw.append([hi,wi])
if len(hh)==1 or len(ww)==1:
    print(m)
else:
    ans=0
    maxh=max(hhh)
    for i in hh:
        if hhh[i]==maxh:
            wwww=www.copy()
            for j in range(m):
                if hw[j][0]==i:
                    wwww[hw[j][1]]-=1
            ansi=maxh+max(wwww)
            ans=max(ans,ansi)

print(ans)

Submission status: Runtime Error

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


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


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


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


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

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

Submission status: Runtime Error

Solution code:
#E
import numpy as np

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

num = [[0]*w for i in range(h)]

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

num = np.array(num)

Sumw = (np.sum(num , axis = 1))
Sumh = (np.sum(num , axis = 0))

point1  = np.argmax(Sumw)
point2  = np.argmax(Sumh)

if num[point2,point1] == 1:
    print(max(Sumw)+max(Sumh)-1)
else:
    print(max(Sumw)+max(Sumh))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import itertools
H, W, M = [int(j) for j in input().split()]
Hx = [0]*H
Wx = [0]*W
dict = [[0] * W for i in range(H)]
for i in range(M):
    h, w =  [int(j) for j in input().split()]
    dict[h-1][w-1]=1
    Hx[h-1] += 1
    Wx[w-1] += 1
maxIndex_Hx = [i for i, x in enumerate(Hx) if x == max(Hx)]
maxIndex_Wx = [i for i, x in enumerate(Wx) if x == max(Wx)]
ans = max(Hx)+ max(Wx)
flag = 1
#print(dict)
for j in list(itertools.product(maxIndex_Hx, maxIndex_Wx)):
    if dict[j[0]][j[1]] == 0:
        print(ans)
        flag = 0
        break
if flag:
    print(ans-1)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
h_cnt = [0] * h
w_cnt = [0] * w

mat = [[0] * w for i in range(h)]

for i in range(m):
    h_, w_ = map(int, input().split())
    h_ -= 1
    w_ -= 1
    h_cnt[h_] += 1
    w_cnt[w_] += 1
    mat[h_][w_] = 1

max_h = max(h_cnt)
max_h_idx = []
for i in range(h):
    if h_cnt[i] == max_h:
        max_h_idx.append(i)

max_w = max(w_cnt)
max_w_idx = []
for i in range(w):
    if w_cnt[i] == max_w:
        max_w_idx.append(i)

for i in max_h_idx:
    for j in max_w_idx:
        if mat[i][j] == 0:
            print(max_h + max_w)
            exit()
print(max_h + max_w - 1)

Submission status: Runtime Error

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

H=[0]*h
W=[0]*w
HW=[[0]*w for i in range(h)]
for mine in M:
    a=mine[0]-1
    b=mine[1]-1
    H[a]+=1
    W[b]+=1
    HW[a][b]+=1

maxh=max(H)
maxw=max(W)

maxhindex = []
maxwindex = []

for i in range(h):
    if H[i]==maxh:
        maxhindex.append(i)
for i in range(w):
    if W[i]==maxw:
        maxwindex.append(i)

end=0
for i in maxhindex:
    if end==1:
        break
    for j in maxwindex:
        if HW[i][j]==0:
            end=1
            break

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * W for i in range(H)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[hi-1][wi-1] = 1

Hbomb = [i for i, x in enumerate(Hdst) if x == max(Hdst)]
Wbomb = [i for i, x in enumerate(Wdst) if x == max(Wdst)]

ans = 0
for i in Hbomb:
    for j in Wbomb:
        if Hdst[i] + Wdst[j] - DST[i][j] > ans:
            ans = Hdst[i] + Wdst[j] - DST[i][j]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

    retu = Counter()
    gyo = Counter()

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

    for _ in range(M):
        a, b = map(int, input().split())
        retu[a-1] += 1
        gyo[b-1] += 1
        ipt[a-1][b-1] = 1

    rm = retu.most_common()
    rmm = rm[0][1]
    gm = gyo.most_common()
    gmm = gm[0][1]

    for r in rm:
        if r[1] < rmm:
            break
        for g in gm:
            if g[1] < gmm:
                break

            if ipt[r[1]][g[1]] == 0:
                return rmm+gmm
    
    return rmm+gmm-1

print(solver())

Submission status: Runtime Error

Solution code:
h,w,m=(int(i) for i in input().split())
l1=[]
l2=[0]*h
l3=[0]*w
for i in range(m):
    x,y=(int(i) for i in input().split())
    l1.append((x,y))
    l2[x-1]+=1
    l3[y-1]+=1
m1=max(l2)
m2=max(l3)
m3=max(m1,m2)
if(m3==m1):
    l4=[0]*w
    k=l2.index(m1)
    for i in range(m):
        if(l1[i][0]!=k+1):
           l4[l1[i][1]-1]+=1
    k1=max(l4)
    print(m1+k1)
else:
    l4=[0]*h
    k=l3.index(m2)
    for i in range(m):
        if(l1[i][0]!=k+1):
           l4[l1[i][1]-1]+=1
    k1=max(l4)
    k2=l4.index(k1)
    print(m2+k1)

Submission status: Runtime Error

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

z = []
Hc = [0]*m
Wc = [0]*m

for i in range(m):
    th,tw = map(int,input().split())
    z.append((th,tw))
    Hc[th-1] += 1
    Wc[tw-1] += 1

mh = max(Hc)
mw = max(Wc)
ans = 0
for i in range(len(Hc)):
    if Hc[i] != mh:
        continue
    for j in range(len(Wc)):
        if Wc[j] != mw:
            continue

        ans = Hc[i] + Wc[j]
        if (i+1,j+1) in z:
            ans -= 1
        else:
            break

print(ans)

Submission status: Runtime Error

Solution code:
import sys

r = list(map(int,input().split()))
h = r[0]
w = r[1]
m = r[2]
l = []

hl = [0 for i in range(m)]
wl = [0 for i in range(m)]

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

#print(l)
#print(hl)
#print(wl)

H = max(hl)
W = max(wl)

hlist = []
wlist = []

for i in range(m):
    if hl[i] == H:
        hlist.append(i+1)
    if wl[i] == W:
        wlist.append(i+1)

ans = H+W
##print(ans)
#print(hlist)
#print(wlist)

flag = 1

for i in range(len(hlist)):
    for j in range(len(wlist)):
        flag *= l.count([hlist[i],wlist[j]])

ans -= flag
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h,w,m=list(map(int, input().split()))
hl=[]
wl=[]
hc=[0]*h
wc=[0]*w
mp=[0]*(h*w)
for j in range(m):
    h1,w1=[int(j) for j in input().split()]
    hl.append(h1)
    wl.append(w1)
for i in range(m):
    x=hl[i]-1
    y=wl[i]-1
    z=y*h+x
    hc[x]+=1
    wc[y]+=1
    mp[z]+=1
mx=max(hc)
my=max(wc)
lmx=[]
lmy=[]
for p in range (h):
    if hc[p]==mx:
        lmx.append(p)
for q in range (w):
    if wc[q]==my:
        lmy.append(q)
zzx=len(lmx)
zzy=len(lmy)
zzz=1
for s in range(zzx):
    ss=lmx[s]
    for t in range(zzy):
        tt=lmy[t]
        uu=tt*h+ss
        if mp[uu]==0:
            zzz=0

print(mx+my-zzz)

Submission status: Runtime Error

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

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)

x_max = np.argmax(W_sum_)
y_max = np.argmax(H_sum_)

sum_ = W_sum_[x_max]+H_sum_[y_max]

if area[y_max][x_max] == 1:
    sum_ -= 1
    
print(sum_)

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan2, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    H, W, M = MAP()
    hw = [LIST() for _ in range(M)]

    x = defaultdict(int)
    y = defaultdict(int)

    for i, j in hw:
        x[i-1] += 1
        y[j-1] += 1

    A = [[-1]*W for _ in range(H)]

    for i, j in hw:
        A[i-1][j-1] = x[i-1] + y[j-1] - 1

    for i in range(H):
        for j in range(W):
            if A[i][j] == -1:
                A[i][j] = x[i] + y[j]
    
    ans = 0
    for li in A:
        ans = max(ans, max(li))
    

    print(ans)



if  __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

m = 0
for h in h_list:
    for w in w_list:
        if bomb[h, w]:
            m = max(m, sh[h] + sw[w] - 1)
        else:
            m = max(m, sh[h] + sw[w])

print(m)

Submission status: Runtime Error

Solution code:
import numpy as np

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

for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    L[a][b] = 1
L = np.array(L)
T = np.rot90(L,k =-1)
#print(L)
#print(T)

ans = 0
sum1 = 0
for i in range(h):
    
    for j in range(w):
        
        sum1 +=sum(L[i]) + sum(T[j])
        #print(L[i],T[j],sum1)
        if L[i][j] ==1:
            sum1 -=1
        ans = max(ans,sum1)
        sum1 = 0
print(ans)

Submission status: Runtime Error

Solution code:
h,w,m=list(map(int, input().split()))
hl=[]
wl=[]
hc=[0]*h
wc=[0]*w
mp=[0]*(h*w)
for j in range(m):
    h1,w1=[int(j) for j in input().split()]
    hl.append(h1)
    wl.append(w1)
for i in range(m):
    x=hl[i]-1
    y=wl[i]-1
    z=y*h+x
    hc[x]+=1
    wc[y]+=1
    mp[z]+=1
mx=max(hc)
my=max(wc)
lmx=[]
lmy=[]
for p in range (h):
    if hc[p]==mx:
        lmx.append(p)
for q in range (w):
    if wc[q]==my:
        lmy.append(q)
zzx=len(lmx)
zzy=len(lmy)
zzz=1
if zzx*zzy<=m:
    for s in range(zzx):
        ss=lmx[s]
        for t in range(zzy):
            tt=lmy[t]
            uu=tt*h+ss
            if mp[uu]==0:
                zzz=0
else:
    zzz=0
print(mx+my-zzz)

Submission status: Runtime Error

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


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


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


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


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

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

def filedplus(h,w,m,hw):
  field=np.zeros([h,w])
  
  for i in hw:
    bh=int(i[0])-1
    bw=int(i[1])-1

    field[bh,:]+=1
    field[:,bw]+=1
    field[bh,bw]-=1
  
  return(int(field.max()))

print(filedplus(h,m,m,hw))

Submission status: Runtime Error

Solution code:
n,m,k=map(int,input().split())
l=[]
for i in range(n):
    dd=[]
    for j in range(m):
        dd.append(0)
    l.append(dd)
for u in range(k):
    x,y=map(int,input().split())
    l[x-1][y-1]+=1
d=list(zip(*l))
for i in range(n):
    d[i]=list(d[i])
x=0
xx=-1
for i in range(n):
    x=max(x,l[i].count(1))
y=0
for i in range(n):
    y=max(y,d[i].count(1))
print(x+y-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
d1 = dict()
d2 = dict()
G = [[False] * (W + 1) for _ in range(H + 1)]
for i in range(M):
    h, w = map(int, input().split())
    if h not in d1:
        d1[h] = 0
    if w not in d2:
        d2[w] = 0
    d1[h] += 1
    d2[w] += 1
    G[h][w] = True

d1 = list(d1.items())
d2 = list(d2.items())

d1.sort(reverse=True, key=lambda x: x[1])
d2.sort(reverse=True, key=lambda x: x[1])

print(d1[0][1] + d2[0][1] - int(G[d1[0][0]][d2[0][0]]))

Submission status: Runtime Error

Solution code:
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################

HH,WW,MM = map(int, input().split())

H=[0] * HH
W=[0] * WW
M = [[0]*WW for i in range(HH)]

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

hm = max(H)
wm = max(W)

# _p(hm,wm)
# _pa(M)

HI = [i for i, x in enumerate(H) if x == hm]
WI = [i for i, x in enumerate(W) if x == wm]

# _p(HI)
# _p(WI)

ans = 0
for h in HI:
  for w in WI:
    ans = max(ans, hm + wm - M[h][w])

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import numpy as np

H,W,M=map(int,input().split())
V=np.zeros([H,W])

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

hs=[]
for i in range(H):
    hs.append(sum(V[i,:]))

ws=[]
for i in range(W):
    ws.append(sum(V[:,i]))

MH=max(hs)
MW=max(ws)
ans=MH+MW

mh=[]
for i in range(H):
    if hs[i]==MH:
        mh.append(i)
mw=[]
for i in range(W):
    if ws[i]==MW:
        mw.append(i)

add=1
for i in mh:
    for j in mw:
        if V[i,j]==0: 
            add=0
            break


ans-=add

print(int(ans))

Submission status: Runtime Error

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

h_list=[0]*H
w_list=[0]*W
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

ans=max(h_list)+max(w_list)-1

h_mx=[i for i, x in enumerate(h_list) if x == max(h_list)]
w_mx=[i for i, x in enumerate(w_list) if x == max(w_list)]

for i in h_mx:
    for j in w_mx:
        if place[i][j]==0:
            ans+=1
            break
    else:
        continue
    break

print(ans)

Submission status: Runtime Error

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

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

listh = [0 for i in range(H+1)]
listw = [0 for i in range(W+1)]
for k in range(M):
    listh[list1[k][0]]+=1

max1 = 0
loc1 = 0
for i in range(len(listh)):
    if max1 < listh[i]:
        max1 = listh[i]
        loc1 =  i

for k in range(M):
    if list1[k][0] == loc1:
        continue
    else:
        listw[list1[k][1]]+=1

max2 = 0
loc2 = 0
for i in range(len(listh)):
    if max2 < listw[i]:
        max2 = listw[i]
        loc2 =  i

print(max1 + max2)

Submission status: Runtime Error

Solution code:
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
##import numpy as np
#sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo 
##    else:
##        if(y > 0):return (x * temp * temp)%mo 
##        else:return ((temp * temp)//x )%mo
##
for _ in range(1):
    r,c,m=cin()
    d=dd(list)
    ro=[0]*r
    co=[0]*c
    mat=[[0]*c for i in range(r)]
    ans=0
    for i in range(m):
        x,y=cin()
        ro[x-1]+=1
        co[y-1]+=1
        mat[x-1][y-1]=1
    for i in range(r):
        for j in range(c):
            t=ro[i]+co[j]-mat[i][j]
            ans=max(ans,t)
    print(ans)

Submission status: Runtime Error

Solution code:
h,w,m = map(int,input().split())
l = [[0 for x in range(w)] for y in range(h)]
lx = [0 for x in range(w)]
ly = [0 for y in range(h)]
for i in range(m):
    x,y = map(int,input().split())
    lx[x-1] += 1
    ly[y-1] += 1
    l[y-1][x-1] = 1
t_x = max(lx)
t_y = max(ly)
flg = 0
for j in range(w):
    if lx[j] == t_x:
        for k in range(h):
            if ly[k] == t_y:
                if l[k][j] == 0:
                    flg = 1
if flg == 1:
    print(t_x+t_y)
else:
    print(t_x+t_y-1)

Submission status: Runtime Error

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

    bn_h = {}
    bn_v = {}

    for i in range(M):
        h, w = map(int, input().split())
        bn_h.setdefault(h, set())
        bn_h[h].add(w)
        bn_v.setdefault(w, set())
        bn_v[w].add(h)

    b1 = sorted(bn_h.items(), key = lambda x:len(x[1]), reverse=True)
    b2 = sorted(bn_v.items(), key = lambda x:len(x[1]), reverse=True)

    m1 = len(b1[0][1])
    m2 = len(b2[0][1])

    max_result = 0
    for i in b1:
        h, sh = i
        if len(sh) < m1:
            break
        for j in b2:
            v, sv = j
            if len(sv) < m2:
                break
            result = len(sh) + len(sv) - 1
            if h not in sv:
                result += 1
                flag = True
            max_result = max(max_result, result)
            if flag == True:
                break
        if flag == True:
            break
    print(max_result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np

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

'''
for i in range(h):
    print(a[i])
'''

Hs = []
greatH = 0
gHs = []
for i in range(h):
    x = np.sum( a[i,:] )
    Hs.append(x)
    if x > greatH:
        greatH = x
for i in range(h):
    if Hs[i] == greatH:
        gHs.append(i)
Ws = []
greatW = 0
gWs = []
for i in range(w):
    x = np.sum( a[:,i] )
    Ws.append(x)
    if x > greatW:
        greatW = x
for i in range(w):
    if 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 a[x][y] == 0:
            flag = 0

print( int(great - flag) )

Submission status: Runtime Error

Solution code:
from sys import stdin
readline = stdin.buffer.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:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

h,w,m = map(int,input().split())
grid = [[0] * w for i in range(h)]
# print(*grid,sep= "\n")
for _ in range(m):
  i,j = map(int,input().split())
  i-=1
  j-=1
  grid[i][j] += 1
tate = [0] * w
yoko = [0] * h
for i in range(h):
  yoko[i] = sum(grid[i])
for j in range(w):
  tmp = 0
  for i in range(h):
    tmp += grid[i][j]
  tate[j] = tmp
for i in range(h):
  for j in range(w):
    ans = max(ans,yoko[i] + tate[j]-grid[i][j])
print(ans)
# print(tate)
# print(yoko)

Submission status: Runtime Error

Solution code:
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
#print(grid)
max_h = 0
max_i = []
for i in range(1,h+1):
    #print(grid[i][1:])
    grid[i][0] = sum(grid[i][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)

max_w = 0
max_j = []
for j in range(1,w+1):
    tmp = 0
    for i in range(1,h+1):
        tmp += grid[i][j]
    grid[0][j] = tmp
    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)

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,ans)
print(max_h+max_w-ans)

Submission status: Runtime Error

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

flag=True
for i in tbox:
    for j in ybox:
        if box[i-1][j-1]==0:
            flag=False
if flag:
    print(tmax+ymax-1)
else:
    print(tmax + ymax)