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:
#提出16832275を参考
import sys
from collections import Counter

H, W, M = map(int, sys.stdin.readline().rstrip().split())#行数H、列数W、爆弾数M
hcnt = [0] * H#何行目に何個あるか
wcnt = [0] * W#何列目に何個あるか
bomb = []

for i in range(M):
    bh,bw=map(int,sys.stdin.readline().rstrip().split())
    hcnt[bh - 1] += 1#行方向
    wcnt[bw - 1] += 1#列方向
    bomb.append((bh - 1,bw - 1))
#hcnt [2,1]
#wcnt[1,1,1]
#bomb[[1,1],[0,0],[0,2]]
hmax = max(hcnt)#2
wmax = max(wcnt)#1

crs = 0#hmax and wmax crosspoint
for i, j in bomb:
    if i == hmax and j == wcnt:
        crs += 1
#all crosspoint has bomb
if crs == Counter(hcnt)[hmax] * Counter(wcnt)[wmax]:
    print(hmax + wmax - 1)
#more than one crosspoint has no bomb
else:
    print(hmax + wmax)

Submission status: Wrong Answer

Solution code:
H,W,N=[int(s) for s in input().split()]
hls=[0 for _ in range(H+1)]
wls=[0 for _ in range(W+1)]
bombs=[set() for _ in range(H+1)]
for _ in range(N):
  h,w=[int(s) for s in input().split()]
  hls[h]+=1
  wls[w]+=1
  bombs[h].add(w)
hmax=max(hls)
wmax=max(wls)
hmaxls=[i for i in range(H+1) if hls[i]==hmax]
wmaxls=[i for i in range(W+1) if wls[i]==wmax]
for h,w in zip(hmaxls,wmaxls):
  if not(w in bombs[h]):
    print(hmax+wmax)
    exit()
else:
  print(hmax+wmax-1)

Submission status: Wrong Answer

Solution code:
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

hb = defaultdict(int)
wb = defaultdict(int)
bomb = defaultdict(int)

for hwi in hw:
    h, w = hwi
    hb[h] += 1
    wb[w] += 1
    bomb[(h, w)] += 1

# print(hb, wb)

mhb = max(hb.values())
mwb = max(wb.values())

maxh = [key for key, val in hb.items() if val == mhb]
maxw = [key for key, val in wb.items() if val == mwb]

# print(maxh, maxw)

for h, w in zip(maxh, maxw):
    if bomb[(h, w)] == 0:
        print(mhb + mwb)
        exit()
print(mhb + mwb - 1)

Submission status: Wrong Answer

Solution code:
H,W,M=list(map(int,input().split()))
bomb=[]
import sys
sys.setrecursionlimit(10**7)
for i in range(M):
    bomb.append(list(map(int,input().split())))
import numpy as np
rows=np.zeros(H+1)
columns=np.zeros(W+1)
for i in range(M):
    rows[bomb[i][0]]+=1
    columns[bomb[i][1]]+=1

maxrows=0
rowi=[]
columni=[]
maxcolumns=0
for i in range(M):
    if maxrows<rows[bomb[i][0]]:
        rowi=[bomb[i][0]]
        maxrows=rows[bomb[i][0]]
    elif maxrows==rows[bomb[i][0]] and maxrows!=0:
        if bomb[i][0] not in rowi:
            rowi.append(bomb[i][0])
for i in range(M):
    if maxcolumns<columns[bomb[i][1]]:
        columni=[bomb[i][1]]
        maxcolumns=columns[bomb[i][1]]
    elif maxcolumns==columns[bomb[i][1]] and maxcolumns!=0:
        if bomb[i][1] not in columni:
            columni.append(bomb[i][1])

def total(rowi,columni):
    for i in rowi:
        for j in columni:
            if [i,j] not in bomb:
                print(maxrows+maxcolumns)
                return
    print(maxrows+maxcolumns-1)
    return
total(rowi,columni)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
H, W, M = map(int, input().split())#slow,行数H、列数W、爆弾数M
hcnt = [0] * H#何行目に何個あるか
wcnt = [0] * W#何列目に何個あるか
bomb = []

for i in range(M):
    bh, bw = map(int, input().split())
    hcnt[bh - 1] += 1#行方向
    wcnt[bw - 1] += 1#列方向
    if bomb.count([bh - 1,bw - 1]) == 0:
        bomb.append([bh - 1,bw - 1])
