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=map(int,input().split())
g=[]
e1=[0]*h
e2=[0]*w
for c in range(m):
    a,b=map(int,input().split())
    g.append([a-1,b-1])
    e1[a-1]+=1
    e2[b-1]+=1
p1=max(e1)
p2=max(e2)
x=[c for c in range(h) if e1[c]==p1]
y=[c for c in range(w) if e2[c]==p2]
if len(x)*len(y)>m:
    print(p1+p2)
    exit()
for i in x:
    for j in y:
        if [i,j] not in g:
            print(p1+p2)
            exit()
print(p+q-1)

Submission status: Runtime Error

Solution code:
import sys
H, W, M= map(int,input().split())
height = [0] * H
width = [0] * W
object = []
for i in range(H):
   wi = [0] * W
   object.append(wi)
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 = h_max + w_max          
else:
   ans += 1
print(ans)

Submission status: Runtime Error

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

nh = [0] * M # number of h == i+1
nw = [0] * M # number of w == i+1

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

mnh = max(nh)
mnw = max(nw)

mh = [i for i, nh1 in enumerate(nh) if nh1 == mnh]
mw = [i for i, nw1 in enumerate(nw) if nw1 == mnw]

hw = list(zip(h,w))
for h1 in mh:
    for w1 in mw:
        if (h1,w1) not in hw:
            print(mnh+mnw)
            exit()
print(mnh+mnw-1)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
for _ in range(m):
    h, w = map(int, input().split())
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    if h_l[h][0] == max_h:
        max_h_l.append(h)
            
 
        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    if w_l[w][0] == max_w:
        max_w_l.append(w)
 
 
flag = 0
ans = 0
for i in max_h_l:
    if flag == 1:
        break
    for j in max_w_l:
        if flag == 1:
            break
        if j in h_l[i][1]:
            ans = max_h + max_w - 1
        else:
            ans = max_h + max_w
            flag = 1
print(ans)
h, w, m = map(int, input().split())
h_l = [[] for i in range(h + 1)]
w_l = [[] for i in range(w + 1)]
max_h = 0
max_h_l = []
max_w = 0
max_w_l = []
for _ in range(m):
    h, w = map(int, input().split())
    if h_l[h] :
        h_l[h][1].append(w)
        h_l[h][0] += 1
    else:
        h_l[h] = [1, [w]]
        
    if h_l[h][0] > max_h:
        max_h_l = [h]
        max_h = h_l[h][0]
    if h_l[h][0] == max_h:
        max_h_l.append(h)
            

        
    if w_l[w]:
        w_l[w][1].append(h)
        w_l[w][0] += 1
    else:
        w_l[w] = [1, [h]]
    if w_l[w][0] > max_w:
        max_w_l = [w]
        max_w = w_l[w][0]
    if w_l[w][0] == max_w:
        max_w_l.append(w)


flag = 0
ans = 0
for i in set(max_h_l):
    if flag == 1:
        break
    for j in set(max_w_l):
        if flag == 1:
            break
        if j in h_l[i][1]:
            ans = max_h + max_w - 1
        else:
            ans = max_h + max_w
            flag = 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools


def pd(s):
    #print(s)
    pass


# input
H, W, M = map(int, input().split())
ms = [
    [int(i) for i in input().split()]
    for m in range(M)
]
pd(f"{H=} {W=} {M=}")
pd(f"{ms=}")

rows = [0]*(H+1)
cols = [0]*(W+1)
bombs = np.zeros((H+1,W+1))
for h,w in ms:
    rows[h] += 1
    cols[w] += 1
    bombs[h][w] = True

rmax = max(rows)
cmax = max(cols)
rmax_hs = [i for i, v in enumerate(rows) if v == rmax]
cmax_wh = [i for i, v in enumerate(cols) if v == cmax]

for h,w in itertools.product(rmax_hs, cmax_wh):
    if bombs[h][w] == 0:
        print(rmax + cmax)
        exit()
print(rmax + cmax - 1)

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
C,R=[],[]
CR=[]
d=[[0]*w for i in range(h)]
d_C=[0]*h
d_R=[0]*w
for i in range(m):
  c,r=map(int,input().split())
  d_C[c-1]+=1
  d_R[r-1]+=1
  d[c-1][r-1] = 1

c_max = max(d_C)
r_max = max(d_R)

