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 collections
import time
H, W, M = map(int, input().split())

h_list = []
w_list = []
hw_list = []

#start_time = time.time()

for m in range(M):
    h_buf, w_buf = map(int, input().split())
    h_list.append(h_buf)
    w_list.append(w_buf)
    hw_list.append([h_buf, w_buf])

#print(time.time()-start_time)
h_c = collections.Counter(h_list)
w_c = collections.Counter(w_list)
h_c_list = h_c.most_common()
w_c_list = w_c.most_common()
#print(time.time()-start_time)

M = 0
count_h = 0
count_w = 0
M_j = 0
finish = 0

for k1, l in enumerate(h_c_list):
    if k1 > 100: break
    if (count_h > l[1])|(finish == 1): break
    count_h = l[1]
    i = l[0]
    M_i = count_h
    for k2, s in enumerate(w_c_list):
        if k2 > 100: break
        if (count_w > s[1])|(finish == 1): break
        count_w = s[1]
        j = s[0]
        M_buf = count_w
        #print(time.time()-start_time)
        if [i,j] in hw_list:
            M_buf -= 1
        else:
            finish = 1
        if M_buf>M_j:
            M_j = M_buf

print(M_i + M_j)

Submission status: Wrong Answer

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


def main():
    [h, w, m] = [int(e) for e in si().split()]
    bh, bw, g = dict(), dict(), dict()
    for i in range(1, h+1):
        bh[i] = 0
    for j in range(1, w+1):
        bw[j] = 0
    mh, mw, mr, mc = 0, 0, 0, 0
    for _ in range(m):
        [r, c] = [int(e) for e in si().split()]
        g[(r, c)] = 1
        bh[r] += 1
        bw[c] += 1
        if bh[r] > mh:
            mh = bh[r]
            mr = r
        if bw[c] > mw:
            mw = bw[c]
            mc = c
    if (mr, mc) not in g:
        print(mh+mw)
    else:
        print(mh+mw-g[(mr, mc)])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
l = []
dic_h, dic_w = {}, {}
list_h, list_w = [], []
for i in range(M):
  h,w = map(int, input().split())
  h, w = h-1, w-1
  l.append([h,w])
  if h not in list_h:
    dic_h[h] = 1
    list_h.append(h)
  else:
    dic_h[h] += 1
  if w not in list_w:
    dic_w[w] = 1
    list_w.append(w)
  else:
    dic_w[w] += 1
dic_h = sorted(dic_h.items(), key=lambda x:x[1], reverse=True)
dic_w = sorted(dic_w.items(), key=lambda x:x[1], reverse=True)
hc, wc, count = 0, 0, 0

if [dic_h[hc][0],dic_w[wc][0]] in l:
  print(dic_h[hc][1]+dic_w[wc][1]-1)
else:
  print(dic_h[hc][1]+dic_w[wc][1])

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
h = [0]*H
w = [0]*W
for i in range(M):
  a,b = map(int,input().split())
  h[a-1] += 1
  w[b-1] += 1
print(max(h)+max(w))

Submission status: Wrong Answer

Solution code:
from sys import exit

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

r = [0] * H
c = [0] * W
l = []
for _ in range(M):
    h, w = map(int, input().split())
    l.append([h-1, w-1])
    r[h-1] += 1
    c[w-1] += 1

set_r = set()
set_c = set()
max_r, max_c = max(r), max(c)

for i in range(H):
    if r[i] == max_r:
        set_r.add(i)

for i in range(W):
    if c[i] == max_c:
        set_c.add(i)

for x, y in l:
    if x in set_r and y in set_c:
        print(max_r + max_c - 1)
        exit()

print(max_r + max_c)

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
Hlist= {}
Wlist ={}
HWlist = []
for i in range(M):
    h,w = map(int,input().split())
    if h not in Hlist:
        Hlist[h] = 1
    else:
        Hlist[h] += 1
    if w not in Wlist:
        Wlist[w] = 1
    else:
        Wlist[w] += 1
    HWlist.append([h,w])
