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:
# -*- coding: utf-8 -*-
from collections import Counter, defaultdict


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, M, HW):
    g = defaultdict(dict)
    for h, w in HW:
        g[h][w] = 1
    h = Counter(h for h, w in HW)
    w = Counter(w for h, w in HW)
    h = list(h.items())
    h.sort(reverse=True, key=lambda x: x[1])
    w = list(w.items())
    w.sort(reverse=True, key=lambda x: x[1])

    ans = 0
    for k, v in h:
        for kk, vv in w:
            if k in g and kk in g[k]:
                ans = max(ans, v + vv - 1)
            else:
                return v + vv

    return ans


def main():
    H, W, M = read_int_n()
    HW = [read_int_n() for _ in range(M)]
    print(slv(H, W, M, HW))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

h,w,m = map(int,input().split())
c = np.zeros([m,2],dtype=np.int8)
hc = np.zeros(h,dtype=np.int8)
wc = np.zeros(w,dtype=np.int8)
for i in range(m):
    y,x = map(int,input().split())
    y -= 1
    x -= 1
    c[i][0] = y
    c[i][1] = x
    hc[y] += 1
    wc[x] += 1

hcuni = np.unique(c[:,0])
wcuni = np.unique(c[:,1])
sumax = 0

for y in hcuni:
    for x in wcuni:
        tempmax = hc[y] + wc[x]
        if tempmax > sumax:
            count = 0
            for i in range(m):
                if c[i][0] == y and c[i][1] == x: count += 1
            if tempmax - count > sumax:
                sumax = tempmax - count       
print(sumax)

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()[0][0]
cw = C(ws).most_common()[0][0]
ans1 = hs.count(ch)
ans2 = ws.count(cw)
ans = ans1 + ans2

if [ch, cw] in hw:
    ans -= 1

print(ans)

Submission status: Wrong Answer

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

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

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

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

  # print(tate)
  # print(yoko)

for i in range(min(h,5)):
    for j in range(min(w,5)):
        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 i == h-1:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hl=[0]*m
hc=[0]*h
wc=[0]*w
n=0
wl=[0]*m
for i in range(m):
    hl[i],wl[i]=list(map(int,input().split()))
    hc[hl[i]-1]+=1
    wc[wl[i]-1]+=1
mw=max(wl)
mh=max(hl)
for i in range(m):
    if (hl[i]==mh)and(wl[i]==mw):
        n+=1
ct=max(hc)+max(wc)-n
print(ct)

Submission status: Wrong Answer

Solution code:
import collections

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

my_s = set()

h_ls = []
w_ls = []

for _ in range(m):
    h_e, w_e = map(int, input().split())
    my_s.add((h_e, w_e))
    h_ls.append(h_e)
    w_ls.append(w_e)

h_c = collections.Counter(h_ls)
w_c = collections.Counter(w_ls)

h_ls = h_c.most_common()
w_ls = w_c.most_common()

h_ptr = 0
w_ptr = 0
ret = 0

h_idx, h_cnt = h_ls[0]
w_idx, w_cnt = w_ls[0]
tmp = h_cnt + w_cnt
flag = False
if (h_idx, w_idx) not in my_s:
    ret = tmp
else:
    for i, item in enumerate(h_ls):
        _, h_cnt_tmp = item
        if h_cnt_tmp != h_cnt:
            h_ptr = i - 1
            break
        if i == len(h_ls) - 1:
            h_ptr = len(h_ls) - 1

    for i, item in enumerate(w_ls):
        _, w_cnt_tmp = item
        if w_cnt_tmp != w_cnt:
            w_ptr = i - 1
            break
        if i == len(w_ls) - 1:
            w_ptr = len(w_ls) - 1

    for i in range(h_ptr):
        for j in range(w_ptr):
            h_idx, _ = h_ls[i]
            w_idx, _ = w_ls[j]
            if (h_idx, w_idx) not in my_s:
                ret = tmp
                flag = True
                break
        if flag:
            break
    if not flag:
        ret = tmp - 1

print(ret)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
d = defaultdict(list)

h,w,m = map(int,input().split())
H = [0]*h
W = [0]*w
for i in range(m):
    h,w = map(int,input().split())
    d[h-1].append(w-1)
    H[h-1] += 1
    W[w-1] += 1
