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:
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W, M = list(map(int, input().split()))
    h_list = np.zeros(M, dtype=int)
    w_list = np.zeros(M, dtype=int)

    sum_h = np.zeros(H, dtype=int)
    sum_w = np.zeros(W, dtype=int)

    for m in range(M):
        tmp = list(map(int, input().split()))
        h = tmp[0]-1
        w = tmp[1]-1

        h_list[m] = h
        w_list[m] = w

        sum_h[h] += 1
        sum_w[w] += 1

    ans_h = np.argmax(sum_h) # hについては決定
    ans = max(sum_h)
    for m in range(M):
        if h_list[m] == ans_h:
            w = w_list[m]
            sum_w[w] -= 1

    ans_w = np.argmax(sum_w)
    ans += max(sum_w)

    print(int(ans))
    pass


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main_slow():
    H, W, M = list(map(int, input().split()))
    h_list = []
    w_list = []
    for m in range(M):
        tmp = list(map(int, input().split()))
        h_list.append(tmp[0]-1)
        w_list.append(tmp[1]-1)

    sum_h = np.zeros(H)
    sum_w = np.zeros(W)

    for h, w in zip(h_list, w_list):
        sum_h[h] += 1
        sum_w[w] += 1

    ans_h = np.argmax(sum_h) # hについては決定
    ans = max(sum_h)

    for h, w in zip(h_list, w_list):
        if h == ans_h:
            sum_w[w] -= 1

    ans_w = np.argmax(sum_w)
    ans += max(sum_w)

    print(int(ans))
    pass

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# Q5
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
from functools import lru_cache

def I(): return int(sys.stdin.readline().rstrip())
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 = LI()
h_w_list = []
for i in range(M):
    h_w_list.append(LI())

count_h = collections.Counter([h for h, w in h_w_list])
count_w = collections.Counter([w for h, w in h_w_list])

h_index, h_bomb = count_h.most_common(1)[0]
w_index, w_bomb = count_w.most_common(1)[0]

if [h_index, w_index] in h_w_list:
    total = h_bomb + w_bomb - 1
else:
    total = h_bomb + w_bomb
print(total)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
hwList = []
hList = [0] * (h + 1)
wList = [0] * (w + 1)
for x in range(m):
    h_i, w_i = map(int, input().split())
    hList[h_i] += 1
    wList[w_i] += 1
    hwList.append([h_i, w_i])
h_max = max(hList)
w_max = max(wList)
h_maxid = [i for i, v in enumerate(hList) if v == h_max]
w_maxid = [i for i, v in enumerate(wList) if v == w_max]
isminus = 1
#if len(h_maxid) * len(w_maxid) > 3 * (10 ** 5): isminus = 0
#else:
#    for a in h_maxid:
#        if isminus == 0: break
#        for b in w_maxid:
#            if [a, b] in hwList: continue
#            isminus = 0
#            break
print(max(hList) + max(wList) - isminus)

Submission status: Wrong Answer

Solution code:
import random
h,w,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
exist = []
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

for y,x in lis:
    exist.append(format(y).zfill(6)+format(x).zfill(6))
    tate[y-1][0] += 1
    yoko[x-1][0] += 1

tate.sort(key=lambda x:x[0],reverse=True)
yoko.sort(key=lambda x:x[0],reverse=True)

ans = 1
if m >= 2:ans = 2
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

for turn in range(200):
    i,j = random.randint(0,h-1),random.randint(0,w-1)
    ans = max(ans,tate[i][0]+yoko[j][0]-bool(format(tate[i][1]+1).zfill(6)+format(yoko[j][1]+1).zfill(6) in exist))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W,M = list(map(int,input().split()))

if M == 1:
    print(1)
    exit()

counterH = Counter()
counterW = Counter()
targets = set()
for i in range(M):
    h,w = list(map(int,input().split()))
    counterH[h] += 1
    counterW[w] += 1
    targets.add((h,w))