h2 = max([(v,k) for k,v in Hlist.items()])
h = h2[1]
hmax = h2[0]
Dua2 = []
for k,v in Hlist.items():
    if v == hmax:
        Dua2.append(k)
w2 = max([(v,k) for k,v in Wlist.items()])
w = w2[1]
wmax = w2[0]
Dua = []
for k,v in Wlist.items():
    if v == wmax:
        Dua.append(k)
Answer = Hlist[h] + Wlist[w]
Wld = set()
Hld = set()
sign = 0
for i in range(M):
    if HWlist[i][0] == h:
        Wld.add(HWlist[i][1])
for _ in range(len(Dua)):
    if Dua[_] not in Wld:
        break
    elif _ == len(Dua)-1:
        sign -= 1
for i in range(M):
    if HWlist[i][1] == w:
        Wld.add(HWlist[i][0])
for _ in range(len(Dua2)):
    if Dua2[_] not in Wld:
        break
    elif _ == len(Dua2)-1:
        sign -= 1
if sign == -2:
    Answer -= 1
print(Answer)

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)]
hs = [i for i, x in enumerate(Hs) if x == max(Hs)]
ws = [i for i, x in enumerate(Ws) if x == max(Ws)]
in_out = 0
for h in hs:
    for w in ws:
        if not([h,w] in hws):
            in_out = 1
if not(hw in hws):
    print(max(Hs) + max(Ws) - 1)
else:
    print(max(Hs) + max(Ws))

Submission status: Wrong Answer

Solution code:
import math
import collections
import itertools

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

    listH=[]
    listW=[]
    for i in range(M):
        h,w=map(int,input().split())
        listH.append(h)
        listW.append(w)

    countedh=collections.Counter(listH)
    countedw=collections.Counter(listW)

    retH = [letter for letter,count in countedh.most_common() if count == countedh.most_common()[0][1]]
    retW = [letter for letter,count in countedw.most_common() if count == countedw.most_common()[0][1]]

    # print(retH)
    # print(retW)
    tmp=0
    tmpMax=0

    for i in range(len(retH)):
        for j in range(len(retW)):
            tmp=0
            for k in range(M):
                if(listH[k]==retH[i] or listW[k]==retW[j]):
                    tmp+=1
                if(tmpMax!=0 and listH[k]==retH[i] and listW[k]==retW[j]):
                    break
            if(tmp>tmpMax):
                tmpMax=tmp
                break
        else:
            continue
        break
    print(tmpMax)
resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter
h,w,m = map(int,input().split())
lir = []
lirr = []
lic = []
licc = []
ans = 0
for _ in range(m):
    x,y = map(int,input().split())
    lir.append(x)
    lirr.append(x)
    lic.append(y)
    licc.append(y)
maxr = Counter(lir).most_common()[0][0]
for i in range(m):
    if lir[i] == maxr:
        ans+=1
        lir[i] = -1
        lic[i] = w+i
if min(lic) <= w:
    maxc = Counter(lic).most_common()[0][0]
    for i in lic:
        if i == maxc:
            ans+=1

anss = 0
maxcc = Counter(licc).most_common()[0][0]
for i in range(m):
    if licc[i] == maxcc:
        anss+=1
        licc[i] = -1
        lirr[i] = w+i
if min(lirr) == w:
    print(max(ans,anss))
else:
    maxrr = Counter(lirr).most_common()[0][0]
    for i in lirr:
        if i == maxrr:
            anss+=1
    print(max(ans,anss))

Submission status: Wrong Answer

Solution code:
#import random

def putmx(lis):
  ret=[]
  mx=max(lis)
  for i in range(len(lis)):
    if mx==lis[i]:
      ret.append(i)
  return ret
  

h,w,m=map(int,input().split())
#inp=[(random.randrange(1,h+1),random.randrange(1,w+1)) for i in range(m)]
hb=[0]*h
wb=[0]*w
bmb=[]
for i in range(h):
  bmb.append([])
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  bmb[hh].append(ww)
  hb[hh]+=1
  wb[ww]+=1