maxh = max(H)
maxw = max(W)

if maxw in d[maxh]:
    maxh -= 1
print(maxh+maxw)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter, defaultdict


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, M, HW):
    g = defaultdict(dict)
    for h, w in HW:
        g[h][w] = 1
    h = Counter(h for h, w in HW)
    w = Counter(w for h, w in HW)
    h = list(h.items())
    h.sort(reverse=True, key=lambda x: x[1])
    w = list(w.items())
    w.sort(reverse=True, key=lambda x: x[1])

    ans = 0
    for k, v in h:
        for kk, vv in w:
            if k in g and kk in g[k]:
                ans = max(ans, v + vv - 1)
            else:
                return ans

    return ans


def main():
    H, W, M = read_int_n()
    HW = [read_int_n() for _ in range(M)]
    print(slv(H, W, M, HW))


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 = []
tate = [[0,i] for i in range(h)]
yoko = [[0,i] for i in range(w)]

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

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

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

  # print(tate)
  # print(yoko)

for i in range(min(h,5)):
    for j in range(min(w-1,5)):
        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 i == h-1:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
import collections
h2l=[]
w2l=[]
for i in range(m):
    h2,w2=map(int,input().split())
    h2l.append(h2)
    w2l.append(w2)

ch=collections.Counter(h2l)
cw=collections.Counter(w2l)

ansh=ch.most_common()[0][1]
answ=cw.most_common()[0][1]
ansx=ch.most_common()[0][0]
ansy=cw.most_common()[0][0]
ans=ansh+answ

for i in range(m):
    if h2l[i]==ansx and w2l[i]==ansy:
        ans-=1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
h, w, m = map(int, input().split())
A = []
B = []
points = set()
for _ in range(m):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)
    points.add((a,b))
ac = Counter(A).most_common(1)
bc = Counter(B).most_common(1)
#print(ac, bc, points)
ans = ac[0][1] + bc[0][1]
if (ac[0][0] + 1, bc[0][0] + 1) in points:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    H, W, M = MI()
    hh = [0]*(H+1)
    ww = [0]*(W+1)
    bomb = set()
    for _ in range(M):
        h, w = MI()
        hh[h] += 1
        ww[w] += 1
        bomb.add((h, w))
    h_max = max(hh)
    w_max = max(ww)
    ans = h_max+w_max
    if (hh.index(h_max), ww.index(w_max)) in bomb:
        ans -= 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

h = []
w = []

bombs=[]

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

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

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

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

ans = max_h + max_w

indexes_h = set(indexes_h)
indexes_w = set(indexes_w)

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