ans = 2
for count_H in counterH.most_common():
    for count_W in counterW.most_common():
        # print(count_H,count_W)
        if (count_H[0],count_W[0]) in targets:
            ans = max(ans,count_H[1]+count_W[1]-1)
            # print(count_H[1]+count_W[1]-1)
        else:
            ans = max(ans,count_H[1]+count_W[1])
            # print(count_H[1]+count_W[1])
        if count_W[1] == 1:
            break
    if count_H[1] == 1:
        break
print(ans)

Submission status: Wrong Answer

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

    x = [0]*h
    y = [0]*w
    for p in h_w:
        x[p[0]-1] += 1
    
    idx = x.index(max(x))
    
    for p in h_w:
        if p[0]-1 == idx:
            continue
        else:
            y[p[1]-1] += 1
    
    print(max(x) + max(y))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h, w, m = map(int,input().split())
dic_h = dict()
dic_w = dict()
max_h = [0, 0]
max_w = [0, 0]
c = dict()
for _ in range(m):
    x, y = map(int,input().split())
    c[(x, y)] = 1
    
    if dic_h.get(x):
        dic_h[x] += 1
        if dic_h[x] > max_h[0]:max_h = [dic_h[x], x]
        elif dic_h[x] == max_h[0]:max_w.append(x)
    else:
        dic_h[x] = 1
        if max_h[0] == 0:max_h = [1, x]
    
    if dic_w.get(y):
        dic_w[y] += 1
        if dic_w[y] > max_w[0]:max_w = [dic_w[y], y]
        elif dic_w[y] == max_w[0]:max_w.append(y)
    else:
        dic_w[y] = 1
        if max_w[0] == 0:max_w = [1, y]
        
res = max_h[0] + max_w[0] - 1
#print(max_h, max_w)
for i in range(len(max_h) - 1):
    for j in range(len(max_w) - 1):
        temp = (max_h[i + 1], max_w[j + 1])
        if c.get(temp):continue
        res += 1
        print(res)
        exit()
print(res)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict

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

ctr_h = defaultdict(int)
ctr_w = defaultdict(int)

for h, w in X:
    ctr_h[h] += 1
    ctr_w[w] += 1

val_h = sorted(ctr_h.items(), key=lambda x: -x[1])
val_w = sorted(ctr_w.items(), key=lambda x: -x[1])
cand = []
max_h = val_h[0][1]
max_w = val_w[0][1]
for h, c_h in val_h:
    for w, c_w in val_w:
        if c_h == max_h and c_w == max_w:
            cand.append((h, w))

res = max_h + max_w
for h, w in X:
    if h == val_h[0][0] and w == val_w[0][0]:
        res -= 1
        break

print(res)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
ans, row, column, vals = 0, [], [], []

for i in range(m):
    a, b = map(int, input().split())
    row.append(a)
    column.append(b)
    vals.append([a, b])

for i in range(h):
    a0 = row.count(i)
    pre = a0
    for j in range(w):
        a0 += column.count(j)
        if i == j:
            if [i, j] in vals:
                a0 -= 1
        ans = max(ans, a0)
        a0 = pre
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W,M=map(int,input().split())
Hcnt=[0]*H
Wcnt=[0]*W
hw=[]
for i in range(M):
    h,w=map(lambda x:int(x)-1,input().split())
    hw.append((h,w))
    Hcnt[h]+=1
    Wcnt[w]+=1

mH=max(Hcnt)
mW=max(Wcnt)

#逆方向の最大値のどれともかぶってないものがあるか探す
set_H=set()
set_W=set()
for i in range(H):
    if Hcnt[i]==mH:
        set_H.add(i)
for i in range(W):
    if Wcnt[i]==mW:
        set_W.add(i)
Hcnt2,Wcnt2=[0]*H,[0]*W
for h,w in hw:
    if not w in set_W:
        Hcnt2[h]+=1
    if not h in set_H:
        Wcnt2[w]+=1
if max(Hcnt2)<mH and max(Wcnt2)<mW:
    print(mH+mW-1)
else:
    print(mH+mW)

Submission status: Wrong Answer

Solution code:
import random
h,w,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
exist = []
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

for y,x in lis:
    exist.append(format(y).zfill(6)+format(x).zfill(6))
    tate[y-1][0] += 1
    yoko[x-1][0] += 1

