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 numpy as np
from collections import Counter
H,W,M=map(int,input().split())

X=[]
Y=[]
tt=[]
for i in range(M):
    inp=list(map(int,input().split()))
    X.append(inp[0])
    Y.append(inp[1])
    tt.append((inp[0],inp[1]))
Z1=sorted(Counter(X).items(),key=lambda x:x[1],reverse=True)[0]
Z2=sorted(Counter(Y).items(),key=lambda x:x[1],reverse=True)[0]

sumsum=Z1[1]+Z2[1]
if (Z1[0],Z2[0]) in tt:
    sumsum-=1
print(sumsum)

Submission status: Wrong Answer

Solution code:
#from collections import deque

import sys
input = sys.stdin.readline
h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for _ in range(m)]

cnt_h = [0] * h
cnt_w = [0] * w

for h1,w1 in hw:
    cnt_h[h1-1] += 1
    cnt_w[w1-1] += 1

lh = []
lw = []

for i,e in enumerate(cnt_h):
    lh.append((e,i))

for i,e in enumerate(cnt_w):
    lw.append((e,i))

lh.sort(reverse = True)
lw.sort(reverse = True)

mh = lh[0][0]
mw = lw[0][0]

idx_h = 0
idx_w = 0

cnt = 0
for i,j in lh:
    if i == mh:
        cnt += 1
    else:
        break

idx_h = cnt

cnt = 0
for i,j in lw:
    if i == mw:
        cnt += 1
    else:
        break

idx_w = cnt

ans = mh + mw

v = [[False] * w for _ in range(h)]
for h1,w1 in hw:
    v[h1-1][w1-1] = True

print(lh,lw)

if idx_h * idx_w > m:
    print(ans)
    exit()
    
for i in range(idx_h):
    for j in range(idx_w):
        if not v[lh[i][1]][lw[j][1]]:
            print(ans)
            exit()