print(ans-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial,sqrt
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    h,w,m=MI()
    lis1=[]
    lis2=[]
    for i in range(m):
        a,b=MI()
        lis1.append(a)
        lis2.append(b)
    c1=Counter(lis1)
    X=c1.most_common()
    #print(c1)
    c2=Counter(lis2)
    Y=c2.most_common()
    #print(c2)
    cand1=[]
    cand2=[]
    for a,b in X:
        if b==X[0][1]:
            cand1.append(b)
        else:
            break
    #print(cand1)
    for a,b in Y:
        if b==Y[0][1]:
            cand2.append(b)
        else:
            break
    #print(cand2)
    if cand2[0]>=len(cand1) and cand1[0]>=len(cand2):
        print(cand1[0]+cand2[0]-1)
    else:
        print(cand1[0]+cand2[0])
            
    

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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


ab_t = list(zip(*ab))
abh =ab_t[0] 
abw =ab_t[1]

from collections import Counter
ch = Counter(abh)
cw = Counter(abw)

hl =[]
wl =[]
for i in range(1,h+1):
    hl.append(ch[i])

for j in range(1,w+1):
    wl.append(cw[i])

hmax = max(hl)
wmax = max(wl)

hml = [k for k, v in ch.items() if v == hmax]
wml = [k for k, v in cw.items() if v == wmax]

for i in hml:
    for j in wml:
        if [i,j] in ab:
            pass
        else:
            print(hmax+wmax)
            exit()
print(hmax+wmax-1)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

for xk,xv in xc.most_common(300):
    for yk,yv in yc.most_common(300):
        if (yk,xk) in yxs: continue
        ans = max(ans, yv + xv)
print(ans)

Submission status: Wrong Answer

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

hdic = {}
wdic = {}
hws = []

for m in range(M):
    h, w = map(int, input().split())
    if h in hdic.keys():
        hdic[h] += 1
    else:
        hdic[h] = 1
    
    if w in wdic.keys():
        wdic[w] += 1
    else:
        wdic[w] = 1
    hws.append([h, w])

max_h = max(hdic, key=hdic.get)
max_w = max(wdic, key=wdic.get)
print(hdic[max_h] + wdic[max_w] - int([h, w] in hws))

Submission status: Wrong Answer

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

hw = np.array(hw)

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

print(ans)

Submission status: Wrong Answer

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

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

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

for xk,xv in xc.most_common(500):
    for yk,yv in yc.most_common(500):
        if (yk,xk) in yxs: continue
        ans = max(ans, yv + xv)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

H,W,M = map(int,input().split())
bomb = [[0,0] for _ in range(M)]
bomb_d = defaultdict(int)

for i in range(M):
    bomb[i] = list(map(int,input().split()))
    bomb[i][0] -= 1
    bomb[i][1] -= 1
    bomb_d[tuple(bomb[i])] = 1


dh = [0]*H
dw = [0]*W

for i in range(M):
    dh[bomb[i][0]] += 1
    dw[bomb[i][1]] += 1

Maxh = max(dh)
Maxw = max(dw)

h_p = []
w_p = []

for i in range(H):
    if dh[i] == Maxh:
        h_p.append(i)
for i in range(W):
    if dw[i] == Maxw:
        w_p.append(i)

f = 0
for h in h_p:
    for w in w_p:
        if bomb_d[(h,w)] != 1:
            f = 1
            print(h,w)

if f == 0:
    print(Maxh+Maxw-1)
else:
    print(Maxh+Maxw)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int,input().rstrip().split())
l = [[0 for i in range(H)] for j in range(W)]
r = [0]*H
c = [0]*W
for i in range(M):
    h, w = map(int,input().rstrip().split())
    l[w-1][h-1] = 1
    r[h-1] += 1
    c[w-1] += 1
max_r = max(r)
max_c = max(c)
r_i =[i for i, x in enumerate(r) if x == max_r]
c_j =[i for i, x in enumerate(c) if x == max_c]
ans = max_r+max_c-1
for i in r_i:
    for j in c_j:
        if l[j][i] == 0:
            print(i,j)
            ans = max_r+max_c
            break
    else:
        continue
    break
print(ans)

Submission status: Wrong Answer

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

list1 = []
for i in range(M):
    list1.append(list(map(int, input().split())))

listh = [0 for i in range(H+1)]
listw = [0 for i in range(W+1)]
for k in range(M):
    listh[list1[k][0]]+=1

max1 = 0
loc1 = 0
for i in range(len(listh)):
    if max1 < listh[i]:
        max1 = listh[i]
        loc1 =  i

for k in range(M):
    if list1[k][0] == loc1:
        continue
    else:
        listw[list1[k][1]]+=1

max2 = 0
loc2 = 0
for i in range(len(listw)):
    if max2 < listw[i]:
        max2 = listw[i]
        loc2 =  i

print(max1 + max2)

Submission status: Wrong Answer

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

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

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



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def read():
    H, W, M = map(int, input().split(' '))
    ts = set()
    for _ in range(M):
        h, w = map(int, input().split(' '))
        ts.add((h, w))
    return H, W, M, ts

def func(H, W, M, ts):
    hs = dict()
    ws = dict()
    for h, w in ts:
        if h not in hs:
            hs[h] = 0
        if w not in ws:
            ws[w] = 0
        hs[h] += 1
        ws[w] += 1
    maxh = max(hs.values())
    maxw = max(ws.values())
    candidate_h = []
    candidate_w = []
    for k, v in hs.items():
        candidate_h.append(k)
    for k, v in ws.items():
        candidate_w.append(w)
    ans = -1
    for h in candidate_h:
        for w in candidate_w:
            temp = hs[h] + ws[w]
            if (h, w) in ts:
                temp -= 1
            if temp > ans:
                ans = temp
    return ans