#hmx=[i for i, x in enumerate(hb) if x == max(hb)]
#wmx=[i for i, x in enumerate(wb) if x == max(wb)]
hmx=putmx(hb)
wmx=putmx(wb)
mhb=max(hb)
mwb=max(wb)
#print(hb,wb,hmx,wmx)
fl=False
for i in hmx:
  for j in wmx:
    if j in bmb[i]:
      print(mhb+mwb-1)
      fl=True
      break
  if fl:
    break
else:
  print(mhb+mwb)

Submission status: Wrong Answer

Solution code:
from collections import Counter
h, w, m = map(int, input().split())
blist = [list(map(int, input().split())) for _ in range(m)]

ans_l = [0]*h
for i in range(h):
    ans = 0
    l = []
    for j in blist:
        if j[0] == i + 1:
            ans += 1
        else:
            l.append(j[1])
    if l != []:
        l_c = Counter(l)
        ans += max(l_c.values())
        ans_l[i] = ans

print(max(ans_l))

Submission status: Wrong Answer

Solution code:
import numpy
h,w,m=map(int,input().split())
h_arr=[0]*h
w_arr=[0]*w
record = set()
for i in range(m):
    tmp_h, tmp_w = map(int,input().split())
    record.add((tmp_h,tmp_w))
    h_arr[tmp_h-1] += 1
    w_arr[tmp_w-1] += 1
#最大の列と行の交差点に爆破対象があるかどうかがわからない?
max_h = max(h_arr)
max_w = max(w_arr)
max_h_indexes = [i for i, x in enumerate(h_arr) if x == max_h]
max_w_indexes = [i for i, x in enumerate(w_arr) if x == max_w]
ans = max_h + max_w -1
#たぶんindexesが多いときにTLEになってるんじゃないか
if not(max_h == w or max_w == h):
    for i in max_h_indexes:
        for j in max_w_indexes:
            if not((i+1,j+1) in record):
                ans += 1
                break
            else:
                continue
        break
print(ans)

Submission status: Wrong Answer

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

from collections import Counter as co
ws=co(ys).most_common(63)
if len(ws)==1:ws.append((0,0))
#key value
hs=co(xs)
ans=1
for i in range(1,h+1):
    preans=0 if i not in hs else hs[i]
    for k,v in ws:
        ans=max(ans,preans+v-int((i,k) in setobj))
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
H, W, M = map(int, input().split())
objs = [list(map(int, input().split())) for i in range(M)]
count_h = defaultdict(int)
count_w = defaultdict(int)
for oh, ow in objs:
    count_h[oh] += 1
    count_w[ow] += 1
res = max(count_h.values()) + max(count_w.values())
ch = max(count_h, key=count_h.get)
cw = max(count_h, key=count_h.get)
for oh, ow in objs:
    if ch==oh and cw==ow:
        res -= 1
        break
print(res)

Submission status: Wrong Answer

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

b = 0
indexh = 0
indexw = 0
takasa = []
haba = []
ans = 0

for i in range(1, H+1):
    for j in range(M):
        if A[j][0] == i:
            b += 1
    takasa.append(b)
    b=0

for i in range(1, W+1):
    for j in range(M):
        if A[j][1] == i:
            b += 1
    haba.append(b)
    b=0

ans = max(takasa) + max(haba)
if [takasa.index(max(takasa))+1, haba.index(max(haba))+1] in A:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c = map(int, input().split())
d = [input().split() for l in range(c)]
counter_x = {}
counter_y = {}
for n in range(c):
    if d[n][0] in counter_x.keys():
        counter_x[d[n][0]] += 1
    else:
        counter_x[d[n][0]] =1
    if d[n][1] in counter_y.keys():
        counter_y[d[n][1]] += 1
    else:
        counter_y[d[n][1]] =1
max_x = max(counter_x, key=counter_x.get)
max_y = max(counter_y, key=counter_y.get)
if [max_x, max_y] in d:
    print(int(max(counter_x.values())) + int(max(counter_y.values())) - 1)