print(ans - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M=map(int,input().split())
hw=[]
xcount=dict()
xmax=0
ans=0
for i in range(M):
    hw.append(list(map(int,input().split())))
    xcount.setdefault(hw[i][0],0)
    xcount[hw[i][0]]+=1
    if xcount[hw[i][0]]>xmax:
        xmax=xcount[hw[i][0]]
        xmaxindex=hw[i][0]
ans+=xcount[xmaxindex]
ycount=dict()
ycount_copy=dict()
ymax=0
for i in range(M):
    if hw[i][0]==xmaxindex:
        ycount_copy.setdefault(hw[i][1],0)
        ycount_copy[hw[i][1]]+=1
        continue
    ycount_copy.setdefault(hw[i][1],0)
    ycount_copy[hw[i][1]]+=1
    ycount.setdefault(hw[i][1],0)
    ycount[hw[i][1]]+=1
    if ycount[hw[i][1]]>ymax:
        ymax=ycount[hw[i][1]]
        ymaxindex=hw[i][1]
try:
    if ([xmaxindex,ymaxindex] in hw)&(list(ycount.values()).count(ymax)!=1)&(list(xcount.values()).count(xmax)!=1):
        ans+=1
    ans+=ycount[ymaxindex]
except:
    pass
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
H, W, M = map(int, input().split())
h = [0]*H
w = [0]*W
ab = []
for i in range(M):
    a, b = map(int, input().split())
    h[a-1] += 1
    w[b-1]+= 1
    ab.append([a, b])
hm = [i for i, v in enumerate(h) if v == max(h)]
wm = [i for i, v in enumerate(w) if v == max(w)]
hw = list(itertools.product(hm, wm))
if hw in ab:
    print(max(h)+max(w)-1)
else:
    print(max(h)+max(w))

Submission status: Wrong Answer

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

H,W,M = (int(x) for x in input().rstrip('\n').split())
dh = {}
dw = {}
ds = []
for _ in range(M):
  h,w = (int(x) for x in input().rstrip('\n').split())
  ds.append([h,w])
  if h in dh:
    dh[h] += 1
  else:
    dh[h] = 1
  if w in dw:
    dw[w] += 1
  else:
    dw[w] = 1
mh = max(dh.values())
mw = max(dw.values())
max_h = [k for k,v in dh.items() if v==mh]
max_w = [k for k,v in dw.items() if v==mw]
check = 0
for x in max_w:
  if check > 0:
    break
  for y in max_h:
    if [x,y] not in ds:
      check += 1
      break
if check ==0:
  print(mh+mw-1)
else:
  print(mh+mw)

Submission status: Wrong Answer

Solution code:
import numpy as np

h, w, m = list(map(int, input().split()))
bh = [0]*h
bw = [0]*w
bhw = np.asarray([[0]*w]*h)
hmaxs = []
wmaxs = []

for i in range(m):
    h,w = map(int, input().split())
    bh[h-1] +=1
    bw[w-1] +=1
    bhw[h-1][w-1] =1

maxbh= max(bh)
maxbw =max(bw)

for i in range(h):
    if bh[i] == maxbh:
        hmaxs.append(i)

for i in range(w):
    if bw[i] == maxbw:
        wmaxs.append(i)

c =1

for i in range(h):
    for j in range(w):
        print(i,j,bhw[i][j])
        if bhw[i][j]==0:
            c=0

for i in hmaxs:
    for j in wmaxs:
        print(i,j,bhw[i][j])
        if bhw[i][j]==0:
            c=0

print(maxbh + maxbw -c)

Submission status: Wrong Answer

Solution code:
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

#maincode-------------------------------------------------
h,w,m = inl()
H = [0] * h
W = [0] * w
hw = [[-1] for i in range(h)]
for i in range(m):
    a,b = inm()
    a -= 1
    b -= 1
    H[a] += 1
    W[b] += 1
    hw[a].append(b)

hm = max(H)
wm = max(W)
hc = H.count(hm)
wc = W.count(wm)

ans = hm + wm

hl = []
for i in range(hc):
    x = H.index(hm) + i
    hl.append(x)
    H.pop(x-i)

wl = []
for i in range(wc):
    x = W.index(wm) + i
    wl.append(x)
    W.pop(x-i)

f = True

for i in hl:
    for j in wl:
        if not(j in hw[i]):
            f = False
            break
    else:
        break

ans -= f
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

h, w, m = map(int, sys.stdin.readline().split())
hl = []
wl = []


for _ in range(m):
    hi, wi = map(int, sys.stdin.readline().split())
    hl.append(hi)
    wl.append(wi)

hc = Counter(hl)
wc = Counter(wl)

maxh = max(hc.values())
maxw = max(wc.values())

seth = []
setw = []

for c,num in hc.most_common():
    if num != maxh:
        break
    seth.append(c)

for c,num in wc.most_common():
    if num != maxw:
        break
    setw.append(c)

ans = 0

if h == len(seth) and w == len(setw):
    print(2)
    exit()


def cnt(r, c):
    for j in range(m):
        if hl[j] == r and wl[j] == c:

            return -1
    return 0


for hei in seth:
    for wei in setw:
        ans = max(ans, hc[hei]+wc[wei]+cnt(hei, wei))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
cnt = 0
H,W,M = list(map(int,input().split()))
data_list = [list(map(int,input().split(" "))) for i in range(M)]
h = [0] * (H + 1)
w = [0] * (W + 1)

for X in data_list:
    h[X[0]] += 1
    w[X[1]] += 1

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

for X in data_list:
    if h_max == X[0] or w_max == X[1]:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
H, W, M = map(int, input().split())
lis =[]
Hlis = [0]*H
Wlis = [0]*W
for _ in range(M):
    Ch, Cm = map(int, input().split())
    Hlis[Ch-1] += 1
    Wlis[Cm-1] += 1
    lis.append([Ch, Cm])

Hmax = max(Hlis)
Hidx = [i+1 for i, v in enumerate(Hlis) if v == Hmax]
Wmax = max(Wlis)
Widx = [i+1 for i, v in enumerate(Wlis) if v == Wmax]

for i in range(len(Hidx)):
    for j in range(len(Widx)):
        if [[Hidx[i], Widx[j]]] not in lis:
            print(Hmax+Wmax)
            sys.exit()
else:
    print(Hmax + Wmax -1)

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)
temp=list(col.items())
temp.sort(key=lambda x:x[1])
a,b=temp[-1][0],temp[-1][1]
cnt2=0
for i in range(H):
    temp=0
    if matrix[(a,i)]:
        temp=(b+row[i]-1)
    else:
        temp=(b+row[i])
    cnt2=max(cnt2,temp)