tate.sort(key=lambda x:x[0],reverse=True)
yoko.sort(key=lambda x:x[0],reverse=True)

ans = 1
if m >= 2:ans = 2
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

for turn in range(100):
    i,j = random.randint(0,h-1),random.randint(0,w-1)
    ans = max(ans,tate[i][0]+yoko[j][0]-bool(format(tate[i][1]+1).zfill(6)+format(yoko[j][1]+1).zfill(6) in exist))
print(ans)

Submission status: Wrong Answer

Solution code:
import random
h,w,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
exist = []
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

for y,x in lis:
    exist.append(format(y).zfill(6)+format(x).zfill(6))
    tate[y-1][0] += 1
    yoko[x-1][0] += 1

tate.sort(key=lambda x:x[0],reverse=True)
yoko.sort(key=lambda x:x[0],reverse=True)

ans = 1
if m >= 2:ans = 2
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

for turn in range(1000):
    i,j = random.randint(0,h-1),random.randint(0,w-1)
    ans = max(ans,tate[i][0]+yoko[j][0]-bool(format(tate[i][1]+1).zfill(6)+format(yoko[j][1]+1).zfill(6) in exist))
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

h_counter = collections.Counter(h)
w_counter = collections.Counter(w)
h_common = h_counter.most_common()[0][0]
w_common = w_counter.most_common()[0][0]

ans=0
for i in range(M):
    if h[i] == h_common or w[i] == w_common:
        ans = ans +1
if ans == 1:
    if M >= 2:
        ans = 2

Submission status: Wrong Answer

Solution code:
#e
h,w,m=map(int,input().split())
hw=[]
hh=set()
ww=set()
hhh=[0]*h
www=[0]*w
for i in range(m):
    hi,wi=map(int,input().split())
    hi-=1
    wi-=1
    hh.add(hi)
    ww.add(wi)
    hhh[hi]+=1
    www[wi]+=1
    hw.append([hi,wi])

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline
from collections import defaultdict
h, w, m = map(int,input().split())
row = defaultdict(int)
col = defaultdict(int)
grid = defaultdict(int)
for _ in range(m):
    x,y = map(int,input().split())
    row[x]+=1
    col[y]+=1
    grid[(x,y)]+=1

#print(row)
#print(col)
#print(grid)
    
t1 = [0, 0]
for r in row:
    if row[r]>t1[0]:
        t1 = row[r], r
t2 = [0, 0] 
for c in col:
    if col[c]>t2[0]:
        t2 = col[c], c
#print(t1)
#print(t2)
ans = t1[0]+t2[0]
if grid[(t1[1],t2[1])]:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
a,b,m=map(int,input().split())
r=defaultdict(int)
c=defaultdict(int)
d=defaultdict(int)
for i in range(m):
  x,y=map(int,input().split())
  d[(x,y)]=1
  r[x]+=1
  c[y]+=1
x=max(r,key=r.get)
y=max(c,key=c.get)
if d[(x,y)]==1:
  print(r[x]+c[y]-1)
else:
  print(r[x]+c[y])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

    retu = Counter()
    gyo = Counter()

    ipt = [[] for _ in range(H)]

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

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

    return rmm+gmm

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

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

print(solver())

Submission status: Wrong Answer

Solution code:
hmw = input()
hmw_l = hmw.split()
h = int(hmw_l[0])
w = int(hmw_l[1])
m = int(hmw_l[2])
hw = []
h_l = []
w_l = []
hc =[]
wc =[]
for i in range(m):
  hwi=input()
  hw.append(hwi)
  hwi_l = hwi.split()
  h_l.append(int(hwi_l[0]))
  w_l.append(int(hwi_l[1]))
for x in range(1,h+1):
  hc.append(h_l.count(x))
for y in range(1,w+1):
  wc.append(w_l.count(y))
mhc = max(hc)
mwc = max(wc)
k = str(hc.index(mhc)+1) + " " + str(wc.index(mwc)+1)
if k in hw:
  print(max(hc)+max(wc)-1)
else:
  print(mhc+mwc)

Submission status: Wrong Answer

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


from bisect import bisect,bisect_left
from collections import defaultdict

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