else:
    print(int(max(counter_x.values())) + int(max(counter_y.values())))

Submission status: Wrong Answer

Solution code:
h, w, m = list(map(int, input().strip().split()))
grid = []
for i in range(m):
    array = list(map(int, input().strip().split()))
    grid.append(array)
aa = []
bb = []
for i in range(m):
    array = grid[i]
    aa.append(array[0])
    bb.append(array[1])

from collections import defaultdict
d = defaultdict(int)
for i in aa:
    d[i] += 1
aa_result = max(d.items(), key=lambda x: x[1]) 

d = defaultdict(int)
for i in bb:
    d[i] += 1
bb_result = max(d.items(), key=lambda x: x[1]) 

# 爆発判定
result = 0
for i in range(m):
    array = grid[i]
    if array[0] == aa_result[0] or array[1] == bb_result[0]:
        result += 1

print (result)

Submission status: Wrong Answer

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

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

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

ans = tate[0][0]+yoko[0][0]-1
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

i = 0
while i < h and i <= 2500:
    j = 0
    while j < w and j <= 2500:
        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))
        if yoko[0][0] > yoko[j][0]+1:
            break
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

y_to_num = defaultdict(int)
x_to_num = defaultdict(int)

y_indexes = set()
x_indexes = set()

for _ in range(m):
    h, w = map(lambda x: int(x), input().split())
    y_to_num[h] += 1
    x_to_num[w] += 1
    
    y_indexes.add(h)
    x_indexes.add(w)
    
# print(y_to_num, x_to_num)
    
# for y, num_y in y_to_num:
#     for x, num_x in x_to_num:

max_num = 0
  
for y in range(h):
    for x in range(w):
        num = y_to_num[y+1] + x_to_num[x+1]
        if (y+1 in y_indexes) & (x+1 in x_indexes):
            num -= 1
        max_num = max(max_num, num)
        
print(max_num)

Submission status: Wrong Answer

Solution code:

def main():
    h, w, m = map(int, input().split())
    blis = []
    xdic = dict()
    ydic = dict()

    for _ in range(m):
        a, b = map(int, input().split())
        blis.append([a,b])

        if a in xdic:
            xdic[a] += 1
        else:
            xdic[a] = 1

        if b in ydic:
            ydic[b] += 1
        else:
            ydic[b] = 1

    xdic = sorted(xdic.items())
    ydic = sorted(ydic.items())
    
    xsaidai = xdic[0][1] 
    ysaidai = ydic[0][1]

    ans = 0

    if xsaidai >= ysaidai:
        for j in range(min(w, 10**2, len(xdic))):
            for i in range(min(h, 10**2, len(ydic))):
                x = xdic[j][0]
                tmp = 0
                y = ydic[i][0]
                for bomb in blis:
                    if bomb[1] == y or bomb[0] == x:
                        tmp += 1
                if ans < tmp:
                    ans = tmp
    else:
        for i in range(min(h, 10**2, len(ydic))):
            for j in range(min(w, 10**2, len(xdic))):
                y = ydic[i][0]
                tmp = 0
                x = xdic[j][0]
                for bomb in blis:
                    if bomb[1] == y or bomb[0] == x:
                        tmp += 1
                if ans < tmp:
                    ans = tmp
    print(ans)
            


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def binary_search(func, array, left=0, right=-1):
    if right==-1:right=len(array)-1
    y_left, y_right = func(array[left]), func(array[right])
    while True:
        middle = (left+right)//2
        y_middle = func(array[middle])
        if y_left==y_middle: left=middle
        else: right=middle
        if right-left==1:break

    return left

H,W,M=map(int,input().split())
hw = defaultdict(int)
sum1=[0]*H
sum2=[0]*W
for i in range(M):
  h,w=map(int,input().split())
  hw[(h-1,w-1)] += 1
  sum1[h-1] += 1
  sum2[w-1] += 1

