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:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  H,W,M=LI()
  h=[0]*H
  w=[0]*W
  lh=[]
  lw=[]
  d={}
  for _ in range(M):
    a,b=LI()
    lh.append(a)
    lw.append(b)
    a-=1
    b-=1
    h[a]+=1
    w[b]+=1
    d[(a,b)]=1

  h_koho=[]
  w_koho=[]

  h_max=max(h)
  w_max=max(w)

  for i,x in enumerate(lh):
    if x==h_max:
      h_koho.append(x)
  for i,x in enumerate(lw):
    if x==w_max:
      w_koho.append(x)

  for x in h_koho:
    for y in w_koho:
      if (x,y) not in d:
        return h_max+w_max

  return h_max+w_max-1

# main()
print(main())

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  H,W,M=LI()
  h=[0]*H
  w=[0]*W
  lh=[]
  lw=[]
  d={}
  for _ in range(M):
    a,b=LI()
    lh.append(a)
    lw.append(b)
    a-=1
    b-=1
    h[a]+=1
    w[b]+=1
    d[(a,b)]=1

  h_koho=[]
  w_koho=[]

  h_max=max(h)
  w_max=max(w)

  for i,x in enumerate(h):
    if x==h_max:
      h_koho.append(x)
  for i,x in enumerate(w):
    if x==w_max:
      w_koho.append(x)

  for x in h_koho:
    for y in w_koho:
      if (x,y) not in d:
        return h_max+w_max

  return h_max+w_max-1

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import collections
h, w, m = map(int, input().split())
a = []
b = []
for i in range(m):
    a1, b1 = map(int, input().split())
    a.append(a1)
    b.append(b1)
a2 = collections.Counter(a)
b2 = collections.Counter(b)
a_max = a2.most_common()
b_max = b2.most_common()

a_ans = []
a_max2 = -1
for i in a_max:
    a_grid, a_count = i
    if a_max2 == -1 or a_max2 == a_count:
        a_max2 = a_count
        a_ans.append(a_grid)
b_ans = []
b_max2 = -1
for i in b_max:
    b_grid, b_count = i
    if b_max2 == -1 or b_max2 == b_count:
        b_max2 = b_count
        b_ans.append(b_grid)
# print(a_ans, b_ans)

for i in a:
    for j in b:
        if i not in a and j not in b:
            print(a_max2+b_max2)
            break
else:
    print(a_max2+b_max2-1)

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


H, W, M = MI()
h = [0] * H
w = [0] * W
item_list = [[0, 0] for _ in range(M)]

for i in range(M):
    item_h, item_w = MI()
    item_h -= 1
    item_w -= 1
    h[item_h] += 1
    w[item_w] += 1
    item_list[i][0] = item_h
    item_list[i][1] = item_w

ans = max(h) + max(w)

if max(h) == 0:
    ans = max(w)
if max(w) == 0:
    ans = max(h)
else:
    d =[h.index(max(h)), w.index(max(w))]
    if d in item_list:
        ans -= 1


print(ans)

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


H, W, M = MI()
h = [0] * H
w = [0] * W
item_list = [[0, 0] for _ in range(M)]

for i in range(M):
    item_h, item_w = MI()
    item_h -= 1
    item_w -= 1
    h[item_h] += 1
    w[item_w] += 1
    item_list[i][0] = item_h
    item_list[i][1] = item_w

ans = max(h) + max(w)
d =[h.index(max(h)), w.index(max(w))]
if d in item_list:
    ans -= 1


print(ans)

Submission status: Wrong Answer

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

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    # 座標だけはsetで格納
    bomb_pos = set()
    # 爆弾情報を行と列ごとで格納
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(bomb_row) if v == bomb_col_max]
    col_index = [i for i, v in enumerate(bomb_col) if v == bomb_row_max]
    ans = bomb_col_max + bomb_row_max
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