hcol = [[0,i] for i in range(H)]
wcol = [[0,i] for i in range(W)]

P = set()
for i in range(M):
  h,w = map(int,readline().split())
  h -= 1
  w -= 1
  hcol[h][0] += 1
  wcol[w][0] += 1
  P.add((h,w))
  
hcol = sorted(hcol, key = lambda x:x[0], reverse = True)
wcol = sorted(wcol, key = lambda x:x[0], reverse = True)

hmax = hcol[0][0]
wmax = wcol[0][0]

ans = 0
hind = 0
wind = 0
while hind < H:
  while wind < W:
    val = hcol[hind][0] + wcol[wind][0]
    if (hcol[hind][1],wcol[wind][1]) in P:
      val -= 1
    if ans < val:
      ans = val
    wind += 1
    if wind == W or wcol[wind][0] < wmax:
      break
  hind += 1
  if hind == H or hcol[hind][0] < hmax:
    break
    
print(ans)

Submission status: Wrong Answer

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

for i in range(0,M):
    e,f=map(int,input().split())
    a.append(e)
    b.append(f)

am=0
bm=0

for i in range(0,H+1):
    am=max(am,a.count(i))

for i in range(0,W+1):
    bm=max(bm,b.count(i))
    
print(am+bm)

Submission status: Wrong Answer

Solution code:
import sys

H, W, M = map(int, input().split())
field = [[0 for j in range(W)] for i in range(H)]
h_sum = []
for i in range(H):
    h_sum.append([i, 0])

w_sum = []
for i in range(W):
    w_sum.append([i, 0])

for _ in range(M):
    h, w = map(int, input().split())
    field[h - 1][w - 1] = 1
    h_sum[h - 1][1] += 1
    w_sum[w - 1][1] += 1

h_sum.sort(key=lambda x: x[1], reverse=True)
w_sum.sort(key=lambda x: x[1], reverse=True)
# print(field)
# print(h_sum)
# print(w_sum)


# print(field[0][0])
def get_value(a, b):
    # print("a,b",a,b)
    # print(w_sum[b][0])
    # print(h_sum[a][0])
    # print(field[w_sum[b][0]][h_sum[a][0]])
    return h_sum[a][1] + w_sum[b][1] - field[h_sum[a][0]][w_sum[b][0]]


for i in range(H):
    if h_sum[0][1] != h_sum[i][1]:
        max_h = i - 1
        break
else:
    max_h = H - 1

for i in range(W):
    if w_sum[0][1] != w_sum[i][1]:
        max_w = i - 1
        break
else:
    max_w = W - 1

# print(max_w,max_h)
for i in range(max_h+1):
    for j in range(max_w+1):
        if field[i][j] == 0:
            # print("unko")
            print(get_value(i, j))
            sys.exit()
else:
    print(get_value(0, 0))

Submission status: Wrong Answer

Solution code:
from collections import Counter
h,w,m=map(int,input().split())
h=[]
w=[]
for i in range(m):
    h1,w1=map(int,input().split())
    h.append(h1)
    w.append(w1)
h_counter=Counter(h)
w_counter=Counter(w)
for i in range(m):
    if h[i]==h_counter.most_common()[0][0] and w[i]==w_counter.most_common()[0][0]:
        print(h_counter.most_common()[0][1]+w_counter.most_common()[0][1]-1)
        exit()