c_list,r_list=[],[]
for i in range(h):
  if d_C[i] == c_max:
    c_list.append(i)
for i in range(w):
  if d_R[i] == r_max:
    r_list.append(i)

ans = c_max + r_max
for i in c_list:
  for j in r_list:
    if d[i][j] == 0:
      print(ans)
      exit()
print(ans-1)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import sys

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

y_to_num = [0] * h
x_to_num = [0] * w
existing_h_to_w = defaultdict(set)


for _ in range(m):
    hh, ww = map(lambda x: int(x), input().split())
    y_to_num[hh-1] += 1
    x_to_num[ww-1] += 1
    existing_h_to_w[hh].add(ww)

max_vertical_num = max(y_to_num)
max_horizontal_num = max(x_to_num)

y_coor_with_max_num = [i for i, num in enumerate(y_to_num) if num == max_vertical_num]
x_coor_with_max_num = [i for i, num in enumerate(x_to_num) if num == max_horizontal_num]

if (len(y_coor_with_max_num) >=2) | (len(x_coor_with_max_num) >= 2):
    print(max_vertical_num + max_horizontal_num)
    sys.exit()

if (x_coor_max_num[0] in existing_h_to_w[y_coor_with_max_num[0]]):
    print(max_vertical_num + max_horizontal_num - 1)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

h = []
w = []
for _ in range(M):
    x, y = map(int, input().split())
    h.append(x)
    w.append(y)

ch = Counter(h)
cw = Counter(w)

h_max = max(ch.values())
w_max = max(cw.values())

h_idx = [x for (x, y) in ch.items() if y == h_max]
w_idx = [x for (x, y) in cw.items() if y == w_max]

boms = set([(x, y) for x, y in zip(h, w)])

minus = []
for x in h_idx:
    for y in w_idx:
        if (x, y) in boms:
            minus.append(-1)

print(h_max + w_max + max(minus))

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools


def pd(s):
    #print(s)
    pass


# input
H, W, M = map(int, input().split())
ms = [
    [int(i) for i in input().split()]
    for m in range(M)
]
pd(f"{H=} {W=} {M=}")
pd(f"{ms=}")

rows = [0]*(H+1)
cols = [0]*(W+1)
bombs = np.zeros((H+1,W+1))
for h,w in ms:
    rows[h] += 1
    cols[w] += 1
    bombs[h][w] += 1

rmax = max(rows)
cmax = max(cols)
rmax_hs = [i for i, v in enumerate(rows) if v == rmax]
cmax_wh = [i for i, v in enumerate(cols) if v == cmax]

for h,w in itertools.product(rmax_hs, cmax_wh):
    if bombs[h][w] == 0:
        print(rmax + cmax)
        exit()
print(rmax + cmax - 1)

Submission status: Runtime Error

Solution code:
#import numpy as np
import collections
#import math




#f = open('./input_E.txt')
#
#H,W,M=map(int, f.readline().split())
#bakuha = []
#bakuha_H=[]
#bakuha_W=[]
#for i in range(M):
#    hh,ww=map(int, f.readline().split())
#    bakuha_H.append(hh)
#    bakuha_W.append(ww)
#    bakuha.append([hh,ww])




H,W,M=map(int, input().split())
bakuha = []
bakuha_H=[]
bakuha_W=[]
for i in range(M):
    hh,ww=map(int, input().split())
    bakuha_H.append(hh)
    bakuha_W.append(ww)
    bakuha.append([hh,ww])





count_H = collections.Counter(bakuha_H)
H_most = count_H.most_common()
H_most_num = H_most[0][1]

#H_only_most = [x for x in H_most if x[1]==H_most_num]
#H_kouho = [x[0] for x in H_only_most]

H_kouho = [x[0] for x in H_most if x[1]==H_most_num]


count_W = collections.Counter(bakuha_W)
W_most = count_W.most_common()
W_most_num = W_most[0][1]

#W_only_most = [x for x in W_most if x[1]==W_most_num]
#W_kouho = [x[0] for x in W_only_most]
W_kouho = [x[0] for x in W_most if x[1]==W_most_num]

ans = H_most_num + W_most_num

#マイナス1するかどうか
ans_minus = True

len_H_kouho=len(H_kouho)
len_W_kouho=len(W_kouho)
num_kouho = len_H_kouho*len_W_kouho