Submission status: Wrong Answer

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

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    # 座標だけはsetで格納
    bomb_pos = set()
    # 爆弾情報を行と列ごとで格納
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(bomb_col) if v == bomb_col_max]
    col_index = [i for i, v in enumerate(bomb_row) if v == bomb_row_max]
    ans = bomb_col_max + bomb_row_max
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

Submission status: Wrong Answer

Solution code:
import heapq
H, W, M = map(int, input().split())
bomb = []
for i in range(M):
    h, w = map(int, input().split())
    h-=1; w-=1
    bomb.append((h, w))

row = [0] * H
col = [0] * W

for h, w in bomb:
    row[h] += 1
    col[w] += 1

lmax = max(row) + max(col)
row = [(r, i) for i, r in enumerate(row)]
col = [(c, i) for i, c in enumerate(col)]
bomb = set(bomb)

for r, i in row:
    for c, j in col:
        if r+c < lmax: break
        if not (i, j) in bomb:
            print(lmax)
            exit()
print(lmax-1)

Submission status: Wrong Answer

Solution code:
def main():
    def solve(strings_max, rows_max, mapa):
        summa = maxs + maxr - 1
        if summa == h + w - 1 or summa == m:
            return summa
        for w_item in rows_max:
            if w_item not in mapa.get(strings_max[0], []):
                return summa + 1
        return summa


    h, w, m = map(int, input().split())
    mapa = {}
    strings = [0]*h
    rows = [0]*w
    for _ in range(m):
        h1, w1 = map(int, input().split())
        if not mapa.get(h1-1, 0):
            mapa[h1-1] = []
        mapa[h1-1].append(w1-1)
        strings[h1-1] += 1
        rows[w1-1] += 1
    
    maxs = max(strings)
    maxr = max(rows)
    strings_max = []
    rows_max = []
    for i in range(h):
        if strings[i] == maxs:
            strings_max.append(i)
    for i in range(w):
        if rows[i] == maxr:
            rows_max.append(i)
    
    ans = solve(strings_max, rows_max, mapa)
    print(ans)

main()

Submission status: Wrong Answer

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

bomb = []
cnth = [0 for i in range(h)]
cntw = [0 for i in range(w)]
for i in range(m):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  cnth[x] += 1
  cntw[y] += 1
  bomb.append([x,y])
maxh = max(cnth)
maxw = max(cntw)

ans = maxh + maxw - 1
for i in range(m):
  x = bomb[i][0]
  y = bomb[i][1]
  if cnth[x] == maxh and cntw[y] == maxw:
    print (ans)
    exit()

