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:
from collections import defaultdict

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

row_dict = defaultdict(int)
col_dict = defaultdict(int)
row_col_dict = defaultdict(list)
for _ in range(m):
    row, col = map(int, input().split())
    row_dict[row] += 1
    col_dict[col] += 1
    row_col_dict[row].append(col)

max_row = max(row_dict.values())
max_col = max(col_dict.values())

max_rows = [k for k, v in row_dict.items() if v == max_row]
max_cols = [k for k, v in col_dict.items() if v == max_col]
ans = max_row + max_col - 1
flg = False
for row in max_rows:
    for col in max_cols:
        if not col in row_col_dict[row]:
            ans += 1
            break
    if flg:
        break

print(ans)

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(h):
                x = xdic[j][0]
                tmp = 0
                y = i + 1
                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(w):
                y = ydic[i][1]
                tmp = 0
                x = j + 1
                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:
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    n,m,q=inar()
    row={}
    column={}
    arr=[]
    take1=defaultdict(int)
    take2=defaultdict(int)
    for i in range(q):
        r,c=inar()
        take1[r]+=1
        take2[c]+=1
        arr.append([r,c])
        if r not in row:
            row[r]=defaultdict(int)
            row[r][c]+=1
        else:
            row[r][c]+=1
        if c not in column:
            column[c]=defaultdict(int)
            column[c][r]+=1
        else:
            column[c][r]+=1
    ans=0
    take1=dict(sorted(take1.items(),key=operator.itemgetter(1),reverse=True))
    take2 = dict(sorted(take2.items(), key=operator.itemgetter(1), reverse=True))
    # print(take1)
    # print(take2)
    # for i in range(len(take1)):
    #     for j in range(len(take2)):
    for key,item in take1.items():
        r=key
        break
    for key,item in take2.items():
        c=key
        break

    temp=len(row[r])
    temp+=len(column[c])
    temp-=row[r][c]
    ans=max(ans,temp)
    print(ans)




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()
    #threadin.Thread(target=main).start()

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_max = np.argmax(np.bincount(Bom[:, 0]))
ind_h = np.where(Bom[:, 0] == h_max)

if not len(ind_h[0]) == M:
    Bom_h = np.delete(Bom, ind_h, 0)
    w_max = np.argmax(np.bincount(Bom_h[:, 1]))
    ind_w = np.where(Bom_h[:, 1] == w_max)
    print(len(ind_h[0])+len(ind_w[0]))
else:
    print(len(ind_h[0]))

Submission status: Wrong Answer

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

max_h=[0 for i in range(h+1)]
max_w=[0 for i in range(w+1)]
grid=[[0 for i in range(w)] for j in range(h)]
pro=[list(map(int,input().split())) for i in range(m)]
pro.sort()
for i in range(m):
    h=pro[i][0]
    w=pro[i][1]
    max_h[h]+=1
    max_w[w]+=1
    grid[h-1][w-1]=1
h_max=[i for i, x in enumerate(max_h) if x == max(max_h)]
w_max=[i for i, x in enumerate(max_w) if x == max(max_w)]

ans=0
for i in h_max:
    for j in w_max:
        cnt=0
        #cnt +=list(zip(*grid))[j-1].count(1)
        #cnt += grid[i-1].count(1)
        for k in range(h):
            if grid[k][j-1]==1:
                cnt += 1
        for l in range(w):
            if grid[i-1][l]==1:
                cnt += 1
        if grid[i-1][j-1]==1:
            cnt -= 1
        
        if cnt > ans:
            ans=cnt
print(ans)

Submission status: Wrong Answer

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

for i in range(M):
    tmp1,tmp2 = map(int,input().split())
    h.append(tmp1)
    w.append(tmp2)

dic1 = {}
dic2 = {}

for i in h:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1

val1 = max(dic1,key=dic1.get)
ans = 0
ans +=dic1[val1]
for j in range(M):
    if h[j] != val1:
        if w[j] not in dic2:
            dic2[w[j]] = 1
        else:
            dic2[w[j]] +=1
if dic2:
    val2 = max(dic2,key=dic2.get)
    ans +=dic2[val2]