bakuha_1d = [W * (x[0]-1) + x[1] for x in bakuha]
bakuha_1d.sort()
bakuha_1d_max = bakuha_1d[-1]
bakuha_1d_min = bakuha_1d[0]

if num_kouho <= M:
    kouho_1d = []
    for h_k in H_kouho:
        for w_k in W_kouho:
            kouho_1d.append(W*(h_k-1)+w_k)
    kouho_1d.sort()
    kouho_1d_max = kouho_1d[-1]
    kouho_1d_min = kouho_1d[0]
    
    
    if kouho_1d_max <= bakuha_1d_max and kouho_1d_min >= bakuha_1d_min:
        for k1 in kouho_1d:
            tuzuku = True
            while tuzuku:
                b1_0 = bakuha_1d.pop(0)
                if b1_0 >= k1:
                    tuzuku = False
                    if b1_0 != k1:
                        ans_minus = False
    else:
        ans_minus = False
        
        
        
else:
    ans_minus = False
#
#if ans_minus:
#    ans-=1
    

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools


def pd(s):
    #print(s)
    pass


# input
H, W, M = map(int, input().split())
ms = [
    [int(i) for i in input().split()]
    for m in range(M)
]
pd(f"{H=} {W=} {M=}")
pd(f"{ms=}")

rows = [0]*(H+1)
cols = [0]*(W+1)
bombs = np.zeros((H+1,W+1))
for h,w in ms:
    rows[h] += 1
    cols[w] += 1
    bombs[m[0]][m[1]] += 1

rmax = max(rows)
cmax = max(cols)
rmax_hs = [i for i, v in enumerate(rows) if v == rmax]
cmax_wh = [i for i, v in enumerate(cols) if v == cmax]

for h,w in itertools.product(rmax_hs, cmax_wh):
    if bombs[h][w] == 0:
        print(rmax + cmax)
        exit()
print(rmax + cmax - 1)

Submission status: Runtime Error

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

nh = [0] * M # number of h == i+1
nw = [0] * M # number of w == i+1

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

mnh = max(nh)
mnw = max(nw)

mh = [i for i, nh1 in enumerate(nh) if nh1 == mnh]
mw = [i for i, nw1 in enumerate(nw) if nw1 == mnw]

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:
# -*- coding: utf-8 -*-
import numpy as np
import sys
def input(): return sys.stdin.readline().strip()


H, W, M = [int(x) for x in input().split()]
init = np.zeros((H,W))

for i in range(M):
  x, y = [int(x)-1 for x in input().split()]
  init[x,y] = 1

#print(init)

row = np.sum(init, axis=1)
col = np.sum(init, axis=0)

max_H = np.where(row == row.max())[0]
max_W = np.where(col == col.max())[0]
#print("len_H:{}".format(len(max_H)))
#print("len_W:{}".format(len(max_W)))

before_point = 0
max_point = row[max_H[0]] + col[max_W[0]]
#print(max_point)
"""
if len(max_H) != 1 or len(max_W) != 1:
  for h in max_H:
    for w in max_W:
      point = row[h] + col[w]
      point -= init[h,w]
      if point > before_point:
        max_point = point
      before_point = point
else:
  """
max_point -= init[max_H[0],max_W[0]]
  
print(int(max_point))

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):
   wi = [0] * W
   object.append(wi)
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 = h_max + w_max          
else:
   ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
def input(): return sys.stdin.readline().strip()


H, W, M = [int(x) for x in input().split()]
init = np.zeros((H,W))

for i in range(M):
  x, y = [int(x)-1 for x in input().split()]
  init[x,y] = 1

#print(init)

row = np.sum(init, axis=1)
col = np.sum(init, axis=0)

max_H = np.where(row == row.max())[0]
max_W = np.where(col == col.max())[0]
print("len_H:{}".format(len(max_H)))
print("len_W:{}".format(len(max_W)))

before_point = 0
max_point = row[max_H[0]] + col[max_W[0]]
print(max_point)
"""
if len(max_H) != 1 or len(max_W) != 1:
  for h in max_H:
    for w in max_W:
      point = row[h] + col[w]
      point -= init[h,w]
      if point > before_point:
        max_point = point
      before_point = point
else:
  """
max_point -= init[max_H[0],max_W[0]]
  
print(int(max_point))

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
H_max = [0 for _ in range(H+1)]
W_max = [0 for _ in range(W+1)]
A = []
for _ in range(M):
    i, k = map(int, input().split())
    A.append((i,k))
    H_max[k] += 1
    W_max[i] += 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 (h, w) in A:
            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:
import numpy as np
h,w,m=map(int,input().split())

lwh1=[[0]*w]*h
lwh2=[[0]*w]*h
lwh3=[[0]*w for i in range(h)]

for i in range(m):
    h1,w1=map(int,input().split())
    h1,w1=h1-1,w1-1
    lwh1[h1][w1]+=1
    lwh2[w1][h1]+=1
    lwh3[h1][w1]-=1

lwh1 = np.array(lwh1)
lwh2 = np.array(lwh2).T
lwh3 = np.array(lwh3)

ll=lwh1+lwh2+lwh3

print(ll.max())

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):
   wi = [0] * W
   object.append(wi)
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 = h_max + w_max
            break
            break           
else:
   ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
mport copy
import sys
H, W, M= map(int,input().split())
height = [0] * H
width = [0] * W
object = []
for i in range(H):
   wi = [0] * W
   object.append(wi)
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 = h_max + w_max
            break
            break           
else:
   ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []
 
for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
  
countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)
 
leftkeys = [k for k, v in countleft.items() if v == leftmax]
rightkeys = [k for k, v in countright.items() if v == rightmax]
 
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)
#これで左右の最頻回数はOK
#左右の最頻奴も探した
#ここから最頻同志になってるやつを探す
 
for T in range(M):
    if c[T][0] in leftkeys:
      if c[T][1] in rightkeys:
        cnt = cnt + 1
      else:
        pass
    else:
      pass
 
 
if cnt == int(leftkeyN * rightkeyN):
    print(int(tempmax - 1))
else:
    print(int(tempmax)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]

lwh1=[[0]*w]*h
lwh2=[[0]*w]*h
lwh3=[[0]*w for i in range(h)]

for i in range(m):
    h1,w1=l[i][0]-1,l[i][1]-1
    lwh1[h1][w1]+=1
    lwh2[w1][h1]+=1
    lwh3[h1][w1]-=1

lwh1 = np.array(lwh1)
lwh2 = np.array(lwh2).T
lwh3 = np.array(lwh3)

ll=lwh1+lwh2+lwh3

print(ll.max())

Submission status: Runtime Error

Solution code:
import collections
h,w,m=map(int,input().split())
C,R=[],[]
CR=[]
d=[[0]*w for i in range(h)]
for i in range(m):
  c,r=map(int,input().split())
  C.append(c-1)
  R.append(r-1)
  d[c-1][r-1] = 1
C_coll=collections.Counter(C)
R_coll=collections.Counter(R)
c=C_coll.most_common()
r=R_coll.most_common()
c_max = c[0][1]
r_max = r[0][1]
c_list,r_list=[],[]
for i in c:
  if i[1]==c_max:
    c_list.append(i[0])
  else:break
for i in r:
  if i[1]==r_max:
    r_list.append(i[0])
  else:break
ans = c_max + r_max
for i in c_list:
  for j in r_list:
    if d[i][j] == 0:
      print(ans)
      exit()
print(ans-1)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = {}
flag = 0

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

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if (i[0], j[0]) not in m.keys():
            flag = 1
            break

if flag == 1:
    print(h_max + w_max)
else:
    print(h_max + w_max - 1)

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
  h, w, m = map(int, input().split())
  graph = np.zeros((h, w), dtype='int64')
  row_sum = np.zeros(h, dtype='int64')
  col_sum = np.zeros(w, dtype='int64')

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

  #print(row_sum)
  #print(col_sum)

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

  result = max_row+max_col

  ris = np.where(row_sum == max_row)
  cis = np.where(col_sum == max_col)
  
  #print(ris)
  #print(cis)

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

Submission status: Runtime Error

Solution code:
x,y,m = map(int,input().split())
row = {}
ch = set()
column = {}
for i in range(m):
	h,k = map(int,input().split())
	ch.add((h,k))
	if h in row:
		row[h] += 1
	else:
		row[h] = 1
 
	if k in column:
		column[k] += 1
	else:
		column[k] = 1
 
 
r_max = 0
c_max = 0
 
for i in row:
	r_max = max(r_max,row[i])
for j in column:
	c_max = max(c_max,column[j])
 
r_inx = []
w_inx = []
 
for i in row:
	if row[i] == r_max:
		r_inx.append(i)