#hcnt [2,1]
#wcnt[1,1,1]
#bomb[[2,2],[1,1],[1,3]]
hmax = max(set(hcnt))#2
wmax = max(set(wcnt))#1
hmaxindex = [ i for i in range(H) if hcnt[i] == hmax]#[0]
wmaxindex = [ i for i in range(W) if wcnt[i] == wmax]#[0,1,2]
#crosspoint has not bomb
for i in range(len(hmaxindex)):
    for j in range(len(wmaxindex)):
        if bomb.count([i, j]) == 0:
            print(hmax + wmax)
            sys.exit()
        else:
            continue
#all crosspoint has bomb
print(hmax + wmax - 1)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
h_list = [0 for _ in range(h)]
w_list = [0 for _ in range(w)]
for i in range(m):
    a, b = map(int, input().split())
    h_list[a - 1] += 1
    w_list[b - 1] += 1
print(max(h_list) + max(w_list))

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
h_list = [0 for _ in range(h)]
w_list = [0 for _ in range(w)]
for i in range(m):
    a, b = map(int, input().split())
    h_list[a - 1] += 1
    w_list[b - 1] += 1
print(max(h_list) + max(w_list) - 1)

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
x = {}
y = {}
dic = {}
for _ in range(m):
    a,b = map(int,input().split())
    dic[(a,b)] = 1
    x[a] = x.get(a,0) + 1
    y[b] = y.get(b,0) + 1
p = max(x.values())
q = max(y.values())
cnt = 1
a = [i for i in x if i == p]
b = [j for j in y if j == q]
for i in a:
    for j in b:
        if dic.get((i,j),-1) == -1:
            cnt = 0
            break
    if not cnt:
        break
print(p+q-cnt)

Submission status: Wrong Answer

Solution code:
import sys
h,w,m = map(int,input().split())
H = [0]*(h)
W = [0]*(w)
ls = []
for _ in range(m):
    a,b = map(int,input().split())
    ls.append([a-1,b-1])
    H[a-1] += 1
    W[b-1] += 1
hm = max(H)
wm = max(W)
a = [i for i in H if i == hm]
b = [j for j in W if j == wm]
for i in a:
    for j in b:
        if [i,j] not in ls:
            print(hm+wm)
            sys.exit()