sum1 = sorted(enumerate(sum1),key=lambda x:x[1],reverse=True)
sum2 = sorted(enumerate(sum2),key=lambda x:x[1],reverse=True)

Idx1 = binary_search(lambda x:x[1]>sum1[0][1]-2, sum1)
Idx2 = binary_search(lambda x:x[1]>sum2[0][1]-2, sum2)

ans=0
for idx1,val1 in sum1[:Idx1+1]:
  for idx2,val2 in sum2[:Idx2+1]:
    tmp = val1+val2-hw[(idx1,idx2)]
    ans = max(ans,tmp)
    
print(ans)

Submission status: Wrong Answer

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

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

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

ans = tate[0][0]+yoko[0][0]-1
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

i = 0
while i < h and i <= 2000:
    j = 0
    while j < w and j <= 2000:
        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))
        if yoko[0][0] > yoko[j][0]+1:
            break
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

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

counter = collections.Counter(h)
h_max = max(counter.values())
mode_h = [key for key , value in counter.items() if value == h_max]
counter = collections.Counter(w)
w_max = max(counter.values())
mode_w = [key for key , value in counter.items() if value == w_max]

ans = 0
for i in mode_h:
    for j in mode_w:
        if ans < h.count(i) + w.count(j):
            ans = h.count(i) + w.count(j)
            ans_i, ans_j = i, j

for k in range(M):
    if h[k] == ans_i and w[k] == ans_j:
        ans -= 1
        break

print(ans)

Submission status: Wrong Answer

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import deque

def main():
	h,w,m=MI()
	A=[0]*(h+1)
	B=[0]*(w+1)
	C=[[] for _ in range(h+1)]

	for _ in range(m):
		hh,ww=MI()
		A[hh]+=1
		B[ww]+=1
		C[hh].append(ww)


	for i in range(h+1):
		C[i].sort()

	AA=max(A)
	BB=max(B)

	x=[]
	y=[]

	for i,v in enumerate(A):
		if v==AA:
			x.append(i)

	for i,v in enumerate(B):
		if v==BB:
			y.append(i)

	#print(x,y,AA,BB)
	#print(C)
	ans=0

	for i in x:
		#print("a")
		#print(C[i])
		#print(y)
		a=0
		for j in y:
			while a<len(C[i]):
				if j==C[i][a]:
					a+=1
					break
				elif j<C[i][a]:
					print(AA+BB)
					exit()
				else:
					a+=1

	print(AA+BB-1)
















if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import random

def main():
    H, W, M = list(map(int, input().split()))
    h = []
    w = []

    bombs = []
    for i in range(M):
        hi, wi = list(map(int, input().split()))
        h.append(hi)
        w.append(wi)
        bombs.append([hi,wi])

    count_h = []
    count_w = []
    for i in range(M):
        count_h.append(sum(x==i for x in h))
        count_w.append(sum(x==i for x in w))

    max_h = max(count_h)
    indexes_h = [i for i, v in enumerate(count_h) if v == max(count_h)]

    max_w = max(count_w)
    indexes_w = [i for i, v in enumerate(count_w) if v == max(count_w)]

    ans = max_h + max_w

    for i in indexes_h:
        for j in indexes_w:
            if [i, j] not in bombs:
                print(i,j)
                print(ans)
                exit()

    print(ans-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, W, M = NMI()
    
    BOMB_HW = [NLI() for _ in range(M)]
    
    bomb_h,bomb_w = zip(*BOMB_HW)

    bomb_most_h = collections.Counter(bomb_h).most_common()[0]
    bomb_most_w = collections.Counter(bomb_w).most_common()[0]
        
    bh = bomb_most_h[0]
    bh_destroy = bomb_most_h[1]
    
    bw = bomb_most_w[0]
    bw_destroy = bomb_most_w[1]
    
    if [bh,bw] in BOMB_HW:
        print(bh_destroy+bw_destroy-1)
    else:
        print(bh_destroy+bw_destroy)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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))

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

Submission status: Wrong Answer