dic1 = {}
dic2 = {}

for i in w:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1
val1 = max(dic1,key=dic1.get)
ans1 = 0
ans1 +=dic1[val1]
for j in range(M):
    if h[j] != val1:
        if w[j] not in dic2:
            dic2[w[j]] = 1
        else:
            dic2[w[j]] +=1
if dic2:
    val2 = max(dic2,key=dic2.get)
    ans1 +=dic2[val2]
print(max(ans,ans1))

Submission status: Wrong Answer

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

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

#print(h)
#print(w)

bomb = False

# 重複要素のmaxを求める
hcount = [x for x in set(h) if h.count(x) > 10000]
if len(hcount)==0:
    hcount = [x for x in set(h) if h.count(x) > 1000]
if len(hcount)==0:
    hcount = [x for x in set(h) if h.count(x) > 1]

maxh = 0
hraw = 0
for i in range(len(hcount)):
    hcnt = h.count(hcount[i])
    if hcnt>maxh:
        maxh = hcnt
        hraw = hcount[i]
# 重複要素のmaxを求める
wcount = [x for x in set(w) if w.count(x) > 10000]
if len(wcount)==0:
    wcount = [x for x in set(w) if w.count(x) > 1000]
if len(wcount)==0:
    wcount = [x for x in set(w) if w.count(x) > 1]

maxw = 0
wraw = 0
for i in range(len(wcount)):
    wcnt = w.count(wcount[i])
    if wcnt>maxw:
        maxw = wcnt
        wraw = wcount[i]
if maxw == 0:
    maxw = 1

#print(hraw)
#print(wraw)

#for i in range(len(h)):
#    if h[i]==hraw and w[i]==wraw:
#        bomb = True
#        break

cnt = maxh + maxw
if bomb:
    cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
x=0
H,W,M = map(int,input().split())
if H == 1 or W == 1:
  print(M)
  
  
else:  
  h = [0]*M
  w = [0]*M
  for i in range(0,M):
    h[i],w[i] = map(int,input().split())
  a = Counter(h).most_common()
  b = Counter(w).most_common()
  x = a[0][1]+b[0][1]
  for i in range(0,M):
    if h[i] == a[0][0] and w[i] == b[0][0]:
      x = x-1
  print(x)

Submission status: Wrong Answer

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

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

#print(h)
#print(w)

bomb = False

# 重複要素のmaxを求める
hcount = [x for x in set(h) if h.count(x) > 10000]
if len(hcount)==0:
    hcount = [x for x in set(h) if h.count(x) > 1000]
if len(hcount)==0:
    hcount = [x for x in set(h) if h.count(x) > 1]

maxh = 0
hraw = 0
for i in range(len(hcount)):
    hcnt = h.count(hcount[i])
    if hcnt>maxh:
        maxh = hcnt
        hraw = hcount[i]
# 重複要素のmaxを求める
wcount = [x for x in set(w) if w.count(x) > 10000]
if len(wcount)==0:
    wcount = [x for x in set(w) if w.count(x) > 1000]
if len(wcount)==0:
    wcount = [x for x in set(w) if w.count(x) > 1]

maxw = 0
wraw = 0
for i in range(len(wcount)):
    wcnt = w.count(wcount[i])
    if wcnt>maxw:
        maxw = wcnt
        wraw = wcount[i]
if maxw == 0:
    maxw = 1

#print(hraw)
#print(wraw)

for i in range(len(h)):
    if h[i]==hraw and w[i]==wraw:
        bomb = True
        break

cnt = maxh + maxw
if bomb:
    cnt -= 1

print(cnt)

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(55)
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:
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) 

I=sys.stdin.readline

 #s="abcdefghijklmnopqrstuvwxyz"

"""
x_move=[-1,0,1,0,-1,1,1,-1]
y_move=[0,1,0,-1,1,1,-1,-1]
"""
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


	
	

	