print(hm+wm-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

input = stdin.readline

Y, X, M = map(int, input().split())
bomb = set([tuple(map(int,inp.split())) for inp in stdin.read().splitlines()])
cx = collections.defaultdict(int)
cy = collections.defaultdict(int)
for y,x in bomb:
    cx[x] += 1
    cy[y] += 1
mx = max(cx.values())
my = max(cy.values())
candidateX = [x for (x,v) in cx.items() if v == mx]
candidateY = [y for (y,v) in cy.items() if v == my]
res = mx + my -1
for x in candidateX:
    for y in candidateY:
        if (y,x) not in bomb:
            res += 1
            break
print(res)

Submission status: Wrong Answer

Solution code:

# SHREE RAM

import os,sys
from io import BytesIO, IOBase
from collections import defaultdict


def main():
    h,w,m= map(int,input().split())
    x=defaultdict(lambda :0)
    y=defaultdict(lambda :0)
    z=[]
    for i in range(m):
        a,b=map(int,input().split())
        z.append([a,b])
        x[a]+=1
        t=-1
        y[b]+=1
    q=-1
    s=-1
    for i in x:
        if x[i]>t:
            t=x[i]
            q=i
    m2=-1
    for i in y:
        if y[i]>m2:
            m2=y[i]
            s=i
    print(t+m2 - int([q,s] in z))


#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

# SHREE RAM

import os,sys
from io import BytesIO, IOBase
from collections import defaultdict


def main():
    h,w,m= map(int,input().split())
    x=defaultdict(lambda :0)
    y=defaultdict(lambda :0)
    for i in range(m):
        a,b=map(int,input().split())

        x[a]+=1
        t=-1
        y[b]+=1
    for i in x:
        if x[i]>t:
            t=x[i]
    m2=-1
    for i in y:
        if y[i]>m2:
            m2=y[i]

    print(t+m2)


#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

# SHREE RAM

import os,sys
from io import BytesIO, IOBase
from collections import defaultdict


def main():
    h,w,m= map(int,input().split())
    x=defaultdict(lambda :0)
    y=defaultdict(lambda :0)
    for i in range(m):
        a,b=map(int,input().split())

        x[a]+=1
        t=-1
        y[b]+=1
    for i in x:
        if x[i]>t:
            t=x[i]
    p=-1
    for i in y:
        if y[i]>p:
            m2=y[i]

    print(t+m2)


#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
h_lst = [0]*h
w_lst = [0]*w
bomb = [['t']*w for i in range(h)]

for i in range(m):
  x,y = map(int,input().split())
  h_lst[x-1] += 1
  w_lst[y-1] += 1
  bomb[x-1][y-1] = 'b'

M_h = 0
Max_h = 0
for i in range(h):
  if Max_h < h_lst[i]:
    M_h = i
    Max_h = h_lst[i]
    
M_w = 0
Max_w = 0
for i in range(w):
  if Max_w < w_lst[i]:
    M_w = i
    Max_w = w_lst[i]  
  
if bomb[M_h][M_w] == 'b':
  print(Max_h+Max_w-1)
else:
  print(Max_h+Max_w)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

boms = []
for m in range(M):
    h, w = map(int, input().split())
    boms.append([h, w])

Bom = np.asarray(boms)

h_argmax = np.argmax(np.bincount(Bom[:, 0]))
w_argmax = np.argmax(np.bincount(Bom[:, 1]))

h_max = np.max(np.bincount(Bom[:, 0]))
w_max = np.max(np.bincount(Bom[:, 1]))


max = h_max + w_max

h_max_l = list()
w_max_l = list()

for i, h in enumerate(Bom[:, 0]):
    if h == h_argmax:
        h_max_l.append(i)

for i, w in enumerate(Bom[:, 1]):
    if w == w_argmax:
        w_max_l.append(i)

for ih in h_max_l:
    _w = Bom[ih, 1]
    for iw in w_max_l:
        if _w != iw:
            print(max)
            exit()
print(max-1)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
H,W,M = readInts()

dic1 = defaultdict(int)
dic2 = defaultdict(int)
s = set()
for i in range(M):
    h,w = map(lambda x:int(x)-1, input().split())
    dic1[h] += 1
    dic2[w] += 1
    s.add((h,w))
# print(dic)
# 答え
ans = 0
# for h in range(H):
#     for w in range(W):
#         if (h,w) in s:
#             ans = max(ans, dic1[h] + dic2[w] -1)
#         else:
#             ans = max(ans, dic1[h] + dic2[w])
# for h,w in s:
#     ans = max(ans, dic1[h] + dic2[w] - 1)
# 辞書の値が最大・最小となるキーを取得
max1 = max(dic1, key = dic1.get)
max2 = max(dic2, key = dic2.get)
if (max1,max2) in s:
    ans = max(ans, dic1[max1] + dic2[max2] - 1)
else:
    ans = max(ans, dic1[max1] + dic2[max2])
print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
H,W,M = readInts()

dic1 = defaultdict(int)
dic2 = defaultdict(int)
s = set()
for i in range(M):
    h,w = map(lambda x:int(x)-1, input().split())
    dic1[h] += 1
    dic2[w] += 1
    s.add((h,w))
# print(dic)
# 答え
ans = 0
# for h in range(H):
#     for w in range(W):
#         if (h,w) in s:
#             ans = max(ans, dic1[h] + dic2[w] -1)
#         else:
#             ans = max(ans, dic1[h] + dic2[w])
for h,w in s:
    ans = max(ans, dic1[h] + dic2[w] - 1)
# 辞書の値が最大・最小となるキーを取得
max1 = max(dic1, key = dic1.get)
max2 = max(dic2, key = dic2.get)
if (max1,max2) in s:
    pass
else:
    ans = max(ans, dic1[max1] + dic2[max2])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
h, w, m = map(int, input().split())

row = [[0, 0] for _ in range(h + 1)]
col = [[0, 0] for _ in range(w + 1)]
ex = defaultdict(bool)
for i in range(m):
    r, c = map(int, input().split())
    row[r][0] += 1
    col[c][0] += 1
    row[r][1] = r
    col[c][1] = c
    ex[(r, c)] = True
row = sorted(row)[::-1]
col = sorted(col)[::-1]
ans = 0
for i in range(0, h + 1):
    for j in range(0, w + 1):
        ans = max(ans, row[i][0] + col[j][0] - ex[(row[i][1], col[j][1])])
        if not ex[(row[i][1], col[j][1])]:
            # iが同一だったら、jの値降順に見てるので木って良い
            print(ans)
            exit()

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 input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    h_d = defaultdict(int)
    w_d = defaultdict(int)
    h, w, n = input_int_list()
    boms = set()
    for _ in range(n):
        h, w = input_int_list()
        h_d[h] += 1
        w_d[w] += 1
        boms.add((h, w))
    H = sorted(h_d.items(), key=lambda x: -x[1])
    W = sorted(w_d.items(), key=lambda x: -x[1])
    ans = 0
    for k_h, v_h in H:
        for k_w, v_w in W:
            tmp = v_h + v_w
            if (k_h, k_w) in boms:
                tmp -= 1
                ans = max(tmp, ans)
            else:
                ans = max(tmp, ans)
                break
        else:
            continue
        break
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
bombs = set([tuple(map(int, input().split())) for _ in range(M)])

cntH = [0] * (H + 1)
cntW = [0] * (W + 1)
for h, w in bombs:
    cntH[h] += 1
    cntW[w] += 1

mxH = max(cntH)
mxW = max(cntW)

ans = mxH + mxW - 1

mxH = [h for h in range(H) if cntH[h] == mxH]
mxW = [w for w in range(W) if cntW[w] == mxW]

for h in mxH:
    for w in mxW:
        if not (h, w) in bombs:
            ans += 1
            print(ans)
            exit()
print(ans)

Submission status: Wrong Answer

Solution code:
def main(): 
    h,w,m = map(int,input().split())
    X = [0]*w
    Y = [0]*h
    g = set([])
    for _ in range(m):
        a,b = map(int,input().split())
        a-=1
        b-=1
        X[b]+=1
        Y[a]+=1
        g.add((a,b))
    
    xmax = max(X)
    ymax = max(Y)

    xlist = []
    for i,x in enumerate(X):
        if x==xmax:
            xlist.append(i)
    ylist = []
    for i,y in enumerate(Y):
        if y==ymax:
            ylist.append(i)
    
    ans = xmax+ymax
    flag = False
    for x in xlist:
        for y in ylist:
            if (x,y) in g:
                flag = True
                break
        if flag:
            break
    
    if flag:
        ans-=1
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
def main(): 
    h,w,m = map(int,input().split())
    X = [0]*w
    Y = [0]*h
    g = set([])
    for _ in range(m):
        a,b = map(int,input().split())
        a-=1
        b-=1
        X[b]+=1
        Y[a]+=1
        g.add((a,b))
    
    xmax = max(X)
    ymax = max(Y)
    x = X.index(xmax) 
    y = Y.index(ymax)
    
    ans = xmax+ymax
    if (x,y) in g:
        ans-=1
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
h=[]
w=[]
for i in range(m):
  h_,w_=map(int,input().split())
  h.append(h_)
  w.append(w_)
from collections import Counter
dic_h=Counter(h)
dic_w=Counter(w)
max_h=max(dic_h.values())
max_w=max(dic_w.values())

h_set=set()
w_set=set()
for i in dic_h:
  if dic_h[i]==max_h:
    h_set.add(i)
for j in dic_w:
  if dic_w[i]==max_w:
    w_set.add(j)

cnt=0
for i in range(m):
  if h[i] in h_set and w[i] in w_set:
    cnt+=1
if len(h_set)*len(w_set)>cnt:
  print(max_h+max_w)
else:
  print(max_h+max_w-1)

Submission status: Wrong Answer

Solution code:
h, w, m = map(int, input().split())
#grid = [[0] * w for i in range(h)]
bombs = []
#集計
sum_yoko = [0] * h
sum_tate = [0] * w

for bomb in range(m):
    y, x = map(int, input().split())
    #grid[y-1][x-1] = 1
    sum_yoko[y-1] += 1
    sum_tate[x-1] += 1
    bombs.append((y, x))

max_yoko = max(sum_yoko)
max_tate = max(sum_tate)

saidai = 0
for i in range(h):
    if max_yoko == sum_yoko[i]:
        for j in range(w):
            if max_yoko == sum_yoko[i]:
                now = max_yoko + max_tate
                if (i+1, j+1) in bombs:
                    now -= 1
                saidai = max(saidai, now)

print(saidai)

Submission status: Wrong Answer

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

for i in range(m):
    hi, wi = list(map(int, input().split()))
    ms.append((hi - 1, wi - 1))
    hs[hi - 1] += 1
    ws[wi - 1] += 1

maxh = max(hs)
maxw = max(ws)
cnt_h = sum([hs[i] == maxh for i in range(h)])
cnt_w = sum([ws[i] == maxw for i in range(w)])
cnt = max(cnt_h, cnt_w)

for x, y in ms:
    if hs[x] == maxh and ws[y] == maxw:
        cnt -= 1

if cnt <= 0:
    print(maxh + maxw - 1)
else:
    print(maxh + maxw)

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split(' '))
bom = []
for i in range(m):
    bom.append(input().split(' '))