for j in column:
	if column[j] == c_max:
		w_inx.append(j)
 
flag = 0
for i in r_inx:
	for j in w_inx:
		if (i,j) not in ch:
			flag = 1
			break
if flag == 0:
	print(r_max+c_max-1)
else:
	print(r_max+c_max)
x,y,m = map(int,input().split())
row = {}
ch = set()
column = {}
for i in range(m):
	h,k = map(int,input().split())
	ch.add((h,k))
	if h in row:
		row[h] += 1
	else:
		row[h] = 1

	if k in column:
		column[k] += 1
	else:
		column[k] = 1


r_max = 0
c_max = 0

for i in row:
	r_max = max(r_max,row[i])
for j in column:
	c_max = max(c_max,column[j])

r_inx = []
w_inx = []

for i in row:
	if row[i] == r_max:
		r_inx.append(i)
for j in column:
	if column[j] == c_max:
		w_inx.append(j)

flag = 0

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
def input(): return sys.stdin.readline().strip()


H, W, M = [int(x) for x in input().split()]
init = np.zeros((H,W))

for i in range(M):
  x, y = [int(x)-1 for x in input().split()]
  init[x,y] = 1

#print(init)

row = np.sum(init, axis=1)
col = np.sum(init, axis=0)

max_H = np.where(row == row.max())[0]
max_W = np.where(col == col.max())[0]
#print(max_H)
#print(max_W)

before_point = 0
max_point = row[max_H[0]] + col[max_W[0]]
#print(max_point)

if len(max_H) != 1 or len(max_W) != 1:
  for h in max_H:
    for w in max_W:
      point = row[h] + col[w]
      point -= init[h,w]
      if point > before_point:
        max_point = point
      before_point = point
else:
  for h in max_H:
    for w in max_W:
      max_point -= init[h,w]
  
print(int(max_point))

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = {}
ans = 0

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

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if (i[0], j[0]) in m.keys():
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp

print(int(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
h,w,m=map(int,input().split())
objs=[tuple(map(int,input().split())) for i in range(m)]
setobj=set(objs)
xs,ys=zip(*objs)

from collections import Counter as co

wk,wv= co(ys).most_common(1)[0]
hk,hv= co(ys).most_common(1)[0]
print(wv+kv-(hk,wk)in setobj)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = {}
ans = 0

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

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))

for i in h_max_index:
    for j in w_max_index:
        if (i[0]], [j[0]) in m.keys():
            tmp = h_max + w_max -1
        else:
            tmp = h_max + w_max
        if ans < tmp:
            ans = tmp

print(int(ans))