print (ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

h,w,m = readInts()
countx = defaultdict(set)
county = defaultdict(set)

for i in range(m):
	x,y = readInts()
	countx[x].add(y)
	county[y].add(x)

maxxi = -1
maxxv = -1
maxyi = -1
maxyv = -1
for i in countx:
	l = len(countx[i])
	if maxxv<l:
		maxxv = l
		maxxi = i
for i in county:
	l = len(county[i])
	if maxyv<l:
		maxyv = l
		maxyi = i


ans = maxxv+maxyv
if maxyi in countx[maxxi] and maxxi in county[maxxi]:
	ans-=1

print(ans)

Submission status: Wrong Answer

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

tate = [0]*(h+1)
yoko = [0]*(w+1)

basyo = []

for i in range(m):
    hh,ww = map(int,input().split())
    basyo.append((hh-1,ww-1))
    
    tate[hh-1] += 1
    yoko[ww-1] += 1
    
tt,yy = 0,0
x = max(tate)

for i in tate:
    if i == x:
        tt += 1
        
y = max(yoko)
for i in yoko:
    if i == x:
        yy += 1
        
ans = x+y
pl = tt * yy

cur = 0
for i,j in basyo:
    if tate[i] + yoko[j] == ans:
        cur += 1
        
if pl > cur:
    print(ans)
else:
    print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
H, W, M = map(int, input().split())
hcount = [[i, 0] for i in range(H)]
wcount = [[i, 0] for i in range(W)]
hcnt = []
wcnt = []
for i in range(M):
    h, w = map(int, input().split())
    hcount[h-1][1] += 1
    wcount[w-1][1] += 1
    hcount[h-1].append(w-1)
    wcount[w-1].append(h-1)
hcount.sort(key=lambda x: x[1], reverse=True)
wcount.sort(key=lambda x: x[1], reverse=True)
hmax = hcount[0][1]
wmax = wcount[0][1]
hcnt = Counter([x[1] for x in hcount])
wcnt = Counter([x[1] for x in wcount])
for i in range(wcnt[wmax]):
    for j in range(wcnt[wmax]):
        if wcount[j][0] in hcount[i][2:]:
            continue
        print(hmax+wmax)
        sys.exit()
print(hmax+wmax-1)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
h,w=map(list,zip(*[list(map(int,input().split())) for i in range(M)]))
from collections import Counter
hc,wc=Counter(h),Counter(w)
hx,wx=hc.most_common()[0][1],wc.most_common()[0][1]
hl,wl=set([k for k,v in hc.items() if v==hx]),set([k for k,v in wc.items() if v==wx])
s=set()
s2=set()
for i in range(M):
    if h[i] in hl:
        s.add(w[i])
    if w[i] in wl:
        s2.add(h[i])
print(hx+wx if wl-s or hl-s2 else hx+wx-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
H, W, M = map(int, input().split())
bakudanH = [[] for _ in range(H)]
bakudanW = [[] for _ in range(W)]
hcount = [[i, 0] for i in range(H)]
wcount = [[i, 0] for i in range(W)]
hcnt = []
wcnt = []
for i in range(M):
    h, w = map(int, input().split())
    hcount[h-1][1] += 1
    wcount[w-1][1] += 1
    bakudanH[h-1].append(w-1)
    bakudanW[w-1].append(h-1)
hcount.sort(key=lambda x: x[1], reverse=True)
wcount.sort(key=lambda x: x[1], reverse=True)
hmax = hcount[0][1]
wmax = wcount[0][1]
hcnt = Counter([x[1] for x in hcount])
wcnt = Counter([x[1] for x in wcount])
for i in range(wcnt[wmax]):
    for j in range(wcnt[wmax]):
        if wcount[j][0] in bakudanH[hcount[i][0]]:
            continue
        print(hmax+wmax)
        sys.exit()
print(hmax+wmax-1)

Submission status: Wrong Answer

Solution code:
from itertools import product

def zero_origin(s: str) -> int:
  return int(s) - 1

H, W, M = map(int, input().split())
h_obj = [0 for _ in range(H)]
w_obj = [0 for _ in range(W)]
obj = set()
for _ in range(M):
  h, w = map(zero_origin, input().split())
  h_obj[h] += 1
  w_obj[w] += 1
  obj.add((h, w))
max_h = max(h_obj)
max_w = max(w_obj)
h_list = [h for h in range(H) if h_obj[h] == max_h]
w_list = [w for w in range(W) if w_obj[w] == max_w]
for h, w in product(h_list, w_list):
  if (h, w) not in obj:
    print(max_h + max_w)
else:
  print(max_h + max_w - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w, m = map(int, input().split())
beds = [tuple(map(lambda x: int(x) - 1, input().split()))  for _ in range(m)]

bom_v = Counter(b[0] for b in beds)
bom_h = Counter(b[1] for b in beds)

v_max = max(bom_v.keys(), key=lambda x: bom_v[x])
h_max = max(bom_h.keys(), key=lambda x: bom_h[x])
if (v_max, h_max) in beds:
    print(bom_v[v_max] + bom_h[h_max] - 1)
else:
    print(bom_v[v_max] + bom_h[h_max])

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

h,w,m = map(int, sys.stdin.readline().split())
targets = [list(map(lambda x: int(x)-1, sys.stdin.readline().split())) for _ in range(m)]

num_in_h = defaultdict(int)
num_in_w = defaultdict(int)
for t in targets:
    num_in_h[t[0]] += 1
    num_in_w[t[1]] += 1

max_h = max(num_in_h.items(), key=lambda x: x[1])
max_w = max(num_in_w.items(), key=lambda x: x[1])
ans = max_h[1] + max_w[1]

#print([max_h[0], max_w[0]] in targets)
if [max_h[0], max_w[0]] in targets:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
H, W, M = map(int, input().split())
h_list = []
w_list = []
hw = []
for i in range(M):
    h, w = map(int, input().split())
    h_list.append(h)
    w_list.append(w)
    hw.append([h, w])
h_col = collections.Counter(h_list)
w_col = collections.Counter(w_list)
h_maxNum = h_col.most_common()[0][1]
w_maxNum = w_col.most_common()[0][1]
if [h_col.most_common()[0][0], w_col.most_common()[0][0]] in hw:
    print(h_maxNum + w_maxNum - 1)
else:
    print(h_maxNum + w_maxNum)

Submission status: Wrong Answer

Solution code:
l = input().split()
H = int(l[0])
W = int(l[1])
M = int(l[2])

G = []
for i in range(M):
    x, y = map(int, input().split())
    g = [x, y]
    G.append(g)

h = [0]*H
for i in range(M):
    h[G[i][0]-1] += 1
h_max = max(h)
h_mi = [i for i, v in enumerate(h) if v == max(h)]

w = [0]*W
for i in range(M):
    w[G[i][1]-1] += 1
w_max = max(w)
w_mi = [i for i, v in enumerate(w) if v == max(w)]

cnt = h_max + w_max

T = []
for i in h_mi:
    for j in w_mi:
        t = [i+1, j+1]
        T.append(t)

for i in G:
    if i in T:
        cnt -= 1
        break

print(cnt)

Submission status: Wrong Answer

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

y_list=[0]*h
x_list=[0]*w

for h_i, w_i in hw:
    y_list[h_i-1]+=1
    x_list[w_i-1]+=1

my_cnt=max(y_list)
mx_cnt=max(x_list)

y_cnt=0
x_cnt=0

for h_i, w_i in hw:
    if y_list[h_i-1]==my_cnt:
        y_cnt+=1
    if x_list[w_i-1]==mx_cnt:
        x_cnt+=1

cnt=0
for h_i, w_i in hw:
    if y_list[h_i-1]==my_cnt and x_list[w_i-1]==mx_cnt:
        cnt+=1

print(my_cnt+mx_cnt if cnt==(my_cnt*mx_cnt) else my_cnt+mx_cnt-1)

Submission status: Wrong Answer

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

maxh = max(h)
maxw = max(w)

ans = 0
for i, ch in enumerate(h,1):
  if ch != maxh:
    continue
  for j, cw in enumerate(w,1):
    if cw != maxw:
      continue
    if (i, j) not in Mem:
      ans = maxh + maxw
      break
    else:
      ans = maxh + maxw - 1
        

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = max(hc)
    maw = max(wc)
    ans = mah+maw
    hmaps = []
    wmaps = []
    for i, h in enumerate(hc):
        if mah == h:
            hmaps.append(i)
    for i, w in enumerate(wc):
        if maw == w:
            wmaps.append(i)

    for h in hmaps:
        for w in wmaps:
            if (h, w) not in maps:
                print(ans)
    else:
        print(ans-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = -1
    maw = -1
    hmaps = set()
    wmaps = set()
    for i, h in enumerate(hc):
        if mah < h:
            mah = h
            hmaps = {i}
        elif mah == h:
            hmaps.add(i)
    for i, w in enumerate(wc):
        if maw < w:
            maw = w
            wmaps = {i}
        elif maw == w:
            wmaps.add(i)
    ans = mah+maw
    aru = True
    if len(hmaps) * len(wmaps) <= 5*10**6:
        for h in list(hmaps):
            for w in list(wmaps):
                if (h, w) not in maps:
                    aru = False
                    break
    if aru:
        print(ans - 1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
R, C, T = map(int, input().split())
RC = []
for _ in range(T):
    RC.append(list(map(int, input().split())))
TR = [0] * (R + 1)
TC = [0] * (C + 1)
for r, c in RC:
    TR[r] += 1
    TC[c] += 1
mxr = max(TR)
mxc = max(TC)
ct = TR.count(mxr) * TC.count(mxc) - len([0 for r, c in RC if TR[r] == mxr and TC[c] == mxc])
print("Answer: ", mxc + mxr - (ct == 0))

Submission status: Wrong Answer

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

num_h = [0] * (h+1)
num_w = [0] * (w+1)
for hi,wi in bomb:
  num_h[hi] += 1
  num_w[wi] += 1
  
max_hs = [k for k,v in enumerate(num_h) if v == max(num_h)]
max_ws = [k for k,v in enumerate(num_w) if v == max(num_w)]

result = max(num_h) + max(num_w)
for i in max_hs:
  for j in max_ws:
    if [i,j] in bomb:
      result -= 1
      print(result)
      exit(0)
print(result)

Submission status: Wrong Answer

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

for i in range(M):
    ARR.append(list(map(int,input().split())))

def calculate(h, w, m, arr):
    points = set()



    rowSum = [0 for i in range(h)]
    columnSum = [0 for i in range(w)]

    for ar in arr:
        points.add((ar[0]-1, ar[1]-1))
        rowSum[ar[0]-1] += 1
        columnSum[ar[1]-1] += 1

    maxRowSum = max(rowSum)
    maxColumnSum = max(columnSum)


    a0 = []

    for i in range(len(rowSum)):
        if rowSum[i] == maxRowSum:
            a0.append(i)

    a1 = []
    for i in range(len(columnSum)):
        if columnSum[i] == maxColumnSum:
            a1.append(i)

    result = 0
    for hIndex in a0:
        for wIndex in a1:

            if (hIndex,wIndex) in points:
                result = max(result, maxRowSum + maxColumnSum - 1)
            else:
                result = max(result, maxRowSum + maxColumnSum)
                print(result)
                break

    print(result)


calculate(H, W, M, ARR)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
targetRow = {}
targetCol = {}
targets = []
for i in range(m):
    row, col = map(int, input().split())
    targets.append((row, col))
    if row in targetRow:
        targetRow[row] += 1
    else:
        targetRow[row] = 1
    if col in targetCol:
        targetCol[col] += 1
    else:
        targetCol[col] = 1
maxRow = 0
for i in targetRow:
    if targetRow[i] > maxRow:
        maxRow = targetRow[i]
        row = i
maxCol = 0
for i in targetCol:
    if targetCol[i] > maxCol:
        maxCol = targetCol[i]
        col = i
if (row, col) in targets:
    count = maxRow + maxCol - 1
else:
    count = maxRow + maxCol
print(count)

Submission status: Wrong Answer

Solution code:
from random import randint
from collections import defaultdict
from numba import njit
import numpy as np


def f(h,w,m,ins):
    yp = np.zeros((h),dtype=np.int)
    xp = np.zeros((w),dtype=np.int)
    #yp[:,1] = np.arange(h)
    #xp[:,1] = np.arange(w)
    ans = 0
    s = set()
    #d = defaultdict(lambda: defaultdict(bool))
    for hi,wi in ins:
        #d[hi-1][wi-1] = True
        s.add((hi-1,wi-1))
        yp[hi-1] += 1
        xp[wi-1] += 1
    yps = np.argsort(yp)[-1]
    xps = np.argsort(xp)[::-1]
    y = yp[yps]
    ans += y
    for xpsi in xps:
        a = y
        a += xp[xpsi]
        #a -= d[yps][xpsi]
        a -= (yps,xpsi) in s
        ans = max(ans,a)
    return ans


if False:
    while True:
        h,w = randint(1,10**5*3),randint(1,10**5*3)
        m = randint(1,min(h*w,10**5*3))
        ins = [(randint(1,h),randint(1,w)) for i in range(m)]
        ans1 = f1(h,w,m,ins)
        ans2 = f2(h,w,m,ins)
        if ans1 != ans2:
            print("!!!!")
            print(h,w,m)
            print(ins)
else:
    h,w,m = map(int,input().split())
    ans = f(h,w,m,[tuple(map(int,input().split())) for i in range(m)])
    print(ans)

Submission status: Wrong Answer

Solution code:
from random import randint
from collections import defaultdict
#from numba import njit
import numpy as np


def f(h,w,m,ins):
    yp = np.zeros((h),dtype=np.int)
    xp = np.zeros((w),dtype=np.int)
    #yp[:,1] = np.arange(h)
    #xp[:,1] = np.arange(w)
    ans = 0
    d = defaultdict(lambda: defaultdict(bool))
    for hi,wi in ins:
        d[hi-1][wi-1] = True
        yp[hi-1] += 1
        xp[wi-1] += 1
    yps = np.argsort(yp)[-1]
    xps = np.argsort(xp)[::-1]
    y = yp[yps]
    ans += y
    for xpsi in xps:
        a = y
        a += xp[xpsi]
        a -= d[yps][xpsi]
        ans = max(ans,a)
    return ans


if False:
    while True:
        h,w = randint(1,10**5*3),randint(1,10**5*3)
        m = randint(1,min(h*w,10**5*3))
        ins = [(randint(1,h),randint(1,w)) for i in range(m)]
        ans1 = f1(h,w,m,ins)
        ans2 = f2(h,w,m,ins)
        if ans1 != ans2:
            print("!!!!")
            print(h,w,m)
            print(ins)
else:
    h,w,m = map(int,input().split())
    ans = f(h,w,m,[tuple(map(int,input().split())) for i in range(m)])
    print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
spot = []
tate = [0 for i in range(h)]
yoko = [0 for i in range(w)]
for i in range(m):
  x, y = map(int, input().split())
  spot.append([x, y])
  tate[x-1] += 1
  yoko[y-1] += 1
maxh = tate.index(max(tate))
maxw = yoko.index(max(yoko))
if([maxh+1, maxw+1] in spot):
  print(max(tate)+max(yoko)-1)
else:
  print(max(tate)+max(yoko))

Submission status: Wrong Answer

Solution code:
from random import randint
from collections import defaultdict
#from numba import njit
import numpy as np


def f1(h,w,m,ins):
    #b = np.zeros((h,w),dtype=np.int8)
    yp = np.zeros(h,dtype=np.int)
    xp = np.zeros(w,dtype=np.int)
    ans = 0
    d = defaultdict(lambda: defaultdict(bool))
    for hi,wi in ins:
        d[hi-1][wi-1] = True
        yp[hi-1] += 1
        xp[wi-1] += 1
    yps = np.argsort(yp)[-1]
    xps = np.argsort(xp)
    y = yp[yps]
    ans += y
    for xpsi in xps:
        a = y
        a += xp[xpsi]
        a -= d[yps][xp[xpsi]]
        ans = max(ans,a)
    return ans


def f2(h,w,m,ins):
    yp = np.zeros((h,2),dtype=np.int)
    xp = np.zeros((w,2),dtype=np.int)
    yp[:,1] = np.arange(h)
    xp[:,1] = np.arange(w)
    ans = 0
    d = defaultdict(lambda: defaultdict(bool))
    for hi,wi in ins:
        d[hi-1][wi-1] = True
        yp[hi-1,0] += 1
        xp[wi-1,0] += 1
    yps = np.argsort(yp[:,0])[::-1]
    xps = np.argsort(xp[:,0])[::-1]
    y = yp[yps[0]]
    ans += y[0]
    for xpsi in xps:
        a = y[0]
        a += xp[xpsi,0]
        a -= d[yps[0]][xpsi]
        ans = max(ans,a)
    return ans


if False:
    while True:
        h,w = randint(1,10**5*3),randint(1,10**5*3)
        m = randint(1,min(h*w,10**5*3))
        ins = [(randint(1,h),randint(1,w)) for i in range(m)]
        ans1 = f1(h,w,m,ins)
        ans2 = f2(h,w,m,ins)
        if ans1 != ans2:
            print("!!!!")
            print(h,w,m)
            print(ins)
else:
    h,w,m = map(int,input().split())
    ans = f2(h,w,m,[tuple(map(int,input().split())) for i in range(m)])
    print(ans)

Submission status: Wrong Answer

Solution code:
from random import randint
from collections import defaultdict
#from numba import njit
import numpy as np


def f1(h,w,m,ins):
    #b = np.zeros((h,w),dtype=np.int8)
    yp = np.zeros(h,dtype=np.int)
    xp = np.zeros(w,dtype=np.int)
    ans = 0
    d = defaultdict(lambda: defaultdict(bool))
    for hi,wi in ins:
        d[hi-1][wi-1] = True
        yp[hi-1] += 1
        xp[wi-1] += 1
    yps = np.argsort(yp)[-1]
    xps = np.argsort(xp)
    y = yp[yps]
    ans += y
    for xpsi in xps:
        a = y
        a += xp[xpsi]
        a -= d[yps][xp[xpsi]]
        ans = max(ans,a)
    return ans


def f2(h,w,m,ins):
    yp = np.zeros((h,2),dtype=np.int)
    xp = np.zeros((w,2),dtype=np.int)
    yp[:,1] = np.arange(h)
    xp[:,1] = np.arange(w)
    ans = 0
    d = defaultdict(lambda: defaultdict(bool))
    for hi,wi in ins:
        d[hi-1][wi-1] = True
        yp[hi-1,0] += 1
        xp[wi-1,0] += 1
    yps = np.argsort(yp[:,0])[::-1]
    xps = np.argsort(xp[:,0])[::-1]
    y = yp[yps[0]]
    ans += y[0]
    print(y[0])
    for xpsi in xps:
        a = y[0]
        a += xp[xpsi,0]
        a -= d[yps[0]][xpsi]
        ans = max(ans,a)
    return ans


if False:
    while True:
        h,w = randint(1,10**5*3),randint(1,10**5*3)
        m = randint(1,min(h*w,10**5*3))
        ins = [(randint(1,h),randint(1,w)) for i in range(m)]
        ans1 = f1(h,w,m,ins)
        ans2 = f2(h,w,m,ins)
        if ans1 != ans2:
            print("!!!!")
            print(h,w,m)
            print(ins)
else:
    h,w,m = map(int,input().split())
    ans = f2(h,w,m,[tuple(map(int,input().split())) for i in range(m)])
    print(ans)

Submission status: Wrong Answer

Solution code:
from random import randint
from collections import defaultdict
#from numba import njit
import numpy as np


def f1(h,w,m,ins):
    #b = np.zeros((h,w),dtype=np.int8)
    yp = np.zeros(h,dtype=np.int)
    xp = np.zeros(w,dtype=np.int)
    ans = 0
    d = defaultdict(lambda: defaultdict(bool))
    for hi,wi in ins:
        d[hi-1][wi-1] = True
        yp[hi-1] += 1
        xp[wi-1] += 1
    yps = np.argsort(yp)[-1]
    xps = np.argsort(xp)
    y = yp[yps]
    ans += y
    for xpsi in xps:
        a = y
        a += xp[xpsi]
        a -= d[yps][xp[xpsi]]
        ans = max(ans,a)
    return ans


def f2(h,w,m,ins):
    yp = np.zeros((h,2),dtype=np.int)
    xp = np.zeros((w,2),dtype=np.int)
    yp[:,1] = np.arange(h)
    xp[:,1] = np.arange(w)
    ans = 0
    d = defaultdict(lambda: defaultdict(bool))
    for hi,wi in ins:
        d[hi-1][wi-1] = True
        yp[hi-1,0] += 1
        xp[wi-1,0] += 1
    yps = np.argsort(yp[:,0])[::-1]
    xps = np.argsort(xp[:,0])[::-1]
    y = yp[yps[0]]
    ans += y[0]
    print(y[0])
    for xpsi in xps:
        a = y[0]
        a += xp[xpsi,0]
        a -= d[yps[0]][xpsi]
        ans = max(ans,a)
    return ans


if False:
    while True:
        h,w = randint(1,10**5*3),randint(1,10**5*3)
        m = randint(1,min(h*w,10**5*3))
        ins = [(randint(1,h),randint(1,w)) for i in range(m)]
        ans1 = f1(h,w,m,ins)
        ans2 = f2(h,w,m,ins)
        if ans1 != ans2:
            print("!!!!")
            print(h,w,m)
            print(ins)
else:
    h,w,m = map(int,input().split())
    ans = f1(h,w,m,[tuple(map(int,input().split())) for i in range(m)])
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

Bom_list = list()
Y_list = list()
X_list = list()

for _ in range(M):
    Bom = list(map(int,input().split()))
    Bom_list.append(Bom)
    Y_list.append(Bom[0])
    X_list.append(Bom[1])

Y_counter = collections.Counter(Y_list)
X_counter = collections.Counter(X_list)

set_Y = list(set(Y_list))
set_X = list(set(X_list))
len_set_Y = len(set_Y)
len_set_X = len(set_X)

max_Y_num = 0 
max_X_num = 0
max_Y_list = list()
max_X_list = list()

for i in range(len_set_Y):
    if max_Y_num < Y_counter[set_Y[i]]:
        max_Y_list.clear()
        max_Y_num = Y_counter[set_Y[i]]
        max_Y_list.append(set_Y[i])
    elif max_Y_num == Y_counter[set_Y[i]]:
        max_Y_list.append(set_Y[i])
        max_Y_num = Y_counter[set_Y[i]]

for i in range(len_set_X):
    if max_X_num < X_counter[set_X[i]]:
        max_X_list.clear()
        max_X_num = X_counter[set_X[i]]
        max_X_list.append(set_X[i])
    elif max_X_num == X_counter[set_X[i]]:
        max_X_list.append(set_X[i])
        max_X_num = X_counter[set_X[i]]

ans = 0


ans = max_Y_num + max_X_num

for i in Bom_list:
    if i[0] in max_Y_list and i[1] in max_X_list:
        ans = max_Y_num + max_X_num - 1
    

# for i in max_Y_list:
#     for j in max_X_list:
#         if [i,j] in Bom_list:
#             ans = max_Y_num + max_X_num - 1
#         else:
#             ans = max_Y_num + max_X_num
#             print(ans)
#             exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import copy

a = list(map(int,input().split()))
c = []
d = []
for i in range(a[2]):
    b = list(map(int,input().split()))
    c.append(b[0])
    d.append(b[1])

ans1 = 0
ans2 = 0

cp = copy.copy(c)
dp = copy.copy(d)

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]
ans1 += gc
ans2 += hc
for i in range(a[2]):
    if cp[i] == g:
        d[i] = -1
    if dp[i] == h:
        c[i] = -1
print(c)
print(d)
e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

if g == -1:
    if gc == a[2]:
        gc = 0
    else:
        g = e.most_common()[1][0]
        gc = e.most_common()[1][1]
if h == -1:
    if hc == a[2]:
        hc = 0
    else:
        h = f.most_common()[1][0]
        hc = f.most_common()[1][1]

print(gc)
print(hc)

ans1 += hc
ans2 += gc
if ans1 > ans2:
    print(str(ans1))
else:
    print(str(ans2))