print(max(cnt,cnt2))

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_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:
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)):
    max_row=0
    max_col=0
    for key,item in take1.items():
        max_row=item
        break
    for key,item in take2.items():
        max_col=item
        break
    rr=[]
    cc=[]
    for key,item in take1.items():
        if item==max_row:
            rr.append(key)
        else:
            break
    for key,items in take2.items():
        if item==max_col:
            cc.append(key)
        else:
            break
    # print(rr)
    # print(cc)
    for i in range(len(rr)):
        for j in range(len(cc)):
            r,c=rr[i],cc[j]
            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
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):
    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:
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    h, w, m = get_int_list()

    a = [0] * (h+1)
    b = [0] * (w+1)
    c = []

    for _ in range(m):
        h2, w2 = get_int_multi()
        c.append([h2,w2])
        a[h2] += 1
        b[w2] += 1

    ans = 0

    wk = -1
    max_r = -1
    for i in range(h+1):
        if wk < a[i]:
            wk = a[i]
            max_r = i

    for c_idx in range(len(c)-1, -1, -1):
        if c[c_idx][0] == max_r:
            ans += 1
            b[c[c_idx][1]] -= 1
            c.pop(c_idx)


    wk = -1
    max_c = -1
    for i in range(w+1):
        if wk < b[i]:
            wk = b[i]
            max_c = i

    for c_idx in range(len(c)-1, -1, -1):
        if c[c_idx][1] == max_c:
            ans += 1
            #a[c[c_idx][0]] -= 1
            #c.pop(c_idx)


    print(ans)

    #print(time.time() - start)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

maxr, maxc = Counter(), Counter()

mass = set()

for i in range(M):
    h, w = map(int, input().split())
    mass.add((h-1, w-1))
    maxr[h-1]+=1
    maxc[w-1]+=1

res = 0

for r in range(H):
    buf = maxr[r-1]
    for c in range(W):
        res = max(res, buf+maxc[c-1] - int((r, c) in mass))
print(res)

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 > 10: 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:
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

yoko.sort(key=lambda x:x[1])
tate.sort(key=lambda x:x[1],reverse=True)
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:
# coding: utf-8
# Your code here!


H,W,M = input().rstrip().split(' ')

H = int(H)
W = int(W)
M = int(M)

hcount = [0 for _ in range(H)]
wcount = [0 for _ in range(W)]

L = [[0 for i in range(W)]for j in range(H)]

for i in range(M):
    ij = input().rstrip().split(' ')
    i = int(ij[0])-1
    j = int(ij[1])-1
    L[i][j] = 1
    hcount[i] += 1
    wcount[j] += 1
 
hmax = max(hcount)
wmax = max(wcount)
count = hmax+wmax-1

hin = [i for i, x in enumerate(hcount) if x == hmax]
win = [i for i, x in enumerate(wcount) if x == wmax]

for i in hin:
    for j in win:
        if L[i][j]==0:
            count += 1
            break
print(count)

Submission status: Wrong Answer

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


row = sorted(list(row.items()), key = lambda x: x[1], reverse = True)
col = sorted(list(col.items()), key = lambda x: x[1], reverse = True)
t = len(row)
for i,j in row:
    if j!=row[0]:
        t = i
        break
row = row[:t]
t = len(col)
for i,j in col:
    if j!=col[0]:
        t = i
        break
col = col[:t]