Solution code:
H, W, M = list(map(int, input().split()))
h = [0] * M
w = [0] * M
hw = [[0] * 2 for i in range(M)]
tmp_h = [0] * (H + 1)
tmp_w = [0] * (W + 1)
for i in range(M):
    h[i], w[i] = list(map(int, input().split()))
    hw[i][0] = h[i]
    hw[i][1] = w[i]
    tmp_h[h[i]] += 1
    tmp_w[w[i]] += 1
max_h = [i for i, v in enumerate(tmp_h) if v == max(tmp_h)]
max_w = [i for i, v in enumerate(tmp_w) if v == max(tmp_w)]
ans = 0
tmp = 0
fail = []
tmp_w2 = [0] * (W + 1)
for i in range(len(max_h)):
    for j in range(M):
        if hw[j][0] == max_h[i]:
            fail.append(hw[j][1])
            tmp_w2[hw[j][1]] += 1
    tmp = tmp_h[max_h[i]] + tmp_w2.index(max(tmp_w2))
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Wrong Answer

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

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

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

ans = tate[0][0]+yoko[0][0]-1
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

i = 0
while i < h and i <= 1180:
    j = 0
    while j < w and j <= 1180:
        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))
        if yoko[0][0] > yoko[j][0]+1:
            break
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def main():
    h, w, m = [int(i) for i in input().split()]
    d_h = defaultdict(int)
    d_w = defaultdict(int)
    bom = set()
    for _ in range(m):
        h, w = [int(i) for i in input().split()]
        bom.add((h, w))
        d_h[h] += 1
        d_w[w] += 1
    H = sorted(d_h.items(), key=lambda x: -x[1])
    W = sorted(d_w.items(), key=lambda x: -x[1])
    ans = H[0][1] + W[0][1]
    if (H[0][0], W[0][0]) in bom:
        ans -= 1
    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    h,w,m = LI()
    hw = LIR(m)
    # h, w, m = [3 * 10 ** 5] * 3
    # hw = [(i, i) for i in range(3 * 10 ** 5)]
    dh = defaultdict(int)
    dw = defaultdict(int)
    ma = defaultdict(int)
    for hi, wi in hw:
        dh[hi] += 1
        dw[wi] += 1
        ma[(hi, wi)] = 1
    maxh = sorted(dh.items(), key=lambda x: -x[1])
    maxw = sorted(dw.items(), key=lambda x: -x[1])
    ans = 0
    for h, ch in maxh[:5]:
        for w, cw in maxw[:5]:
            tmp = 0
            for hi, wi in hw:
                if hi == h or w == wi:
                    tmp += 1
            ans = max(ans, tmp)
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
row=defaultdict(int)
col=defaultdict(int)
H,W,M=map(int,input().split())
#matrix=[[1 for i in range(W)] for j in range(H)]
matrix=defaultdict(bool)
for i in range(M):
    h,w=map(int,input().split())
    row[h-1]+=1
    col[w-1]+=1
    matrix[(h-1,w-1)]=True