bom = [[int(i) for i in j] for j in bom]
print(bom[0][0])
c = [[0] for i in range(h)]
r = [[0] for i in range(w)]
for i in range(m):
    
    c[bom[i][0] -1][0] = c[bom[i][0] -1][0] + 1
    r[bom[i][1] -1][0] = r[bom[i][1] -1][0] + 1

max_c = 0
max_r = 0
c_loc = 0
r_loc = 0
for i in range(h):
    if c[i][0] > max_c:
        max_c = c[i][0]
        c_loc = c[i][0] + 1
for i in range(w):
    if r[i][0] > max_r:
        max_r = r[i][0]
        r_loc = r[i][0] + 1
if [c_loc,r_loc] in bom:
    print(max_c + max_r -1)
else:
    print(max_c + max_r)

Submission status: Wrong Answer

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

X = [0] * W
Y = [0] * H
Map = []

for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map.append((h, w))

MX = max(X)
MY = max(Y)
ans = MX + MY
Xans = []
Yans = []
for i, x in enumerate(X):
    if x == MX:
        Xans.append(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.append(i)
flag = False
cnt = 0
for h, w in Map:
    if h in Yans and w in Xans:
        cnt += 1
if cnt < len(Xans) * len(Yans):
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import *

def init(N,node,unit,func):
  n=1
  while n<N:
    n<<=1
  for i in range(n*2-1):
    if len(node)<=i:
      node.append(deepcopy(unit))
    else:
      node[i]=deepcopy(unit)
  node.append(func)
  node.append(unit)
  node.append(n)

def upd(node,x,a):
  y=node[-1]+x
  node[y-1]=a
  while y>1:
    y=y>>1
    node[y-1]=node[-3](node[(y<<1)-1],node[y<<1])

def query(node,l,r):
  x,y=l,r
  z=node[-1]-1
  r=node[-2]
  while True:
    if x==y:
      return r
    if x&1:
      r=node[-3](r,node[x+z])
      x+=1
    if y&1:
      r=node[-3](r,node[y+z-1])
    x>>=1
    y>>=1
    z>>=1
    if z==0:
      return r

def bis_min_k(node,k,cond):
  x=k+1
  while True:
    if node[-1]<=x:
      return x-node[-1]
    if cond(node[(x<<1)-1]):
      x=x<<1
    else:
      x=(x<<1)+1

def bis_min(node,l,r,cond):
  x,y=l,r
  z=node[-1]-1
  for i in range(30):
    if x+(1<<i)>y:
      break
    if x&(1<<i):
      if cond(node[z+(x>>i)]):
        return bis_min_k(node,z+(x>>i),cond)
      x+=(1<<i)
    if z==0:
      break
    z>>=1
  for i in range(29,-1,-1):
    if i and ((node[-1]-1)>>(i-1))==0:
      continue
    if x+(1<<i)>y:
      continue
    if (y-x)&(1<<i):
      if cond(node[((node[-1]-1)>>i)+(x>>i)]):
        return bis_min_k(node,((node[-1]-1)>>i)+(x>>i),cond)
      x+=(1<<i)
  return node[-1]

H,W,N=map(int,input().split())
S=[[] for i in range(H+1)]
T=[]
init(W+3,T,0,lambda x,y:max(x,y))
X=[tuple(map(int,input().split())) for i in range(N)]
for i in range(N):
  S[X[i][0]].append(X[i][1])
  upd(T,X[i][1],T[(len(T)>>1)+X[i][1]]+1)
P=0
Q=0
for i in range(1,H+1):
  Q=len(S[i])
  for j in range(len(S[i])):
    upd(T,S[i][j],T[(len(T)>>1)+S[i][j]]-1)
  P=max(P,Q+T[0])
  for j in range(len(S[i])):
    upd(T,S[i][j],T[(len(T)>>1)+S[i][j]]+1)
print(P)

Submission status: Wrong Answer

Solution code:
from copy import *

def init(N,node,unit,func):
  n=1
  while n<N:
    n<<=1
  for i in range(n*2-1):
    if len(node)<=i:
      node.append(deepcopy(unit))
    else:
      node[i]=deepcopy(unit)
  node.append(func)
  node.append(unit)
  node.append(n)

def upd(node,x,a):
  y=node[-1]+x
  node[y-1]=a
  while y>1:
    y=y>>1
    node[y-1]=node[-3](node[(y<<1)-1],node[y<<1])

def query(node,l,r):
  x,y=l,r
  z=node[-1]-1
  r=node[-2]
  while True:
    if x==y:
      return r
    if x&1:
      r=node[-3](r,node[x+z])
      x+=1
    if y&1:
      r=node[-3](r,node[y+z-1])
    x>>=1
    y>>=1
    z>>=1
    if z==0:
      return r

def bis_min_k(node,k,cond):
  x=k+1
  while True:
    if node[-1]<=x:
      return x-node[-1]
    if cond(node[(x<<1)-1]):
      x=x<<1
    else:
      x=(x<<1)+1

def bis_min(node,l,r,cond):
  x,y=l,r
  z=node[-1]-1
  for i in range(30):
    if x+(1<<i)>y:
      break
    if x&(1<<i):
      if cond(node[z+(x>>i)]):
        return bis_min_k(node,z+(x>>i),cond)
      x+=(1<<i)
    if z==0:
      break
    z>>=1
  for i in range(29,-1,-1):
    if i and ((node[-1]-1)>>(i-1))==0:
      continue
    if x+(1<<i)>y:
      continue
    if (y-x)&(1<<i):
      if cond(node[((node[-1]-1)>>i)+(x>>i)]):
        return bis_min_k(node,((node[-1]-1)>>i)+(x>>i),cond)
      x+=(1<<i)
  return node[-1]

H,W,N=map(int,input().split())
S=[[] for i in range(H+1)]
T=[]
init(W+3,T,0,lambda x,y:max(x,y))
X=[tuple(map(int,input().split())) for i in range(N)]
for i in range(N):
  S[X[i][0]].append(X[i][1])
  upd(T,X[i][1]+1,T[(len(T)>>1)+X[i][1]]+1)
P=0
Q=0
for i in range(1,H+1):
  Q=len(S[i])
  for j in range(len(S[i])):
    upd(T,S[i][j]+1,T[(len(T)>>1)+S[i][j]]-1)
  P=max(P,Q+T[0])
  for j in range(len(S[i])):
    upd(T,S[i][j]+1,T[(len(T)>>1)+S[i][j]]+1)
print(P)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m,t=map(int,input().split())

grid=defaultdict(list)

row=[0]*n
col=[0]*m

for _ in range(t):
    x,y=map(int,input().split())
    grid[x-1].append(y-1)
    row[x-1]+=1
    col[y-1]+=1

prow=[]
pcol=[]
q=max(row)
for i in range(n):
    if row[i]==q :
        prow.append(i)

q=max(col)
for i in range(m):
    if col[i]==q :
        pcol.append(i)

ans=0
for i in prow :
    for j in pcol :
        if j not in grid[i] :
            ans=row[i]+col[j]
            break
        else:
            ans=row[i]+col[j]-1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
ans = hhh[0][1] + www[0][1]
if (hhh[0][0], www[0][0]) not in S:
    print(ans)
    sys.exit()
for i in range(1, len(hhh)):
    if hhh[i][1] == hhh[i-1][1]:
        h = hhh[i][0]
        if (h, www[0][0]) not in S:
            print(ans)
            sys.exit()
        for j in range(1, len(www)):
            if www[j][1] == www[j-1][1]:
                if (h, www[j][0]) not in S:
                    print(ans)
                    sys.exit()
            else:
                break
    else:
        break
print(ans-1)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
ans = hhh[0][1] + www[0][1]
if (hhh[0][0], www[0][0]) in S:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

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

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

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

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

print(mh+mw-1)