else:
    print(h_counter.most_common()[0][1]+w_counter.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
a,b,m = map(int,input().split())
data = []
H,W = set(),set()
for i in range(m):
  h,w = map(int,input().split())
  data.append([h,w])
  H.add(h)
  W.add(w)
H = sorted(list(H))
W = sorted(list(W))
comp = [[bisect_right(H,h)-1,bisect_right(W,w)-1] for h,w in data]
data = [[0 for i in range(len(W))] for j in range(len(H))]
y = [sum(data[j])for j in range(len(H))]
t = [sum([data[i][j] for i in range(len(H))]) for j in range(len(W))]

res = 0
for i,p in enumerate(y):
  for j,q in enumerate(t):
    res = max(res,p+q-data[i][j])

print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W,M=map(int,input().split())
hl=[]
wl=[]
hwl=set()
for _ in range(M):
    h,w=map(int,input().split())
    hl.append(h)
    wl.append(w)
    hwl.add((h,w))
hl=Counter(hl).most_common()
wl=Counter(wl).most_common()
if (hl[0][0],wl[0][0]) not in hwl:
    print(hl[0][1]+wl[0][1])
else:
    print(hl[0][1]+wl[0][1]-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H,W,M = map(int,input().split())
YX = [tuple(map(int,input().split())) for i in range(M)]
yxs = set(YX)

from collections import Counter
xc = Counter()
yc = Counter()
for y,x in YX:
    yc[y] += 1
    xc[x] += 1

ans = 0
for y,x in YX:
    ans = max(ans, yc[y] + xc[x] - 1)

xmc = xc.most_common(3000)
ymc = yc.most_common(3000)
xmx = xmc[0][1]
ymx = ymc[0][1]
for xk,xv in xmc:
    if xv < xmx: break
    for yk,yv in ymc:
        if yv < ymx: break
        if (yk,xk) in yxs: continue
        ans = max(ans, yv + xv)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np
h,w,m = (int(x) for x in input().split())
hw = []
for _ in range(m):
    hw.append([int(x) for x in input().split()])

np_hw = np.array(hw)

c_h = collections.Counter(np_hw[:,0])
c_w = collections.Counter(np_hw[:,1])
ans = c_h.most_common()[0][1]+c_w.most_common()[0][1]
if [c_h.most_common()[0][0],c_w.most_common()[0][0]] in hw:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M = map(int,input().split( ))
Hs = [0 for _ in range(H)]
Ws = [0 for _ in range(W)]
hws = []
for _ in range(M):
    h,w = map(int,input().split( ))
    hws.append([h-1,w-1])
    Hs[h-1] += 1
    Ws[w-1] += 1
hw = [np.argmax(Hs),np.argmax(Ws)]
if hw in hws:
    print(max(Hs) + max(Ws) - 1)
else:
    print(max(Hs) + max(Ws))

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
Hsum = [0] * H
Wsum = [0] * W
hw = []
for m in range(M):
  h, w = map(int, input().split())
  Hsum[h-1] += 1
  Wsum[w-1] += 1
  hw.append(str(h-1)+"_"+str(w-1))

res = max(Hsum) + max(Wsum)
print(res - 1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    H, W, M = map(int, input().split())
    bomb = set()
    yoko = [0] * W
    tate = [0] * H
    for _ in range(M):
        h, w = map(int, input().split())
        bomb.add((h-1, w-1))
        yoko[w - 1] += 1
        tate[h - 1] += 1

    idx_yoko = [(yoko[i], i) for i in range(W)]
    idx_tate = [(tate[i], i) for i in range(H)]
    idx_yoko.sort(reverse=True)
    idx_tate.sort(reverse=True)
    ans = 0
    for p in range(min(1000, W)):
        for q in range(min(1000, H)):
            yoko_bomb, idx_w = idx_yoko[p]
            tate_bomb, idx_h = idx_tate[q]
            get_bomb = yoko_bomb + tate_bomb
            if (idx_h, idx_w) in bomb: get_bomb -= 1
            ans = max(ans, get_bomb)
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
points = []
xs = {}
ys = {}
for i in range(m):
    x,y = map(int,input().split())
    points.append([x,y])
    if xs.get(str(x)):
        xs[str(x)] += 1
    else:
        xs[str(x)] = 1
    if ys.get(str(y)):
        ys[str(y)] += 1
    else:
        ys[str(y)] = 1
max_x = max(xs, key=xs.get)
max_y = max(ys, key=ys.get)
if [xs[max_x], ys[max_y]] in points:
    print(xs[max_x] + ys[max_y]-1)
else:
    print(xs[max_x] + ys[max_y])

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split()) 
A =[[] for i in range(h)]
B = [[] for j in range(w)] 
C = []
for i in range(m):
    a, b =map(int,input().split()) 
    a = a- 1
    b = b- 1
    A[a].append(b) 
    B[b].append(a) 
    C.append((a,b)) 
    

map = [[0]*w for i in range(h)]
ans = 0
for i in range(m):
    a, b = C[i]
    if map[a][b] == 1:
        continue 
    queue = [(a,b)]
    temp  = len(A[a])-1 + len(B[b])-1 + 1
    
    ans = max(ans, temp)

print(ans)

Submission status: Wrong Answer

Solution code:
H, W, N = map(int, input().split())
h_array = [0]*H
w_array = [0]*W
for _ in range(N):
    h, w = map(int, input().split())
    h_array[h-1] +=1
    w_array[w-1] +=1

max_h = max(h_array)
h_indexes = [i for i, x in enumerate(h_array) if x == max_h]
max_w = max(w_array)
w_indexes = [i for i, x in enumerate(w_array) if x == max_w]

count=0
for i in range(len(h_indexes)):
    if h_indexes[i]	in w_indexes:
      if max_h + max_w -1 > count:
      	count = max_h + max_w -1
    else:
      if max_h + max_w > count:
      	count = max_h + max_w
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

    retu = Counter()
    gyo = Counter()

    ipt = [[] for _ in range(H)]

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

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

    return rmm+gmm

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

            if g[0] not in ipt[r[0]]:
                return rmm+gmm
    
    return rmm+gmm-1
    """

print(solver())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

H, W, M = map(int, input().split())
targets = []
tate = []
yoko = []
for i in range(M):
    i = list(map(int, input().split()))
    targets.append(i)
    tate.append(i[0])
    yoko.append(i[1])

c1 = collections.Counter(tate)
c2 = collections.Counter(yoko)
most_c1 = c1.most_common()[0][1]
most_c2 = c2.most_common()[0][1]
if [c1.most_common()[0][0], c2.most_common()[0][0]] in targets:
    print(most_c1 + most_c2 - 1)
else:
    print(most_c1 + most_c2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H,W,M = map(int,input().split())
YX = [tuple(map(int,input().split())) for i in range(M)]
yxs = set(YX)

from collections import Counter
xc = Counter()
yc = Counter()
for y,x in YX:
    yc[y] += 1
    xc[x] += 1

ans = 0
for y,x in YX:
    ans = max(ans, yc[y] + xc[x] - 1)

xmc = xc.most_common(1000)
ymc = yc.most_common(1000)
xmx = xmc[0][1]
ymx = ymc[0][1]
for xk,xv in xmc:
    if xv < xmx: break
    for yk,yv in ymc:
        if yv < ymx: break
        if (yk,xk) in yxs: continue
        ans = max(ans, yv + xv)
print(ans)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
hs = [0] * h
ws = [0] * w
pos = [ws.copy()]*h
for _ in range(m):
    hi, wi = map(int, input().split())
    pos[hi-1][wi-1] = 1
    hs[hi-1] += 1
    ws[wi-1] += 1
    
mh = max(hs)
mhs = []
for i in range(h):
    if hs[i] == mh:
        mhs.append(i)

mw = max(ws)
mws = []
for i in range(w):
    if ws[i] == mw:
        mws.append(i)

flg = False
for i in mhs:
    for j in mws:
        if pos[i][j]==0:
            flg = True
            print(max(hs) + max(ws))
            break
    if flg:
        break
else:
    print(max(hs) + max(ws) - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,m,targets = map(int,input().split())
r,c = {},{}
rcnt,ccnt = Counter(),Counter()
done = set()
for _ in range(targets):
    i,j = map(int,input().split())
    done.add((i,j))
    rcnt[i] += 1
    ccnt[j] += 1
    if i in r:
        r[i].append(j)
    else:
        r[i] = [j]
    if j in c:c[j]+=1
    else:c[j]=1
#print(r,c)
mx = 0

for key in r.keys():
    arr = r[key]
    l = len(arr)
    for v in arr:
        cand = l + c[v] - 1
        mx = max(cand,mx)
rcnt = [(k,v) for (k,v) in rcnt.items()]
ccnt = [(k,v) for (k,v) in ccnt.items()]

rcnt.sort(key = lambda x:x[1],reverse = True)
ccnt.sort(key = lambda x:x[1],reverse = True)
rcnt = rcnt[:500]
ccnt = ccnt[:500]
#print(rcnt,ccnt)
#print(done)
for row in rcnt:
    for col in ccnt:
        rowk,colk = row[0],col[0]
        if rowk in r and colk in c and (rowk,colk) not in done:
            cand = len(r[rowk]) + c[colk]
            mx = max(cand,mx)
print(mx)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split(' '))
H = [0 for _ in range(h+1)]
W = [0 for _ in range(w+1)]
bomb = set()
for m in range(m):
  i, j = map(int, input().split(' '))
  bomb.add((i, j))
  H[i] += 1
  W[j] += 1
  
max_h = max(H)
max_w = max(W)
target_h = [i for i, v in enumerate(H) if v == max_h]
target_w = [i for i, v in enumerate(W) if v == max_w]

for m in target_h:
  for n in target_w:
    if (m, n) not in bomb:
      print(max_h + max_w)
      break
print(max_h + max_w - 1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H,W,M = map(int,input().split())
YX = [tuple(map(int,input().split())) for i in range(M)]
yxs = set(YX)

from collections import Counter
xc = Counter()
yc = Counter()
for y,x in YX:
    yc[y] += 1
    xc[x] += 1

ans = 0
for y,x in YX:
    ans = max(ans, yc[y] + xc[x] - 1)

xmc = xc.most_common(500)
ymc = yc.most_common(500)
xmx = xmc[0][1]
ymx = ymc[0][1]
for xk,xv in xmc:
    if xv < xmx: break
    for yk,yv in ymc:
        if yv < ymx: break
        if (yk,xk) in yxs: continue
        ans = max(ans, yv + xv)
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
P=list()
P_X=[0]*(H+1)
P_Y=[0]*(W+1)
for _ in range(M):
    P.append(list(map(int,input().split())))
for m in range(M):
    P_X[P[m][0]]+=1
for m in range(M):
    P_Y[P[m][1]]+=1
Max_X=max(P_X)
Max_Y=max(P_Y)
if [P_X.index(Max_X),P_Y.index(Max_Y)] in P:
    answer=max(P_X)+max(P_Y)-1
else:
    answer=max(P_X)+max(P_Y)
print(answer)

Submission status: Wrong Answer

Solution code:
h,w,m = map(int, input().split())
retu = [0 for i in range(h)]
gyou = [0 for  i in range(w)]
h_max = 0
w_max = 0
bom = []
h_li =  []
w_li = []
for i in range(m):
    hi, wi = map(int, input().split())
    hi -= 1
    wi -= 1
    bom.append([hi,wi])
    retu[hi] += 1
    gyou[wi] += 1
    if retu[hi] > h_max:
        h_max = retu[hi]
        h_li = [hi]
    elif retu[hi] == h_max:
        h_li.append(hi)
    if gyou[wi] > w_max:
        w_max = gyou[wi]
        w_li = [wi]
    elif gyou[wi] == w_max:
        w_li.append(wi)
ans = h_max + w_max -1
for i in range(len(h_li)):
    for j in range(len(w_li)):
        if [h_li[i],w_li[j]] not in bom:
            ans += 1
            break
        else:
            continue
    break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    H, W, M = map(int, input().split())
    hw = []
    Hlist = [0] * H
    Wlist = [0] * W
    hset = set()
    wset = set()
    hwmatrix = [[0] * W]*H

    for _ in range(M):
        h, w = map(int, input().split())
        Hlist[h-1] += 1
        Wlist[w-1] += 1
        hw.append([h, w])
        hset.add(h)
        wset.add(w)
        hwmatrix[h-1][w-1] = 1

    hmax = [i for i, x in enumerate(Hlist) if x == max(Hlist)]
    wmax = [i for i, x in enumerate(Wlist) if x == max(Wlist)]

    flag = False
    for h in hmax:
        for w in wmax:
            if hwmatrix[h][w] == 0:
                flag = True
                break

    if flag:
        print(Hlist[h] + Wlist[w])
    else:
        print(Hlist[h] + Wlist[w] - 1)





if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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