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: Wrong Answer

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

H,W=[0]*h,[0]*w
P=set()

for i in range(m):
  y,x=map(int,input().split())
  H[~-y]+=1
  W[~-x]+=1
  P.add(~-y*w+~-x)

mh,mw=max(H),max(W)
for y in [i for i,v in enumerate(H) if v==mh]:
  for x in [i for i,v in enumerate(W) if v==mw]:
    if y*h+x not in P:
      exit()

print(mh+mw-1)

Submission status: Wrong Answer

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

H,W=[0]*h,[0]*w
P=set()

for i in range(m):
  y,x=map(int,input().split())
  H[~-y]+=1
  W[~-x]+=1
  P.add(~-y*w+~-x)

mh,mw=max(H),max(W)
for y in [i for i,v in enumerate(H) if v==mh]:
  for x in [i for i,v in enumerate(W) if v==mw]:
    print(y,x)
    if y*h+x not in P:
      print(mh+mw)
      exit()

print(mh+mw-1)

Submission status: Wrong Answer

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

mat=[]

for i in range(M):
  h, w = map(int, input().split())
  row[h-1]+=1
  col[w-1]+=1
  mat.append((h-1,w-1))
  
r=max(row)
c=max(col)

rr=[i for i in range(H) if row[i]==r]
cc=[i for i in range(W) if col[i]==c]

for k in mat:
  if rr.count(k[0])==0 or cc.count(k[1])==0:
    print(r+c)
    exit()