Submission status: Runtime Error

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

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 s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object.append([h-1, w-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 not [cand_h[i], [cand_w[j]] in object:
            ans = h_max + w_max            
else:
   ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
H, W, m = map(int, input().split())
hs = [0] * (H+1)
ws = [0] * (W+1)
fs = [[0]*(W+1) for i in range(H+1)]
for i in range(m):
    hi,wi = map(int, input().split())
    hs[hi-1] += 1
    ws[wi-1] += 1
    fs[hi-1][wi-1] += 1

Submission status: Runtime Error

Solution code:
h,w,m = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
bomb = set()
h_list = [0] * (h+1)
w_list = [0] * (w+1)
for H,W in hw:
  h_list[H] += 1
  w_list[W] += 1
  bomb.add((H,W))
max_h = max(h_list)
max_w = max(w_list)
maxh_list = []
maxw_list = []
for k,v in enumerate(h_list):
  if v == max_h:
    maxh_list.append(k)
for k,v in enumerate(w_list):
  if v == max_w:
    maxw_list.append(k)
if len(maxh_list) * len(maxv_list) > m:
  ans = max_h * max_w
else:
  ans = max_h * max_w - 1
  for i in maxh_list:
    for j in maxw_list:
      if (i,j) not in bomb:
        ans = max_h * max_w
        break
print(ans)

Submission status: Runtime Error

Solution code:
#import numpy as np
import collections
#import math




#f = open('./input_E.txt')
#
#H,W,M=map(int, f.readline().split())
#bakuha = []
#bakuha_H=[]
#bakuha_W=[]
#for i in range(M):
#    hh,ww=map(int, f.readline().split())
#    bakuha_H.append(hh)
#    bakuha_W.append(ww)
#    bakuha.append([hh,ww])



#
H,W,M=map(int, input().split())
bakuha = []
bakuha_H=[]
bakuha_W=[]
for i in range(M):
    hh,ww=map(int, input().split())
    bakuha_H.append(hh)
    bakuha_W.append(ww)
    bakuha.append([hh,ww])





count_H = collections.Counter(bakuha_H)
H_most = count_H.most_common()
H_most_num = H_most[0][1]

#H_only_most = [x for x in H_most if x[1]==H_most_num]
#H_kouho = [x[0] for x in H_only_most]

H_kouho = [x[0] for x in H_most if x[1]==H_most_num]


count_W = collections.Counter(bakuha_W)
W_most = count_W.most_common()
W_most_num = W_most[0][1]

#W_only_most = [x for x in W_most if x[1]==W_most_num]
#W_kouho = [x[0] for x in W_only_most]
W_kouho = [x[0] for x in W_most if x[1]==W_most_num]

ans = H_most_num + W_most_num

#マイナス1するかどうか
ans_minus = True

len_H_kouho=len(H_kouho)
len_W_kouho=len(W_kouho)
num_kouho = len_H_kouho*len_W_kouho

bakuha_1d = [W * (x[0]-1) + x[1] for x in bakuha]
bakuha_1d.sort()
bakuha_1d_max = bakuha_1d[-1]

if num_kouho <= M:
    kouho_1d = []
    for h_k in H_kouho:
        for w_k in W_kouho:
            kouho_1d.append(W*(h_k-1)+w_k)
    kouho_1d.sort()
    kouho_1d_max = kouho_1d[-1]
    
    if kouho_1d_max <= bakuha_1d_max:
        for k1 in kouho_1d:
            tuzuku = True
            while tuzuku:
                b1_0 =bakuha_1d.pop(0)
                if b1_0 >= k1:
                    tuzuku = False
                    if b1_0 != k1:
                        ans_minus = False
    else:
        ans_minus = False
else:
    ans_minus = False

if ans_minus:
    ans-=1
    

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 s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object.append([h-1, w-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 not [cand_h[i], [cand_w[j] in object:
            ans = h_max + w_max            
else:
   ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
H, W, m = map(int, input().split())
hs = [0] * (H+1)
ws = [0] * (W+1)
fs = [[0]*(W+1) for i in range(H+1)]
for i in range(m):
    hi,wi = map(int, input().split())
    hs[hi-1] += 1
    ws[wi-1] += 1
    fs[hi-1][wi-1] += 1

hmx = max(hs)
hset = set()
for i,h in enumerate(hs):
    if h == hmx:
        hset.add(i)
wmx = max(ws)
wset = set()
for j, w in enumerate(ws):
    if w == wmx:
        wset.add(j)

flg = False
ans = 0
cnt = 0
for i in hset:
    for j in wset:
        ans = max(ans, hmx+wmx-fs[i][j]) 
        if cnt >= m:
            flg = True
            break
        cnt += 1
    if flg:break

print(ans)

Submission status: Runtime Error

Solution code:
h, w, m=map(int,input().split())
H=[0]*h
W=[0]*w
HW=[]
for i in range(m) :
    h_, w_=map(int,input().split())
    H[h_-1]+=1
    W[w_-1]+=1
    HW.append([h_-1,w_-1])
    
maxH=max(H)
maxW=max(W)

mh=[i for i,v in enumerate(H) if v==maxH]
mw=[i for i,v in enumfrate(W) if v==maxW]

for i in mh :
    for j in mw :
        if [i,j] not in HW :
            print(maxH+maxW)
            exit()
print(maxH+maxW-1)

Submission status: Runtime Error

Solution code:
H, W, m = map(int, input().split())
hs = [0] * (H+1)
ws = [0] * (W+1)
fs = [[0]*(W+1) for i in range(H+1)]
for i in range(m):
    hi,wi = map(int, input().split())
    hs[hi-1] += 1
    ws[wi-1] += 1
    fs[hi-1][wi-1] += 1

N = 10**6
hmx = max(hs)
hset = set()
for h in hs:
    if h == hmx:
        hset.add(h)
wmx = max(ws)
wset = set()
for w in ws:
    if w == wmx:
        wset.add(w)

flg = False
ans = 0
cnt = 0
for i in hset:
    for j in wset:
        ans = max(ans, hmx+wmx-fs[i][j]) 
        if cnt >= m:
            flg = True
            break
        cnt += 1
    if flg:break

print(ans)