i,j = 0,0
ans = row[0][1]+col[0][1] + (-1 if grid[(row[0][0], col[0][0])] else 0)
dq = deque([(i,j)])
while dq:
    i,j = dq.popleft()
    temp = row[i][1]+col[j][1] + (-1 if grid[(row[i][0], col[j][0])] else 0)
    if ans<temp:
        ans = temp
        break
    
    if i+1<len(row):dq.append((i+1,j))
    if j+1<len(col):dq.append((i,j+1))

    
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    h, w, m = get_int_list()

    a = [0] * (h+1)
    b = [0] * (w+1)
    c = []

    for _ in range(m):
        h2, w2 = get_int_multi()
        c.append([h2,w2])
        a[h2] += 1
        b[w2] += 1

    ans = 0

    wk = -1
    max_r = -1
    for i in range(h+1):
        if wk < a[i]:
            wk = a[i]
            max_r = i

    for c_idx in range(len(c)-1, -1, -1):
        if c[c_idx][0] == max_r:
            ans += 1
            b[c[c_idx][1]] -= 1
            c.pop(c_idx)


    wk = -1
    max_c = -1
    for i in range(w+1):
        if wk < b[i]:
            wk = b[i]
            max_c = i

    for c_idx in range(len(c)-1, -1, -1):
        if c[c_idx][1] == max_c:
            ans += 1
            #a[c[c_idx][0]] -= 1
            #c.pop(c_idx)


    print(ans)

    print(time.time() - start)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def E():
    h,w,m = list(map(int, input().split()))
    h_l = []
    w_l = []
    bomb = []
    for _ in range(m):
        h_t,w_t = list(map(int, input().split()))
        h_l.append(h_t)
        w_l.append(w_t)
        bomb.append(str(h_t-1)+":"+str(w_t-1))
    import collections
    c_h = collections.Counter(h_l)
    c_w = collections.Counter(w_l)
    max_h = c_h.most_common()[0][1]
    max_w = c_w.most_common()[0][1]
    flg = -1
    for i in range(len(c_h)):
        if c_h.most_common()[i][1] != max_h:
            break
        for j in range(len(c_w)):
            if c_w.most_common()[j][1] != max_w:
                break
            if str(c_h.most_common()[i][0])+":"+str(c_w.most_common()[j][0]) in bomb:
                flg = 0
                break
    print(max_h + max_w + flg)
E()

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]
    if mrow > row and mcow > cow:
        break
    ans1 = hs.count(row)
    ans2 = ws.count(cow)
    ans = ans1 + ans2

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

    anss.append(ans)


print(max(anss))

Submission status: Wrong Answer

Solution code:
import sys
import collections

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    H, W, M = map(int, input().split())
    bombs = []
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append((h, w))
    g = list(zip(*bombs))
    g0 = collections.Counter(g[0])
    g1 = collections.Counter(g[1])
    g0items = list(g0.items()); g0items.sort(key=lambda x: x[1], reverse=True)
    g1items = list(g1.items()); g1items.sort(key=lambda x: x[1], reverse=True)
    x = g0items[0][0]; countx = g0items[0][1]
    y = g1items[0][0]; county = g1items[0][1]
    ans = countx + county - ((x, y) in bombs)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
c=[list(map(int,input().split())) for i in range(m)]
ans = 0
aa = {}
bb = {}
z = 1

for i in range(m):
  if c[i][0] in aa:
    aa[c[i][0]] += 1
  else:
    aa[c[i][0]] = 1
    
  if c[i][1] in bb:
    bb[c[i][1]] += 1
  else:
    bb[c[i][1]] = 1
    
    
print(max(aa.values())+ max(bb.values())-z)

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

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:
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)
  