#print(row)
#print(col)
#for i in matrix:
#    print(*i)
temp=list(row.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt=0
for i in range(W):
    temp=0
    if matrix[(a,i)]:
        temp=(b+col[i]-1)
    else:
        temp=(b+col[i])
    cnt=max(cnt,temp)
print(cnt)

Submission status: Wrong Answer

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def array(size, init=0):
    return [[init for j in range(size[1])] for i in range(size[0])]


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


directions = np.array([[1, 0], [0, 1], [-1, 0], [0, -1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def permutate(x, A):
    n = len(x)
    res = [-1]*n
    for i in range(n):

        res[i] = x[A[i]]
    return res


def generate_bin(digit):
    for b in range(2**digit):
        b = bin(b)
        tmp = b[2:].zfill(digit)
        yield list(map(int, tmp))
        # b=list(map(int,list(b[2:].zfill(digit))))
        # yield b


H, W, M = acinput()

Bh = [[0, i] for i in range(H+1)]
Bw = [[0, i] for i in range(W+1)]
B = {}
for i in range(M):
    h, w = acinput()
    Bh[h][0] += 1
    Bw[w][0] += 1
    B[(h, w)] = 1

Bh = sorted(Bh,  reverse=True)
Bw = sorted(Bw,  reverse=True)

Hidx = []
Widx = []
k = 0
while True:
    Hidx.append(k)
    if Bh[k][0] > Bh[k+1][0]:
        break
    k += 1
    if k >= len(Bw):
        break

k = 0
while True:
    Widx.append(k)
    if Bw[k][0] > Bw[k+1][0]:
        break
    k += 1
    if k >= len(Bw):
        break

'''
print(Bh)
print(Hidx)
print(Bw)
print(Widx)
'''
for hi in Hidx:
    h = Bh[hi][1]
    for wi in Widx:
        w = Bw[wi][1]
        if not((h, w) in B):
            res = Bh[h-1][0]+Bw[w-1][0]
            print(res)
            #print(h, w)
            sys.exit()


print(Bh[0][0]+Bw[0][0]-1)

Submission status: Wrong Answer

Solution code:
import collections
a = input().split()
M = int(a[2])
hidari = []
migi = []
c = []

for i in range(M):
  b = input().split()
  hidari.append(b[0])
  migi.append(b[1])
  c.append(b)
  
print(hidari)
print(migi)
print(c)

countleft = collections.Counter(hidari)
countright = collections.Counter(migi)
leftmax = countleft.most_common()[0][1]
rightmax = countright.most_common()[0][1]
tempmax = int(leftmax + rightmax)

leftkeys = [k for k, v in countleft.items() if v == leftmax]
rightkeys = [k for k, v in countright.items() if v == rightmax]
print(leftkeys)
print(rightkeys)
leftkeyN = int(len(leftkeys))
rightkeyN = int(len(rightkeys))
flag = int(0)
cnt = int(0)
#これで左右の最頻回数はOK
#左右の最頻奴も探した
#ここから最頻同志になってるやつを探す

for T in range(M):
    if c[T][0] in leftkeys and c[T][1] in rightkeys:
        cnt = cnt + 1
    else:
        pass


if cnt == int(leftkeyN * rightkeyN):
    print(int(tempmax - 1))
else:
    print(int(tempmax))

Submission status: Wrong Answer

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

tate=[]
yoko=[]

for i in range(m):
    tate.append(hw[i][0])
    yoko.append(hw[i][1])

from collections import Counter
tatec=Counter(tate).most_common()
yokoc=Counter(yoko).most_common()

c_1_max=tatec[0][0]
c_1s=[]
for t in tatec:
    if t[0]==c_1_max:
        c_1s.append(t[0])

c_2_max=yokoc[0][0]
c_2s=[]
for y in yokoc:
    if t[0]==c_2_max:
        c_2s.append(t[0])


flag=False

for c_1, c_2 in zip(c_1s, c_2s):
    tmp_flag=0
    for i in range(m):
        h_i=hw[i][0]
        w_i=hw[i][1]
        if h_i!=c_1 or w_i!=c_2:
            tmp_flag+=1
    if tmp_flag==m:
        flag=True

print(tatec[0][1],yokoc[0][1])

print(max(tatec[0][1]+yokoc[0][1], 1) if flag else max(tatec[0][1]+yokoc[0][1]-1, 1))

Submission status: Wrong Answer

Solution code:
import copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = []
for i in range(H):
   object.append(copy.deepcopy(width))
for s in sys.stdin.readlines():
    h, w = map(int, s.split())
    height[h-1] += 1
    width[w-1] += 1
    object[h-1][w-1] = 1
h_max = max(height)
w_max = max(width)
cand_w = []
cand_h = []
for i in range(W):
   if width[i] == w_max:
      cand_w.append(i)
for i in range(H):
   if height[i] == h_max:
      cand_h.append(i)
ans = h_max + w_max - 1
ans += 1
print(ans)