print(r+c-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import numba
import sys
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@njit((i8, i8, i8[:]), cache=True)
def main(Height, Width, XY):
    UP = 300010
    row = np.zeros(UP, np.int64)
    col = np.zeros(UP, np.int64)
    
    for i in range(0, len(XY), 2):
        x, y = XY[i:i + 2] - 1
        row[x] += 1
        col[y] += 1
    
    row_max = row.max()
    col_max = col.max()

    judge = np.sum(row == row_max) * np.sum(col == col_max)

    for i in range(0, len(XY), 2):
        x, y = XY[i:i + 2] - 1
        
        if (row[x] == row_max and col[y] == col_max):
            judge -= 1
    
    summ = row_max * col_max
    
    return (summ if judge else summ - 1)


Height, Width, M_ko = map(int, readline().split())
XY = np.array(read().split(), np.int64)

ans = main(Height, Width, XY)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import numba
import sys
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@njit((i8, i8, i8[:]), cache=True)
def main(Height, Width, XY):
    UP = 300000
    row = np.zeros(UP, np.int64)
    col = np.zeros(UP, np.int64)
    
    for i in range(0, len(XY), 2):
        x, y = XY[i:i + 2] - 1
        row[x] += 1
        col[y] += 1
    
    row_max = row.max()
    col_max = col.max()

    judge = np.sum(row == row_max) * np.sum(col == col_max)

    for i in range(0, len(XY), 2):
        x, y = XY[i:i + 2] - 1
        
        if (row[x] == row_max and col[y] == col_max):
            judge -= 1
    
    summ = row_max * col_max
    
    return (summ if judge else summ - 1)


Height, Width, M_ko = map(int, readline().split())
XY = np.array(read().split(), np.int64)

ans = main(Height, Width, XY)
print(ans)

Submission status: Wrong Answer

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

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

HMAX = 0
for i in range(H + 1):
    HMAX = max(HMAX, hl.count(i))
    if HMAX == hl.count(i): HPOS = i

WMAX = 0
for i in range(W + 1):
    WMAX = max(WMAX, wl.count(i))

print(HMAX + WMAX) if wl[hl.index(HPOS)] == WMAX else print(HMAX + WMAX - 1)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    H, W, M = LI()
    hw = LIR(M)

    s = set()
    for h, w in hw:
        s.add(h + w * (10 ** 7))

    ch = Counter([i for i, _ in hw])
    cw = Counter([j for _, j in hw])
    y, cy = ch.most_common(1)[0]
    x, cx = cw.most_common(1)[0]

    print(cy + cx - int(y + x * (10 ** 7) in s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    H, W, M = LI()
    hw = LIR(M)

    s = set()
    for h, w in hw:
        s.add(h + w * 10 ** 6)

    ch = Counter([i for i, _ in hw])
    cw = Counter([j for _, j in hw])
    y, cy = ch.most_common(1)[0]
    x, cx = cw.most_common(1)[0]

    print(cy + cx - int(y + x * 10 ** 6 in s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
b = []
for i in range(m):
    hh, ww = map(int,input().split())
    hh -= 1
    ww -= 1
    b.append([hh, ww])
    
cnth = [0] * h
cntw = [0] * w
          
for i in range(m):
    hh, ww = b[i][0], b[i][1]
    cnth[hh] += 1
    cntw[ww] += 1
    
mh = max(cnth)
mw = max(cntw)

ans = 0
for i in range(m):
    hh, ww = b[i][0], b[i][1]
    tmp = cnth[hh] + cntw[ww]
    if cnth[hh] == mh and cntw[ww] == mw:
        tmp -= 1
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
h, w, m = map(int, input().split())
target = []
point = defaultdict(int)
count_target_of_y = defaultdict(int)
count_target_of_x = defaultdict(int)
for i in range(m):
    x, y = map(int, input().split())
    count_target_of_y[y] += 1
    count_target_of_x[x] += 1
    point[(x,y)] += 1
max_x_count = max(list(count_target_of_x.items()),key=lambda x:x[1])
max_y_count = max(list(count_target_of_y.items()), key=lambda x:x[1])
if point[(max_x_count[0], max_y_count[0])]:
    print(max_x_count[1] + max_y_count[1] - 1)
else:
    print(max_x_count[1] + max_y_count[1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
h, w, m = map(int, input().split())
target = []
x_candidate = set()
y_candidate = set()
point = defaultdict(int)
count_target_of_y = defaultdict(int)
count_target_of_x = defaultdict(int)
for i in range(m):
    x, y = map(int, input().split())
    x_candidate.add(x)
    y_candidate.add(y)
    count_target_of_y[y] += 1
    count_target_of_x[x] += 1
    point[(x,y)] += 1
max_x_count = max(list(count_target_of_x.items()),key=lambda x:x[1])
max_y_count = max(list(count_target_of_y.items()), key=lambda x:x[1])
if point[(max_x_count[0], max_y_count[0])]:
    print(max_x_count[1] + max_y_count[1] - 1)
else:
    print(max_x_count[1] + max_y_count[1])

Submission status: Wrong Answer

Solution code:
def main():
    h, w, m, *BOM = map(int, open(0).read().split())
    row = [0] * h
    col = [0] * w
    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        row[i] += 1
        col[j] += 1

    p, q = max(row), max(col)
    rr = {i for i in range(h) if row[i] == p}
    rl = {i for i in range(w) if col[i] == q}

    ans = p + q
    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        if (row[i], col[j]) == (p, q) and not (i in rr and j in rl):
            break
    else:
        ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
for p in P:
    p[0] -= 1 
    p[1] -= 1
cnth = [0]*H
cntw = [0]*W
ans = 0
for p in P:
    cnth[p[0]] += 1
for p in P:
    cntw[p[1]] += 1 
mxh = max(cnth)
mxw = max(cntw)
f = False
for p in P:
    if cnth[p[0]] == mxh and cntw[p[1]] == mxw:
        f = True
if f:
    ans = mxh + mxw -1
else:
    ans = mxh + mxw
print(ans)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
for p in P:
    p[0] -= 1 
    p[1] -= 1
cnth = [0]*H
cntw = [0]*W
ans = 0
for p in P:
    cnth[p[0]] += 1
for p in P:
    cntw[p[1]] += 1
mxh = max(cnth)
mxw = max(cntw)
f = False
for p in P:
    if cnth[p[0]] == mxh:
        if cntw[p[1]] == mxw:
            f = True
if f:
    ans = mxh + mxw -1
else:
    ans = mxh + mxw
print(ans)

Submission status: Wrong Answer

Solution code:
m,n,tot=[int(i) for i in input().split()]
from collections import defaultdict
row=defaultdict(int)
col=defaultdict(int)
loc=[]
for k in range(tot):
    i,j=[int(t) for t in input().split()]
    row[i]+=1
    col[j]+=1
    loc.append([i,j])

k=[-1,-1]
r=[-1,-1]
for i in row.items():
    if i[1]>k[0]:
        k[0]=i[1]
        k[1]=i[0]

for j in col.items():
    if j[1]>r[0]:
        r[0]=j[1]
        r[1]=j[0]
#print(loc)
#print(k,r)
if [k[1],r[1]] in loc:
    print(k[0]+r[0]-1)
else:
    print(k[0]+r[0])

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
B=[]
for i in range(M):
    b=list(map(int,input().split()))
    B.append(b)
C=[]
for i in range(H):
    C.append(0)
R=[]
for i in range(W):
    R.append(0)
for i in range(M):
    C[B[i][0]-1]+=1
    R[B[i][1]-1]+=1
Cm=[i for i, v in enumerate(C) if v == max(C)]
Rm=[i for i, v in enumerate(R) if v == max(R)]
D=[]
for i in range(len(Cm)):
    for v in range(len(Rm)):
        D.append([Cm[i]+1,Rm[v]+1])
count=0
for i in range(len(D)):
    for v in range(M):
       if D[i]==B[v]:
           count+=1
if count == 0:
    print(max(C)+max(R))
else:
    print(max(C)+max(R)-1)

Submission status: Wrong Answer

Solution code:
# こんがらがりがちな貪欲？

h, w, m = map(int, input().split())
hs, ws = {}, {}
h_max, w_max = 0, 0
data = {}
for _ in range(m):
    hv, wv = map(int, input().split())
    data[(hv, wv)] = True
    if hv in hs:
        hs[hv] += 1
    else:
        hs[hv] = 1
    if wv in ws:
        ws[wv] += 1
    else:
        ws[wv] = 1
    h_max = max(h_max, hs[hv])
    w_max = max(w_max, ws[wv])
hss = sorted(hs.items(), key=lambda x: x[1])
wss = sorted(ws.items(), key=lambda x: x[1])

ok, ng = len(hss), 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if hss[mid][1] < h_max:
        ng = mid
    else:
        ok = mid
hi = hss[ok:]
ok, ng = len(wss), 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if wss[mid][1] < w_max:
        ng = mid
    else:
        ok = mid

wi = wss[ok:]

ans = 0
for wv in wi:
    wv = wv[0]
    for k, v in hss:
        tmp = w_max + v
        if (k, wv) in data:
            tmp -= 1
        ans = max(ans, tmp)
for hv in hi:
    hv = hv[0]
    for k, v in wss:
        tmp = h_max + v
        if (hv, k) in data:
            tmp -= 1
        ans = max(ans, tmp)
print(ans)

# oooxo
# oxxox
# oooox
# ooxoo
# xoxxx

Submission status: Wrong Answer

Solution code:
H,W,M = map(int, input().split())
width = [0]*W
height = [0]*H
nakatta = 0
mat = []
for i in range(M):
  x,y = map(int, input().split())
  mat.append((x,y))
  width[y-1] += 1
  height[x-1] += 1

indexW = [i for i, v in enumerate(width) if v == max(width)]
indexH = [i for i, v in enumerate(height) if v == max(height)]

ans = max(width) + max(height)

for i in indexW:
  for j in indexW:
    if (i,j) not in mat:
      nakatta = 1
      break

if nakatta == 1:
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
def sol(x,y):
    row = {}
    col = {}
    for i in x:
        if i not in row:
            row[i] = 1
        else:
            row[i] += 1
    for i in y:
        if i not in col:
            col[i] = 1
        else:
            col[i] += 1
    maxRow = 0
    maxCol = 0
    mR = 0
    mC = 0
    for i in row:
        if row[i]>mR:
            mR = row[i]
            maxRow = i
    for i in col:
        if col[i]>mC:
            mC = col[i]
            maxCol = i
    rd = set()
    cd = set()
    for i in row:
        if row[i] == mR:
            rd.add(i)
    for i in col:
        if col[i] == mC:
            cd.add(i)
    diff1 = rd.difference(cd)
    diff2 = cd.difference(rd)
    s = mR+mC
    if len(diff1) == 0 and len(diff2)==0:
        s-=1
        print(s)
        return
    print(s)
    return

x,y,z = list(map(int,input().split(' ')))
row = []
col = []
for i in range(z):
    p = list(map(int,input().split(' ')))
    row.append(p[0])
    col.append(p[1])
sol(row,col)

Submission status: Wrong Answer

Solution code:
def sol(x,y):
    row = {}
    col = {}
    for i in x:
        if i not in row:
            row[i] = 1
        else:
            row[i] += 1
    for i in y:
        if i not in col:
            col[i] = 1
        else:
            col[i] += 1
    maxRow = 0
    maxCol = 0
    mR = 0
    mC = 0
    for i in row:
        if row[i]>=mR:
            mR = row[i]
            maxRow = i
    for i in col:
        if col[i]>=mC:
            mC = col[i]
            maxCol = i
    s = mR+mC
    if maxCol == maxRow:
        s-=1
    print(s)

x,y,z = list(map(int,input().split(' ')))
row = []
col = []
for i in range(z):
    p = list(map(int,input().split(' ')))
    row.append(p[0])
    col.append(p[1])
sol(row,col)

Submission status: Wrong Answer

Solution code:
def sol(x,y):
    row = {}
    col = {}
    for i in x:
        if i not in row:
            row[i] = 1
        else:
            row[i] += 1
    for i in y:
        if i not in col:
            col[i] = 1
        else:
            col[i] += 1
    maxRow = 0
    maxCol = 0
    mR = 0
    mC = 0
    for i in row:
        if row[i]>mR:
            mR = row[i]
            maxRow = i
    for i in col:
        if col[i]>mC:
            mC = col[i]
            maxCol = i
    s = mR+mC
    if maxCol == maxRow:
        s-=1
    print(s)

x,y,z = list(map(int,input().split(' ')))
row = []
col = []
for i in range(z):
    p = list(map(int,input().split(' ')))
    row.append(p[0])
    col.append(p[1])
sol(row,col)

Submission status: Wrong Answer

Solution code:
def sol(x,y):
    row = {}
    col = {}
    for i in x:
        if i not in row:
            row[i] = 1
        else:
            row[i] += 1
    for i in y:
        if i not in col:
            col[i] = 1
        else:
            col[i] += 1
    a = max(row.values())
    b = max(col.values())
    print(a+b-1)


x,y,z = list(map(int,input().split(' ')))
row = []
col = []
for i in range(z):
    p = list(map(int,input().split(' ')))
    row.append(p[0])
    col.append(p[1])
sol(row,col)

Submission status: Wrong Answer

Solution code:
def sol(x,y):
    row = {}
    col = {}
    for i in x:
        if i not in row:
            row[i] = 1
        else:
            row[i] += 1
    for i in y:
        if i not in col:
            col[i] = 1
        else:
            col[i] += 1
    a = max(row.values())
    b = max(col.values())
    print(a+b)


x,y,z = list(map(int,input().split(' ')))
row = []
col = []
for i in range(z):
    p = list(map(int,input().split(' ')))
    row.append(p[0])
    col.append(p[1])
sol(row,col)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

    # Do not use element '0'.
    x_map = [0]*(3*10**5+1)
    y_map = [0]*(3*10**5+1)

    for h, w in hw:
        x_map[w] += 1
        y_map[h] += 1

    max_x = max(x_map)
    max_y = max(y_map)

    ans = x_map[max_x] + y_map[max_y]

    if (max_y, max_x) in hw:
        ans -= 1

    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


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

num_bombs_each_row = [0] * H
max_bombs_in_row = 0
row_with_max_bombs = None

num_bombs_each_col = [0] * W
max_bombs_in_col = 0
col_with_max_bombs = None

bombs = set()

for _ in range(M):
    h, w = map(int, input().split())
    # 0-index
    h -= 1
    w -= 1

    bombs.add((h, w))
    num_bombs_each_row[h] += 1
    num_bombs_each_col[w] += 1

    if max_bombs_in_row < num_bombs_each_row[h]:
        # row h has the largest number of bombs
        max_bombs_in_row = num_bombs_each_row[h]
        row_with_max_bombs = h

    if max_bombs_in_col < num_bombs_each_col[w]:
        # col w has the largest number of bombs
        max_bombs_in_col = num_bombs_each_col[w]
        col_with_max_bombs = w

ans = max_bombs_in_row + max_bombs_in_col
if (row_with_max_bombs, col_with_max_bombs) in bombs:
    # double counted
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
#E - Bomber
target     = []
hsetting   = []
wsetting   = []
hcount = 0
wcount = 0
xcount = 1
append = target.append
happend =hsetting.append
wappend =wsetting.append
# 入力
H,W,M = map(int,input().split())
for hwinput in range(M):
    h,w = map(int,input().split())
    append([h,w])
    happend(h)
    wappend(w)
#h_target = sorted(hsetting)
#w_target = sorted(wsetting)

max_bomb_out = 0
w_max_bomb_out = 0
h_max_bomb_out = 0
h_index_count = 0
w_index_count = 0
h_index = [0]
w_index = [0]

targetcount = target.count
hsetcount = hsetting.count
wsetcount = wsetting.count
h_index_ap =  h_index.append
h_index_cl =  h_index.clear
w_index_ap =  w_index.append
w_index_cl =  w_index.clear
h_index_index = h_index.index
w_index_index = w_index.index
h_index_p =[]
w_index_p =[]
h_index_p_ap =  h_index_p.append
w_index_p_ap =  w_index_p.append

for i in range(1,H+1):
    h_index_ap(hsetcount(i))
h_max_bomb_out = max(h_index)
    
for j in range(1,W+1):
    w_index_ap(wsetcount(j))
w_max_bomb_out = max(w_index)

max_bomb_out = h_max_bomb_out + w_max_bomb_out - xcount

# 出力
print(max_bomb_out)

Submission status: Wrong Answer

Solution code:
#E - Bomber
target     = []
hsetting   = []
wsetting   = []
hcount = 0
wcount = 0
xcount = 1
append = target.append
happend =hsetting.append
wappend =wsetting.append
# 入力
H,W,M = map(int,input().split())
for hwinput in range(M):
    h,w = map(int,input().split())
    append([h,w])
    happend(h)
    wappend(w)


max_bomb_out = 0
w_max_bomb_out = 0
h_max_bomb_out = 0
h_index_count = 0
w_index_count = 0
h_index = []
w_index = []

targetcount = target.count
hsetcount = hsetting.count
wsetcount = wsetting.count
h_index_ap =  h_index.append
h_index_cl =  h_index.clear
w_index_ap =  w_index.append
w_index_cl =  w_index.clear
for i in range(1,H+1):
    hcount = hsetcount(i)
    if h_max_bomb_out  <= hcount:
        if h_max_bomb_out  != hcount:
            h_index_cl()
            h_index_count = 0
        h_index_ap(i)
        h_index_count += 1
        h_max_bomb_out = hcount

for j in range(1,W+1):
    wcount = wsetcount(j)
    if w_max_bomb_out  <= wcount:
        if w_max_bomb_out  != wcount:
            w_index_cl()
            w_index_count = 0
        w_index_ap(j)
        w_index_count += 1
        w_max_bomb_out = wcount

#for k in range(h_index_count):
#    for l in range(w_index_count):
#        xcount_flag = targetcount([h_index[k],w_index[l]])
#        if xcount_flag == 0:
#            xcount = 0
#            break

max_bomb_out = h_max_bomb_out + w_max_bomb_out - xcount

# 出力
print(max_bomb_out)

Submission status: Wrong Answer

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

countW = {0:0}
countH = {0:0}
bomb = [[] for _ in range(H+1)]
for i in range(M):
    h, w = map(int, input().split())
    bomb[h].append(w)
    if h in countH.keys():
        countH[h] += 1
    else:
        countH[h] = 1
    if w in countW.keys():
        countW[w] += 1
    else:
        countW[w] = 1

sortedW = sorted(countW.items(), key=lambda x:x[1])
sortedH = sorted(countH.items(), key=lambda x:x[1])

szH = len(sortedH)
szW = len(sortedW)
maxW = sortedW[szW-1][1]
maxH = sortedH[szH-1][1]
ans = maxW + maxH - 1
for h in range(szH-1, 0, -1):
    hh, bh = sortedH[h]
    if bh < maxH: break
    for w in range(szW-1, 0, -1):
        ww, bw = sortedW[w]
        if bw < maxW: break
        if ww not in bomb[hh]:
            ans += 1
            break

print(ans)

Submission status: Wrong Answer

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

countW = {0:0}
countH = {0:0}
bomb = [[] for _ in range(H+1)]
for i in range(M):
    h, w = map(int, input().split())
    bomb[h].append(w)
    if h in countH.keys():
        countH[h] += 1
    else:
        countH[h] = 1
    if w in countW.keys():
        countW[w] += 1
    else:
        countW[w] = 1

sortedW = sorted(countW.items(), key=lambda x:x[1])
sortedH = sorted(countH.items(), key=lambda x:x[1])

ans = 0
szH = len(sortedH)
szW = len(sortedW)
found = False
for h in range(szH-1, 0, -1):
    if found: break
    hh, bh = sortedH[h]
    for w in range(szW-1, 0, -1):
        ww, bw = sortedW[w]
        nval = bh + bw
        if ww in bomb[hh]:
            nval -= 1
        if ans < nval: ans = nval
        elif ans > nval:
            found = True
            break

print(ans)

Submission status: Wrong Answer

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

countW = {0:0}
countH = {0:0}
bomb = [[] for _ in range(H+1)]
for i in range(M):
    h, w = map(int, input().split())
    bomb[h].append(w)
    if h in countH.keys():
        countH[h] += 1
    else:
        countH[h] = 1
    if w in countW.keys():
        countW[w] += 1
    else:
        countW[w] = 1

sortedW = sorted(countW.items(), key=lambda x:x[1])
sortedH = sorted(countH.items(), key=lambda x:x[1])

ans = 0
szH = len(sortedH)
szW = len(sortedW)
found = False
for h in range(szH-1, 0, -1):
    if found: break
    hh, bh = sortedH[h]
    for w in range(szW-1, 0, -1):
        ww, bw = sortedW[w]
        nval = bh + bw
        if w in bomb[h]:
            nval -= 1
        if ans < nval: ans = nval
        elif ans > nval:
            found = True
            break

print(ans)

Submission status: Wrong Answer

Solution code:
#E - Bomber
target     = []
hsetting   = []
wsetting   = []
hcount = 0
wcount = 0
xcount = 1
# 入力
H,W,M = map(int,input().split())
for hwinput in range(M):
    h,w = map(int,input().split())
    target.append([h,w])
    hsetting.append(h)
    wsetting.append(w)

max_bomb_out = 0
w_max_bomb_out = 0
h_max_bomb_out = 0
h_index_count = 0
w_index_count = 0
h_index = []
w_index = []
for i in range(1,H+1):
    hcount = hsetting.count(i)
    if h_max_bomb_out  <= hcount:
        h_max_bomb_out = hcount
        h_index.append(i)
for j in range(1,W+1):
    wcount = wsetting.count(j)
    if w_max_bomb_out  <= wcount:
        w_max_bomb_out = wcount
        w_index.append(j)
h_index_count = len(h_index)
w_index_count = len(w_index)
for k in range(h_index_count):
    for l in range(w_index_count):
        xcount_flag = target.count([h_index[k],w_index[l]])
        if xcount_flag == 0:
            xcount = 0
            break

max_bomb_out = h_max_bomb_out + w_max_bomb_out - xcount

# 出力
print(max_bomb_out)

Submission status: Wrong Answer

Solution code:
#E - Bomber
target     = []
hsetting   = []
wsetting   = []
hcount = 0
wcount = 0
xcount = 0
# 入力
H,W,M = map(int,input().split())
for hwinput in range(M):
    h,w = map(int,input().split())
    target.append([h,w])
    hsetting.append(h)
    wsetting.append(w)

max_bomb_out = 0
w_max_bomb_out = 0
h_max_bomb_out = 0
h_index = 0
w_index = 0
for i in range(1,H+1):
    hcount = hsetting.count(i)
    if h_max_bomb_out  < hcount:
        h_max_bomb_out = hcount
        h_index = i
for j in range(1,W+1):
    wcount = wsetting.count(j)
    if w_max_bomb_out  < wcount:
        w_max_bomb_out = wcount
        w_index = j
xcount = target.count([h_index,w_index])
max_bomb_out = h_max_bomb_out + w_max_bomb_out - xcount

# 出力
print(max_bomb_out)

Submission status: Wrong Answer

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

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

row = [0]*h
col = [0]*w
maze = [[0 for _ in range(w)] for _ in range(h)]

for i in range(m):
    hh, ww = map(lambda x:int(x)-1,input().split())
    row[hh] += 1
    col[ww] += 1
    maze[hh][ww] = 1

rmax = max(row)
cmax = max(col)

print(rmax+cmax)

Submission status: Wrong Answer

Solution code:
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
import time
"""
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
from numba import jit
"""

def main():
    H,W,M = map(int,input().split())
    h={}
    w={}
    bomb_list=[]
    for i in range(M):
        ih,iw = map(int,input().split())
        bomb_list.append([ih,iw])
        if ih not in h:
            h[ih]=1
        else:
            h[ih]+=1
        if iw not in w:
            w[iw]=1
        else:
            w[iw]+=1

    #max_h = [k for k, v in h.items() if v == max(h.values())]
    #max_w = [k for k, v in w.items() if v == max(w.values())]
    #for mh in max_h:
    #    for mw in max_w:
    #        if [mh,mw] not in bomb_list:
    #            print(max(h.values())+max(w.values()))
    #            return
    
    print(max(h.values())+max(w.values())-1)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import operator


def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    # H, W, M = 3, 3, 3
    # targets = ((1, 1), (2, 1), (1, 3))
    
    target_h = {}
    target_w = {}
    target_hw = set()
    for h, w in targets:
        target_h[h - 1] = target_h.setdefault(h - 1, 0) + 1
        target_w[w - 1] = target_w.setdefault(w - 1, 0) + 1
        target_hw.add((h - 1, w - 1))

    getter = operator.itemgetter(1)
    h, max_h = max(target_h.items(), key=getter)
    w, max_w = max(target_w.items(), key=getter)
    ans = max_h + max_w - (1 if (h, w) in target_hw else 0)
    
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
h,w,m = map(int,input().split())
dh = defaultdict(int)
dw = defaultdict(int)
l=defaultdict(tuple)
for _ in range(m):
    x,y = map(int,input().split())
    dh[x]+=1
    dw[y]+=1
    l[(x,y)]=1
m = 0
for i in range(1,h+1):
    if dh[i]>m:
        m = dh[i]
        hi=i
c=m
m = 0
for i in range(1,w+1):
    d = dw[i]
    if l[(hi,i)]==1:
        d-=1
    m = max(m,d)
c+=m
print(c)

Submission status: Wrong Answer

Solution code:
import sys


def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = [0] * H
    target_w = [0] * W
    for h, w in targets:
        target_h[h - 1] += 1
        target_w[w - 1] += 1

    ans = 0
    for h, w in targets:
        ans = max(ans, target_h[h - 1] + target_w[w - 1] - 1)
    
    return ans

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hl=[0]*(h)
wl=[0]*(w)
bom=[]
for i in range(m):
  h1,w1=map(int,input().split())
  bom.append([h1-1,w1-1])
  hl[h1-1]+=1
  wl[w1-1]+=1
  
print(hl)
print(wl)

mh=max(hl)
mw=max(wl)
ans=mh+mw
mhl=set()
mwl=set()
for i in range(h):
  if mh==hl[i]:
    mhl.add(i)
    
for i in range(w):
  if mw==wl[i]:
    mwl.add(i)

count=len(mhl)*len(mwl)
for i in range(len(bom)):
  if bom[i][0] in mhl and bom[i][1] in mwl:
    count-=1
if count>0:
  print(ans)
else:
  print(ans-1)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hl=[0]*(h+1)
wl=[0]*(w+1)
bom=[]
for i in range(m):
  h,w=map(int,input().split())
  bom.append([h-1,w-1])
  hl[h-1]+=1
  wl[w-1]+=1
mh=max(hl)
mw=max(wl)
ans=mh+mw
mhl=set()
mwl=set()
for i in range(h):
  if mh==hl[i]:
    mhl.add(i)
    
for i in range(w):
  if mw==wl[i]:
    mwl.add(i)
    
count=len(mhl)*len(mwl)
for i in range(len(bom)):
  if bom[i][0] in mhl and bom[i][1] in mwl:
    count-=1
if count>0:
  print(ans)
else:
  print(ans-1)