if __name__ == '__main__':
    H, W, M, ts = read()
    print(func(H, W, M, ts))

Submission status: Wrong Answer

Solution code:
import collections

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

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

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

print(ans)

Submission status: Wrong Answer

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

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

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

for xk,xv in xc.most_common(1000):
    for yk,yv in yc.most_common(1000):
        if (yk,xk) in yxs: continue
        ans = max(ans, yv + xv)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import collections

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

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

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

    bomH=countedh.most_common()[0][0]
    bomW=countedw.most_common()[0][0]

    tmp=0
    for i in range(M):
        if(listH[i]==bomH or listW[i]==bomW):
            tmp+=1
    
    print(tmp)
resolve()

Submission status: Wrong Answer

Solution code:
H, W, M = map(int,input().split())
S1 = [0 for i in range(H)]
S2 = [0 for i in range(W)]
bombs_list = []

for i in range(M):
  hi, wi = map(int,input().split())
  bombs_list.append([hi, wi])
  S1[hi-1] += 1
  S2[wi-1] += 1

S1max = max(S1)
S1max_index = [i for i, x in enumerate(S1) if x == S1max]
S2max = max(S2)
S2max_index = [i for i, x in enumerate(S2) if x == S2max]
bombs = S1max + S2max

for i in range(M):
  hi = bombs_list[i][0]
  wi = bombs_list[i][1]
  if hi-1 in S1max_index and wi-1 in S2max_index:
    if len(S1max_index) == 1 and len(S2max_index) == 1:
      bombs -= 1
      break
    else:
      if len(S1max_index) > 1:
        S1max_index.remove(hi-1)
      if len(S2max_index) > 1:
        S2max_index.remove(wi-1)

print(bombs)

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

Submission status: Wrong Answer

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

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

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

for xk,xv in xc.most_common(100):
    for yk,yv in yc.most_common(100):
        if (yk,xk) in yxs: continue
        ans = max(ans, yv + xv)
print(ans)

Submission status: Wrong Answer

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

freq_w = [ 0 for _ in range(W)]
freq_h = [ 0 for _ in range(H)]
pos = dict()

for _ in range(M):
    h, w = map(int, input().split())
    freq_h[h-1] += 1
    freq_w[w-1] += 1
    pos[(h-1, w-1)] = True


m_w = max(freq_w)
pos_w = [i for i, j in enumerate(freq_w) if j == m_w]

m_h = max(freq_h)
pos_h = [i for i, j in enumerate(freq_h) if j == m_h]

max_ = m_w + m_h - 1
for i in pos_h:
    for j in pos_w:
        if not((i, j) in pos):
            max_ += 1
print(max_)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
H, W, M = map(int, input().split())
d = defaultdict(int)
tate = [0 for i in range(H+1)]
yoko = [0 for i in range(W+1)]
for i in range(M):
    x, y = map(int, input().split())
    d[(x, y)] = 1
    tate[x] += 1
    yoko[y] += 1

ans = 0
T = []
Y = []
for i, v in enumerate(tate):
    T.append((v, i))
for i, v in enumerate(yoko):
    Y.append((v, i))
T.sort(reverse=True)
Y.sort(reverse=True)

value_t = T[0][0]
value_y = Y[0][0]
cnt_t = 0
cnt_y = 0
for value, index in T:
    if value == value_t:
        cnt_t += 1

for Value, Index in Y:
    if Value == value_y:
        cnt_y += 1
if cnt_t*cnt_y > M:
    print(value_t*value_y)

else:
    M = T[0][0]+Y[0][0] - 1
    value_t = T[0][0]
    value_y = Y[0][0]
    for value, index in T:
        if value < value_t:
            break
        for Value, Index in Y:
            if Value < value_y:
                break
            if (index, Index) in d.keys():
                ans = max(ans, value+Value-1)
            else:
                ans = max(ans, value+Value)
    print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

h,w,m=rm()
lih = []
liw = []
for _ in range(m):
  a,b=rm()
  lih.append(a)
  liw.append(b)