def main():
	h,w,m=mi()
	if h==1 or w==1:
		print(m) 
	else:
		row=defaultdict(int)
		col=defaultdict(int)

		d=defaultdict(int)
		for _ in range(m):
			x,y=mi()
			d[(x,y)]=1
			row[x]+=1
			col[y]+=1


		r_max=max(row.values())
		c_max=max(col.values())
		r_val=0
		c_val=0
		
		for i in row:
			if row[i]==r_max:
				r_val=i
				break

		for j in col:
			if col[j]==c_max:
				c_val=j
				break



		#print(r_val,c_val)
		max_val=0

		for i in range(1,w+1):
			if d[(r_val,i)]==1:
				if row[r_val]+col[i]-1>max_val:
					max_val=row[r_val]+col[i]-1
			elif row[r_val]+col[i]>max_val:
				max_val=row[r_val]+col[i]







		print(max_val)

	


	
	
	
		







	












	
	
	





if __name__ == '__main__':
	main()

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 = 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 <= 800:
    j = 0
    while j < w and j <= 800:
        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))
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

h, w, m = map(int, input().split())
H = []
W = []
for _ in range(m):
    h, w = map(int, input().split())
    H.append(h)
    W.append(w)
ch = collections.Counter(H)
h = ch.most_common()[0][0]
cw = collections.Counter(W)
w = cw.most_common()[0][0]
cnt = 0
for i in range(m):
    if (H[i] == h) or (W[i] == w):
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import Counter
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
h,w,m=get_ints()
a=[]
b=[]
for i in range(m):
    h1,w1=get_ints()
    a.append(h1)
    b.append(w1)
c=Counter(a)
d=Counter(b)
maxi11=max(c,key=c.get)
maxi22=max(d,key=d.get)
maxi1=c[maxi11]
maxi2=d[maxi22]
ans=0
for i in range(m):
    if a[i]==maxi11 and b[i]==maxi22:
        ans+=1
print((maxi1+maxi2)-ans)

Submission status: Wrong Answer

Solution code:
import collections

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

h = []
w = []
point = []
for i in range(M):
    a, b = list(map(int, input().split()))

    h.append(a)
    w.append(b)
    point.append((a, b))

h_most = collections.Counter(h).most_common()[0]
w_most = collections.Counter(w).most_common()[0]

count = h_most[1] + w_most[1]


if ((h_most[0], w_most[0]) in point):
    count = count - 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
H, W, M = list(map(int, input().split()))
row = np.zeros(H)
col = np.zeros(W)
sys.exit()

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
  h, w, m = map(int, input().split())
  li = []
  height = []
  width = []
  count_h = []
  count_w = []
  for i in range(m):
    li.append(input().split())
    height.append(li[i][0])
    width.append(li[i][1])

  for j in range(m):
    count_h.append(height.count(str(j+1)))
    count_w.append(width.count(str(j+1)))
  print(max(count_h)+max(count_w))

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
p=0
q=0
r=0

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

for i in range(0,W+1):
    if bm<b.count(i):
        q=1
    bm=max(bm,b.count(i))

for i in range(0,M):
    if (a[i],b[i])==(p,q):
        r+=1
        
if r==0:
    print(am+bm)
else:
    print(am+bm-1)

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 = 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 <= 700:
    j = 0
    while j < w and j <= 700:
        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))
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
h, w, m = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
hw1, hw2 = deepcopy(hw), deepcopy(hw)
hw1.sort()
hw2.sort(key=lambda x:x[1], reverse=True)
ans1, ans2 = 0, 0
cur1, cur2 = 1, 1
ind1, ind2 = float("inf"), float("inf")
sec1, sec2 = 0, 0
for i in range(1, m):
    if hw1[i][0] != hw1[i - 1][0]:
        if cur1 > ans1:
            ind1 = hw1[i - 1][0]
            sec1 = ans1
            ans1 = max(ans1, cur1)
        else:
            sec1 = max(sec1, cur1)
        cur1 = 1
    else:
        cur1 += 1
if cur1 >= ans1:
    ind1 = hw1[-1][0]
    sec1 = ans1
    ans1 = max(ans1, cur1)
for i in range(1, m):
    if hw2[i][1] != hw2[i - 1][1]:
        if cur2 > ans2:
            ind2 = hw[i - 1][1]
            sec2 = ans2
            ans2 = max(ans2, cur2)
        else:
            sec2 = max(sec2, cur2)
        ans2 = max(ans2, cur2)
        cur2 = 1
    else:
        cur2 += 1