cnt = xm + ym         
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    H, W, M = in_nn()

    hcnt = [0] * H
    wcnt = [0] * W

    hw = []

    for i in range(M):
        h, w = in_nn()
        h, w = h - 1, w - 1
        hw.append((h, w))

    for i in range(M):
        h, w = hw[i]
        hcnt[h] += 1
        wcnt[w] += 1

    max_h = max(hcnt)
    max_w = max(wcnt)

    ans = max_h + max_w - 1

    h_index = []
    w_index = []

    for i in range(H):
        if hcnt[i] == max_h:
            h_index.append(i)

    for i in range(W):
        if wcnt[i] == max_w:
            w_index.append(i)

    hw_set = set(hw)
    # print(h_index)
    # print(w_index)

    hn = len(h_index)
    wn = len(w_index)

    f = False
    for i in range(hn):
        for j in range(wn):
            if (h_index[i], w_index[j]) not in hw_set:
                f = True

        if f or hn * i > 3 * 10**5:
            ans += 1
            break

    print(ans)


if __name__ == '__main__':
    main()

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[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 <= 1300:
    j = 0
    while j < w and j <= 1300:
        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 numpy as np
import collections
#import math




#f = open('./input_E.txt')
#
#H,W,M=map(int, f.readline().split())
#bakuha = []
#bakuha_H=[]
#bakuha_W=[]
#for i in range(M):
#    hh,ww=map(int, f.readline().split())
#    bakuha_H.append(hh)
#    bakuha_W.append(ww)
#    bakuha.append([hh,ww])




H,W,M=map(int, input().split())
bakuha = []
bakuha_H=[]
bakuha_W=[]
for i in range(M):
    hh,ww=map(int, input().split())
    bakuha_H.append(hh)
    bakuha_W.append(ww)
    bakuha.append([hh,ww])





count_H = collections.Counter(bakuha_H)
H_most = count_H.most_common()
H_most_num = H_most[0][1]

H_only_most = [x for x in H_most if x[1]==H_most_num]
H_kouho = [x[0] for x in H_only_most]


count_W = collections.Counter(bakuha_W)
W_most = count_W.most_common()
W_most_num = W_most[0][1]

W_only_most = [x for x in W_most if x[1]==W_most_num]
W_kouho = [x[0] for x in W_only_most]

ans = H_most_num + W_most_num



#爆破対称のある座標にしか置けなかったらマイナス1
#H_kouho_index = [i for i in range(M) if bakuha_H[i] in H_kouho]
#W_kouho_index = [i for i in range(M) if bakuha_W[i] in W_kouho]
#
#ans_minus=True
#if len(H_kouho_index) <= len(W_kouho_index):
#    for h_index in H_kouho_index:
#        if h_index not in W_kouho_index:
#            ans_minus = False
#            break
#else:
#    for w_index in W_kouho_index:
#        if w_index not in H_kouho_index:
#            ans_minus = False
#            break
#if H_kouho_index == W_kouho_index:

#if ans_minus:
#    ans-=1

#bakuha_array = np.array(bakuha)
#for h_kouho in H_kouho:
#    for w_kouho in W_kouho:
#        bakuha_array = bakuha_array[bakuha_array[0]==h_kouho]
#
##    bakuha_array = bakuha_array[bakuha_array[1]==w_kouho]


#ryouhou = 0
#for bb in bakuha:
#    x,y = bb
#    if x in H_kouho and y in W_kouho:
#        ryouhou+=1
#
#h_by_w = len(H_kouho)*len(W_kouho)
#
#if ryouhou == h_by_w:
#    ans -= 1
    

print(ans)

Submission status: Wrong Answer

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

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

for item in P:
  column[item[0] -1] += 1
  row[item[1] -1] += 1
  
co_max = sorted(column, reverse=True)[0]
ro_max = sorted(row, reverse=True)[0]

if co_max == 1 and ro_max == 1:
  print(2)
else:
  column_max = [i for i, x in enumerate(column) if x == co_max]
  row_max = [i for i, x in enumerate(row) if x == ro_max]

  flag = 0
  for i in column_max:
    for j in row_max:
      if [i+1, j+1] not in P:
        flag = 1
        break
  if flag == 1:
    print(max(column) + max(row))
  elif flag == 0:
    print(max(column) + max(row) -1)