ch=collections.Counter(lih)
cw=collections.Counter(liw)
lish=sorted(ch.items(),key=lambda x:x[1])
lisw=sorted(cw.items(),key=lambda x:x[1])
a=lish[-1][0]
b=[]
ddd=lisw[-1][1]
for i in reversed(lisw):
  if i[1]==ddd:
    b.append(i[0])
lenb=len(b)
cnt=lish[-1][1]+ddd
for i,j in zip(lih,liw):
  ccc=0
  for aaa in b:
    if i==a and j==b:
      ccc+=1
  if ccc == lenb:
    cnt-=1
print(cnt)

Submission status: Wrong Answer

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

ans=[]

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

for i in range(m):
    Y=[]
    for j in range(m):
        if X[i][0]==X[j][0]:
            Y.append(X[j])
    for j in range(m):
        if X[i][1]==X[j][1]:
            Y.append(X[j])
    ans.append(len(get_unique_list(Y)))
print(max(ans))

Submission status: Wrong Answer

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

hdic = {}
wdic = {}
hw = [[0 for _ in range(W)] for _ in range(H)]

for m in range(M):
    h, w = map(int, input().split())
    if h in hdic.keys():
        hdic[h] += 1
    else:
        hdic[h] = 1
    
    if w in wdic.keys():
        wdic[w] += 1
    else:
        wdic[w] = 1
    hw[h-1][w-1] += 1

max_h = max(hdic, key=hdic.get)
max_w = max(wdic, key=wdic.get)

print(hdic[max_h] + wdic[max_w] - hw[max_h-1][max_w-1])

Submission status: Wrong Answer

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

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

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

for xk,xv in xc.most_common()[:100]:
    for yk,yv in yc.most_common()[:100]:
        if (yk,xk) in yxs: continue
        ans = max(ans, yv + xv)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
h, w, m = map(int, input().split())
hw =[list(map(int, input().split())) for i in range(m)]
hh = [0]*m
ww = [0]*m
for i in range(m):
  hh[i] = hw[i][0]
  ww[i] = hw[i][1]
  
hcnt = collections.Counter(hh).most_common()[0][1]
wcnt = collections.Counter(ww).most_common()[0][1]

ans = hcnt + wcnt
if [collections.Counter(hh).most_common()[0][0],collections.Counter(ww).most_common()[0][0]] in hw:
  ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:

h,w,m=list(map(int,input().split()))
from collections import defaultdict
x=defaultdict(list)
s=set()
d={}
e={}
for i in range(m):
    a,b=list(map(int,input().split()))
    x[a].append(b)
    s.add((a,b))
    if a in d:
        d[a]+=1
    else:
        d[a]=1
    if b in e:
        e[b]+=1
    else:
        e[b]=1
ma=0
for i in e:
    ma=max(ma,e[i])
mi=0
for i in d:
    mi=max(mi,d[i])
a=[]
for i in d:
    if d[i]==mi:
        a.append(i)
b=[]
for i in e:
    if e[i]==ma:
        b.append(i)
for i in a:
    for j in b:
        if j not in x[i]:
            print(mi+ma)
            break
else:    
    print(ma+mi-1)

Submission status: Wrong Answer

Solution code:
def read():
    H, W, M = map(int, input().split(' '))
    ts = set()
    for _ in range(M):
        h, w = map(int, input().split(' '))
        ts.add((h, w))
    return H, W, M, ts

def func(H, W, M, ts):
    hs = dict()
    ws = dict()
    for h, w in ts:
        if h not in hs:
            hs[h] = 0
        if w not in ws:
            ws[w] = 0
        hs[h] += 1
        ws[w] += 1
    maxh = max(hs.values())
    maxw = max(ws.values())
    candidate_h = []
    candidate_w = []
    for k, v in hs.items():
        if v >= maxh - 1:
            candidate_h.append(k)
    for k, v in ws.items():
        if v >= maxw - 1:
            candidate_w.append(w)
    ans = -1
    for h in candidate_h:
        for w in candidate_w:
            temp = hs[h] + ws[w]
            if (h, w) in ts:
                temp -= 1
            if temp > ans:
                ans = temp
    return ans


if __name__ == '__main__':
    H, W, M, ts = read()
    print(func(H, W, M, ts))