if cur2 >= ans2:
    ind2 = hw2[-1][1]
    sec2 = ans2
    ans2 = max(ans2, cur2)
if [ind1, ind2] in hw:
    print(ans1 + ans2 - 1)
else:
    print(ans1 + ans2)

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(70)
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:
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])
h = max([(v,k) for k,v in Hlist.items()])[1]
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()
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:
        Answer -= 1
print(Answer)

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

for i in range(H):
    if takasa[i] > b:
        b = takasa[i]
        indexh = i

b=0
        
for i in range(W):
    if haba[i] > b:
        b = haba[i]
        indexw = i

ans = takasa[indexh] + haba[indexw]
if [takasa[indexh]+1, haba[indexw]+1] in A:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
print('1')

Submission status: Wrong Answer

Solution code:
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools, copy, math
from bisect import *
from heapq import *
from collections import *


def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

H, W, M = In.ints()

hdict = defaultdict(list)
wdict = defaultdict(list)

for i in range(M):
    h, w = In.ints()

    hdict[h].append(w)
    wdict[w].append(h)

ans = 0

hsorted = [hdict[key] for key in hdict]
hsorted.sort(key=lambda x: -len(x))
ans += len(hsorted[0])

for w in hsorted[0]:
    wdict[w].pop(0)

wsorted = [wdict[key] for key in wdict]
wsorted.sort(key=lambda x: -len(x))
ans += len(wsorted[0])

Out.int(ans)

######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

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 = 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 <= 500:
    j = 0
    while j < w and j <= 500:
        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))
        j += 1
    i += 1
print(ans)

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[str(x)] = str(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 = [k for k, v in xs.items() if v == max(xs.values())]
max_y = [k for k, v in ys.items() if v == max(ys.values())]
boolen = 0
for x in max_x:
    for y in max_y:
        if (x , y) in points.items():
            boolen = 1
            break
if boolen == 0:
    print(xs[max_x[0]] + ys[max_y[0]]-1)
else:
    print(xs[max_x[0]] + ys[max_y[0]])

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(), [[0 for _ in range(w+1)]for _ in range(h+1)]
    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
    print(mh+mw-g[mr][mc])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

B = []
h = H
while h:
    h -= 1
    B.append([])
    
A = []
m = M
while m:
    m -= 1
    x, y = map(int,input().split())
    x, y = x -1, y -1
    A.append((x, y))
    B[x].append(y)
    X[x] += 1
    Y[y] += 1

def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

xm = max(X)
ym = max(Y)
xms = my_index_multi(X, xm)
yms = my_index_multi(Y, ym)

ans = False
for i in xms:
    for j in yms:
        if not j in B[x]:
            ans = True
            break
  
cnt = xm + ym         
print(cnt if ans else cnt - 1)

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
hli = [0]*h
wli = [0]*w
li = []
for i in range(m):
    a,b = map(int,input().split())
    li.append([a,b])
    hli[a-1] += 1
    wli[b-1] += 1
a = max(hli)
b = max(wli)
ans1 = hli.index(a) + 1
ans2 = wli.index(b) + 1
if [ans1,ans2] in li:
    print(a + b - 1)
else:
    print(a + b)

Submission status: Wrong Answer

Solution code:
from collections import Counter

ans = 0

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

x = []
y = []

for i in range(M):
    _x, _y = map(int, input().split())
    x.append(_x)
    y.append(_y)

cnt_x = Counter(x)
cnt_y = Counter(y)

x_max = cnt_x.most_common(1)

ans += x_max[0][1]

for i in range(M):
    if x_max[0][0] == x[i]:
        x[i] = -1
        y[i] = -1

cnt_x = Counter(x)
cnt_y = Counter(y)

del cnt_x[-1], cnt_y[-1]

y_max = cnt_y.most_common(1)


if y_max:
    ans += y_max[0][1]

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 = 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 <= 300:
    j = 0
    while j < w and j <= 300:
        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))
        j += 1
    i += 1
print(ans)

Submission status: Wrong Answer

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

hw_list=[[0 for i in range(w)] for j in range(h)]
h_list=[0]*h
w_list=[0]*w
for i in range(m) :
  a,b=map(int,input().split())
  h_list[a-1]+=1
  w_list[b-1]+=1
  

h_max=max(h_list)
w_max=max(w_list)
print(str(h_max+w_max))

Submission status: Wrong Answer

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

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

#print(h)
#print(w)

bomb = False

# 重複要素のmaxを求める
hcount = [x for x in set(h) if h.count(x) > 100]
if len(hcount)==0:
    hcount = [x for x in set(h) if h.count(x) > 1]

maxh = 0
hraw = 0
for i in range(len(hcount)):
    hcnt = h.count(hcount[i])
    if hcnt>maxh:
        maxh = hcnt
        hraw = hcount[i]
# 重複要素のmaxを求める
wcount = [x for x in set(w) if w.count(x) > 100]
if len(wcount)==0:
    wcount = [x for x in set(w) if w.count(x) > 1]

maxw = 0
wraw = 0
for i in range(len(wcount)):
    wcnt = w.count(wcount[i])
    if wcnt>maxw:
        maxw = wcnt
        wraw = wcount[i]
if maxw == 0:
    maxw = 1

#print(hraw)
#print(wraw)

for i in range(len(h)):
    if h[i]==hraw and w[i]==wraw:
        bomb = True
        break

cnt = maxh + maxw
if bomb:
    cnt -= 1

print(cnt)

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
    col[w]+=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-1,i)]:
        temp=(b+col[i+1]-1)
    else:
        temp=(b+col[i+1])
    cnt=max(cnt,temp)
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys 
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M= map(int,readline().split())
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
data = [[False]*(W+1) for i in range(H+1)]

for i in range(M):
    h,w = map(int,readline().split())
    data[h][w] = True
    h_cnt[h] += 1 
    w_cnt[w] += 1
    
max_h = max(h_cnt)
max_w = max(w_cnt)

max_h_ind = []
max_w_ind = []
max_h_cnt = 0
max_w_cnt = 0

for i in range(H+1):
    if max_h == h_cnt[i]:
        max_h_cnt += 1
        max_h_ind.append(i)

for i in range(W+1):
    if max_w == w_cnt[i]:
        max_w_cnt += 1
        max_w_ind.append(i)

if max_w_cnt * max_h_cnt > M:
    print(max_h+max_w-1)
else:
    for h in max_h_ind:
        for w in max_w_ind:
            if data[h][w] == False:
                print(max_h+max_w)
                sys.exit()
    print(max_h+max_w-1)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    import collections
    H,W,M=map(int,input().split())
    hw=[list(map(int,input().split())) for _ in range(M)]
    A=[]
    B=[]
    ans=0
    for x in hw:
        A.append(x[0])
        B.append(x[1])
    cx=collections.Counter(A)
    cy=collections.Counter(B)
    a=cx.most_common()[0]
    b=cy.most_common()[0]
    ans=a[1]+b[1]

    aa=list(cx.values()).count(a[1])
    bb=list(cy.values()).count(b[1])

    for i in range(aa):
        for j in range(bb):
            a=cx.most_common()[i]
            b=cy.most_common()[j]

            if [int(a[0]),int(b[0])] in hw:
                ans -= 1
            print(ans)
            sys.exit()

    
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter as C

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

hs, ws = [], []
hw = []

for i in range(m):
    hi, w = map(int, input().split())
    hs.append(hi)
    ws.append(w)
    hw.append([hi, w])


ch = C(hs).most_common()
cw = C(ws).most_common()
anss = []
pre_ans = -float('inf')
mrow = ch[0][0]
mcow = cw[0][0]

for num1, num2 in zip(ch, cw):
    row, cow = num1[0], num2[0]
    ans1 = hs.count(row)
    ans2 = ws.count(cow)
    ans = ans1 + ans2

    if [row, cow] in hw:
        ans -= 1

    anss.append(ans)
    if (mrow > row or mcow > cow) and pre_ans > ans:
        break

    if pre_ans >= ans:
        ans = pre_ans
    else:
        pre_ans = ans


print(max(anss))