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 copy
import sys
H, W, M= map(int,input().split())
height = [0]*H
width = [0]*W
object = [[0 for i in range(W)] for j in range(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
p = len(cand_h)*len(cand_w)
if M > p:
   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
else:
   ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import random
import time
start=time.time()
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
ans=0
random.shuffle(w)
for j in w:
  for x,i in hh:
    if (i,j) in hw:
      ans=max(ans,s+x-1)
    else:
      ans=max(ans,s+x)
  if time.time()-start>=1.7:exit(print(ans))
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 = []
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 = tate[0][0]+yoko[0][0]-1
if h == 1 or w == 1:
    print(m)
    exit()

  # print(tate)
  # print(yoko)

i = 0
j = 0
while i < h and i <= 30:
    while j < w and j <= 30:
        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 collections import defaultdict
a,b,m=map(int,input().split())
r=defaultdict(int)
c=defaultdict(int)
d=defaultdict(int)
for i in range(m):
  x,y=map(int,input().split())
  d[(x,y)]=1
  r[x]+=1
  c[y]+=1
z=list()
zz=list()
x=max(r,key=r.get)
y=max(c,key=c.get)
for i in r.keys():
  if r[i]==r[x]:
    z.append(r[i])
for i in c.keys():
  if c[i]==c[y]:
    zz.append(c[i])
flag=False
for i in z:
  for j in zz:
    if d[(i,j)]==0:
      flag=True
      break
if flag==False:
  print(r[x]+c[y]-1)
else:
  print(r[x]+c[y])

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

import sys

int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, W, M = map(int, readline().split())
m = [list(map(int1, readline().split())) for _ in range(M)]

hs = [0] * H
ws = [0] * W
ans = 0

for (h_, w_) in m:
    hs[h_] += 1
    ws[w_] += 1

dh = 0
dw = 0

for h_ in range(H):
    for w_ in range(W):
        if (hs[h_] < dh) or (ws[w_] < dw):
            continue

        acc = hs[h_] + ws[w_]
        if (h_, w_) in m:
            acc -= 1

        ans = max(ans, acc)
        dh = hs[h_]
        dw = ws[w_]

print(ans)

Submission status: Wrong Answer

Solution code:
H, W, M = map(int, input().split())
ans_H = [0] * (H + 1)
ans_W = [0] * (W + 1)

hw = []

for _ in range(M):
    h, w = map(int, input().split())
    ans_H[h] += 1
    ans_W[w] += 1
    hw.append([h, w])

h_ind = ans_H.index(max(ans_H))
w_ind = ans_W.index(max(ans_W))
tmp = 0

if hw.count([h_ind, w_ind]) != 0:
    ans = max(ans_H) + max(ans_W)
    ans -= 1
    """
    ans_H[h_ind] -= 1
    ans1 = max(ans_H) + max(ans_W)
    ans_H[h_ind] += 1
    ans_W[w_ind] -= 1
    ans2 = max(ans_H) + max(ans_W)
    ans = max(ans1, ans2)
    """
else:
    ans = max(ans_H) + max(ans_W)

print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M = map (int, input ().split ())
p = 0
X = []
Y = []
Z = []
for i in range (M):
  x,y = map (int ,input ().split ())
  X.append (x)
  Y.append (y)
  Z.append (x*10+y)
from statistics import mode
x = mode(X)
y = mode(Y)
p += X.count (x)
p += Y.count (y)
print (p-Z.count (x*10+y))

Submission status: Wrong Answer

Solution code:
n,m,k=map(int,input().split())
c={}
e={}
for i in range(k):
    a,b=map(int,input().split())
    t=str(a)+'x'
    s=str(b)+'y'
    e[t+s]=1
    if t in c:
        c[t]+=1
    else:
        c[t]=1
    if s in c:
        c[s]+=1
    else:
        c[s]=1
d=sorted(c.items(),key=lambda x:x[1],reverse=True)
p,r=d[0]
w=''
p=list(p)
m=r
if p[1]=='x':
    for i in range(len(d)):
        u,v=d[i]
        u=list(u)
        if u[1]=='y':
            m+=v
            w+=''.join(p)+''.join(u)
            break
else:
    for i in range(len(d)):
        u, v = d[i]
        u = list(u)
        if u[1] == 'x':
            m += v
            w+=''.join(u)+''.join(p)
            break

if w in e:
    print(m-1)
else:
    print(m)

Submission status: Wrong Answer

Solution code:
import collections

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

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
loc=[[0,0] for n in range(M)]
for i in range(M):
    loc[i]=list(map(int,input().split()))
numlist=[]
bombloc=[0,0]
for h in range(H):
    for w in range(W):
        num=0
        for oneloc in loc:
            if oneloc[0]==h or oneloc[1]==w:
                num+=1
            numlist.append(num)
print(max(numlist))

Submission status: Wrong Answer

Solution code:
import collections

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

li, row_li, column_li = [], [], []

sum_row, sum_column, count = 0, 0, 0

for i in range(m):
    temp_li = list(map(int, input().split()))
    row_li.append(temp_li[0])
    column_li.append(temp_li[1])
    li.append(temp_li)

c_row = collections.Counter(row_li)
c_column = collections.Counter(column_li)

# print(li)
# print(row_li)
# print(c_row.most_common()[0][0])
# print(column_li)
# print(c_column.most_common()[0][0])

for n in li:
    if n[0] == c_row.most_common()[0][0] or n[1] == c_column.most_common()[0][0]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:

def resolve():
    H,W,M = map(int,input().split())
    yy=dict()
    xx=dict()    
    bd=dict()
    for i in range(M):
        h,w = map(int,input().split())
        if not h in yy:
            yy[h]=0
        if not w in xx:
            xx[w]=0
 
        yy[h]+=1
        xx[w]+=1

        if not (h,w) in bd:
            bd[(h,w)]=0
        bd[(h,w)]+=1 
    x = list(xx.items())
    x.sort(key=lambda i: i[1])    
    y = list(yy.items())
    y.sort(key=lambda i: i[1])    
    mx = 0
    
    for xxx,scx in x:
        cou =-1
        for yyy,scy in y:
            sc = scx+scy
            if sc < mx:
                if cou -1 or cou ==scy:
                    cou =scy
                else:
                    break
            if (yyy,xxx) in bd:
                sc-=bd[(yyy,xxx)]
            mx = max(sc,mx)
    print(mx)

resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import collections
import sys
input=sys.stdin.readline

h,w,m=map(int,input().split())
items=[set() for _ in range(h+1)]
count_h=[0]*(h+1)
count_w=[0]*(w+1)
for _ in range(m):
    y,x=map(int,input().split())
    items[y].add(x)
    count_h[y]+=1
    count_w[x]+=1
count_num=collections.defaultdict(int)
for x in range(1,w+1):
    count_num[count_w[x]]+=1
count_cand=list(count_num.keys())
count_cand=sorted(count_cand,reverse=True)
ans=0
for y in range(1,h+1):
    value_y=count_h[y]
    count_tmp=collections.defaultdict(int)
    for x in items[y]:
        value_x=count_w[x]
        count_tmp[value_x]+=1
        ans=max(ans,value_y+value_x-1)
    for x in count_cand:
        value_x=count_w[x]
        if count_num[value_x]>count_tmp[value_x]:
            ans=max(ans,value_y+value_x)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w,m=map(int,input().split())
print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


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

h = [-1]
w = [-1]
hw_dict = defaultdict(int)
for _ in range(M):
    hi, wi = map(int, input().split())
    h.append(hi)
    w.append(wi)
    hw_dict[(hi, wi)] = 1
# print(h)
# print(w)
# print(hw)
h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)
for i in range(1, M + 1):
    h_cnt[h[i]] += 1
    w_cnt[w[i]] += 1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1, H + 1):
    if len(h_max_idx) >= 10**2:
        break
    if h_cnt[i] == h_max:
        h_max_idx.append(i)

for i in range(1, W + 1):
    if len(w_max_idx) >= 10**2:
        break
    if w_cnt[i] == w_max:
        w_max_idx.append(i)

# print(h_max_idx)
# print(w_max_idx)

# if len(h_max_idx)>=10**2:
#     h_max_idx = h_max_idx[:10**2]
# if len(w_max_idx)>=10**2:
#     w_max_idx = w_max_idx[:10**2]

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp = h_cnt[i] + w_cnt[j]
        if hw_dict[(i, j)] == 1:
            tmp -= 1
        ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split(" ")) 
hl=[] 
wl=[] 
c=[list(input().split(" "))for i in range(M)]
for i in range(M): 
    hl.append(c[i][0]) 
    wl.append(c[i][1]) 
from collections import Counter 
ac=Counter(hl)
bc=Counter(wl)

a=ac.most_common(1)[0]
b=bc.most_common(1)[0]
count=a[1]+b[1]
if [a[0],b[0]] in c:
    count-=1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

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

from collections import defaultdict

bom = defaultdict(int)
rows = [0] * H
columns = [0] * W
ng_rows = defaultdict(list)
for h, w in hw:
    rows[h - 1] += 1
    columns[w - 1] += 1
    ng_rows[w - 1].append(h - 1)
max_row = max(rows)
max_row_idx = set()
for i in range(h):
    if rows[i] == max_row:
        max_row_idx.add(i)
ans = 0
for i in range(w):
    res = columns[i]
    cnt = 0
    for j in ng_rows[i]:
        if j in max_row_idx:
            cnt += 1
    if cnt >= len(max_row_idx):
        res += max_row - 1
    else:
        res += max_row
    ans = max(ans, res)
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]
print(ans)

Submission status: Wrong Answer

Solution code:
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])
if [h.index(max(h)), w.index(max(w))] in ab:
    print(max(h)+max(w)-1)
else:
    print(max(h)+max(w))

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

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

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


print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W, M = list(map(int, input().split()))
    h = np.zeros(M, dtype=int)
    w = np.zeros(M, dtype=int)

    sum_h = np.zeros(H, dtype=int)
    sum_w = np.zeros(W, dtype=int)

    ans = 0

    for m in range(M):
        tmp = list(map(int, input().split()))
        tmp_h = tmp[0]-1
        tmp_w = tmp[1]-1

        h[m] = tmp_h
        w[m] = tmp_w

        sum_h[tmp_h] += 1
        sum_w[tmp_w] += 1

    if H == 1:
        print(sum_w.sum())
        return
    elif W == 1:
        print(sum_h.sum())
        return


    ans_h = np.argmax(sum_h) # hについては決定
    ans += max(sum_h)

    for m in range(M):
        if h[m] == ans_h:
            sum_w[w[m]] -= 1

    ans_w = np.argmax(sum_w)
    ans += max(sum_w)

    print(ans)
    pass


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
print(0)

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)
hmp = []
for i in range(h):
    if H[i] == hm:
        hmp.append(i)

wm = max(W)
wmp = []
for i in range(w):
    if W[i] == wm:
        wmp.append(i)

ans = hm + wm

f = True
for i in hmp:
    for j in wmp:
        if not(j in hw[i]):
            f = False
            break
    else:
        break
ans -= f
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
list_H = []
list_W = []
H,W,M = map(int,input().split())
for i in range(M):
    S1,S2 = map(int,input().split())
    list_H.append(S1)
    list_W.append(S2)
c1 = collections.Counter(list_H)
mode1 =c1.most_common()[0]
c2 = collections.Counter(list_W)
mode2 =c2.most_common()[0]
bomb = (mode1[0],mode2[0])
num = mode1[1]+mode2[1]
for j in range(M):
    if list_H[j]==mode1[0] and list_W[j]==mode2[0]:
        num -= 1
        break
print(num)

Submission status: Wrong Answer

Solution code:
H,W,M = map (int, input ().split ())
p = 0
X = []
Y = []
Z = []
for i in range (M):
  x,y = map (int ,input ().split ())
  X.append (x)
  Y.append (y)
  Z.append (x*10+y)
from statistics import mode
x = mode(X)
y = mode(Y)
p += X.count (x)
p += Y.count (y)
if Z.count (x*10+y) == 0:
  print (p)
else:
  print (p-1)

Submission status: Wrong Answer

Solution code:
h,w,m = map(int,input().split())
b = []
x = [0 for _ in range(w)]
y = [0 for _ in range(h)]
for i in range(m):
  bh,bw = map(int,input().split())
  bh -= 1
  bw -= 1
  b.append((bh,bw))
  x[bw] += 1
  y[bh] += 1
#print(b,x,y)

mxx = max(x)
mxy = max(y)

cmxb = 0
for by,bx in b:
  if y[by]+x[bx] == mxx+mxy-1:
    cmxb += 1
cmxx = 0
for xi in x:
  if xi == mxx:
    cmxx += 1
cmxy = 0
for yi in y:
  if yi == mxy:
    cmxy += 1
#print(cmxb,cmxx,cmxy)

if cmxb >= cmxx*cmxy:
  print(mxx+mxy-1)
else:
  print(mxx+mxy)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy3

from sys import stdin, stdout
 
def input():
    return stdin.readline().strip()

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

x_score = [0]*300009
y_score = [0]*300009

elems = set()

for _ in range(M):
    h, w = input().split()
    h = int(h)
    w = int(w)

    x_score[h] += 1
    y_score[w] += 1

    elems.add((h, w))

best_x_score = max(x_score)
best_y_score = max(y_score)

best_x = []
best_y = []

for i in range(len(x_score)):
    if x_score[i] == best_x_score:
        best_x += [i]
    
for i in range(len(y_score)):
    if y_score[i] == best_y_score:
        best_y += [i]

import sys

if len(best_x)*len(best_y) > M+10:
    print(x_score + y_score)
    sys.exit(0)

for x in best_x:
    for y in best_y:
        if (x, y) not in elems:
            print(best_x_score + best_y_score)
            sys.exit(0)

print(best_x_score + best_y_score - 1)

Submission status: Wrong Answer

Solution code:
import math
import collections
import itertools

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import collections
h, w, m = map(int, input().split())
L_g = []
L_r = []
L = []
for i in range(m):
    a, b = map(int, input().split())
    L_g.append(a)
    L_r.append(b)
    L.append((a, b))
c1 = collections.Counter(L_g)
c2 = collections.Counter(L_r)

L1 = c1.most_common()
L2 = c2.most_common()

bom = (L1[0][0], L2[0][0])
t = L1[0][1]+L2[0][1]

for e in L:
    if e == bom:
        t -= 1
print(t)

Submission status: Wrong Answer

Solution code:
H,W,M=map(int,input().split())
h,w=map(list,zip(*[list(map(int,input().split())) for i in range(M)]))
from collections import Counter
hc,wc=Counter(h),Counter(w)
r=max([hc[h[i]]+wc[w[i]]-1 for i in range(M)])
hx,wx=hc.most_common()[0][1],wc.most_common()[0][1]
hl,wl=set([k for k,v in hc.items() if v==hx]),set([k for k,v in wc.items() if v==wx])
s=set()
for i in range(M):
    if h[i] in hl:
        s.add(w[i])
print(hx+wx if wl-s else r)

Submission status: Wrong Answer

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

counterH = Counter()
counterW = Counter()
targets = set()
for i in range(M):
    h,w = list(map(int,input().split()))
    counterH[h] += 1
    counterW[w] += 1
    targets.add((h,w))

if M == 1:
    print(1)
    exit()

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

Submission status: Wrong Answer

Solution code:
import numpy as np
 
H, W, M = [int(n) for n in input().split()]

Submission status: Wrong Answer

Solution code:
H, W, N = map(int, input().split())
h_array = [0]*H
w_array = [0]*W
array = []
for _ in range(N):
    h, w = map(int, input().split())
    array.append([h,w])
    h_array[h-1] +=1
    w_array[w-1] +=1
max_h = max(h_array)
h_indexes = [i for i, x in enumerate(h_array) if x == max_h]
max_w = max(w_array)
w_indexes = [i for i, x in enumerate(w_array) if x == max_w]

count=0
for i in range(len(h_indexes)): 
  for j in range(len(w_indexes)):
    if [h_indexes[i]+1, w_indexes[j]+1] in array:
      count = max_h + max_w -1
    else:
      count = max_h + max_w
print(count)

Submission status: Wrong Answer

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

h_obj=[0]*(h+1)
w_obj=[0]*(w+1)
hw_grid=[]
for _ in range(m):
  li=list(map(int,input().split()))
  hw_grid.append(li)
  h_obj[li[0]]+=1
  w_obj[li[1]]+=1
  
def index_Multi(List,liter):
    #Listはリスト本体・literは検索したい文字
    index_L = []
    for val in range(0,len(List)):
        if liter == List[val]:
            index_L.append(val)
    return index_L
  
max_h=max(h_obj)
max_w=max(w_obj)

max_h_li=index_Multi(h_obj,max_h)
max_w_li=index_Multi(w_obj,max_w)

#print("max_w_li",max_w_li)
#print("max_h_li",max_h_li)
#print(hw_grid)

for H in max_h_li:
  for W in max_w_li:
    #print("print([H,W])",[H,W])
    if [H,W] not in hw_grid:
      #print(max(h_obj)+max(w_obj))
      sys.exit()
print(max(h_obj)+max(w_obj)-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W,M = map(int,input().split( ))
Hs = [0 for _ in range(H)]
Ws = [0 for _ in range(W)]
hws = []
for _ in range(M):
    h,w = map(int,input().split( ))
    hws.append([h-1,w-1])
    Hs[h-1] += 1
    Ws[w-1] += 1
hw = [np.argmax(Hs),np.argmax(Ws)]
hs = []
ws = []
maxh = max(Hs)
maxw = max(Ws)
for h in Hs:
    if h == maxh:
        hs.append(h)
for w in Ws:
    if w == maxw:
        ws.append(w)

in_out = 0
for w in ws:
    for h in hs:
        if [h,w] in hws:
            in_out = 1
if in_out:
    print(maxh + maxw - 1)
else:
    print(maxh + maxw)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
# n=int(stdin.readline())
m,n,t=list(map(int,stdin.readline().split()))
r={};c={};l=[]
for i in range(t):
    x,y=map(int,stdin.readline().split())
    r[x]=r.get(x,0)+1
    c[y]=c.get(y,0)+1
    l+=[[x,y]]
sel_row=sel_col=0;mx=0
for k,v in r.items():
    if mx<v:
        mx=v
        sel_row=k
mx=0
for k,v in c.items():
    if mx<v:
        mx=v
        sel_col=k
print(r[sel_row]+c[sel_col]-int([sel_row,sel_col] in l))

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    h, w, m = i_map()
    num_list = i_row_list(m)

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

    h_list = []
    w_list = []

    count = 0

    for num in num_list:
        h_list.append(num[0])
        w_list.append(num[1])

    co_h_list = Counter(h_list)
    co_w_list = Counter(w_list)

    # print(num_list)
    # print(co_h_list.most_common())
    # print(co_w_list.most_common())

    h_max_key = co_h_list.most_common()[0][0]
    h_max_value = co_h_list.most_common()[0][1]

    w_max_key = co_w_list.most_common()[0][0]
    w_max_value = co_h_list.most_common()[0][1]

    if h_max_value >= w_max_value:
        max_index = h_max_key
        count = h_max_value

        tmp_list = []
        for num in num_list:
            if num[0] == max_index:
                continue
            tmp_list.append(num[1])

        if len(tmp_list) != 0:
            count += Counter(tmp_list).most_common()[0][1]
    else:
        max_index = w_max_key
        count = w_max_value

        tmp_list = []
        for num in num_list:
            if num[1] == max_index:
                continue
            tmp_list.append(num[0])
            
        if len(tmp_list) != 0:  
            count += Counter(tmp_list).most_common()[0][1]

    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H,W,M = map(int,input().split())
TH = {}
TW = {}
TS = set()

for _ in range(M):
  h,w = map(int,input().split())
  TS.add((h,w))
  if h in TH:
    TH[h] += 1
  else:
    TH[h] = 1
  if w in TW:
    TW[w] += 1
  else:
    TW[w] = 1

maxhi = -1
maxhh = 0
for i,h in TH.items():
  if maxhh < h:
    maxhi = i
    maxhh = h
    
res = 0
p = 0
for i in range(W+1):
  if not i in TW:
    continue
  p = maxhh + TW[i]
  if (maxhi,i) in TS:
    p -= 1
  res = max(res,p)
  
print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W, M = list(map(int, input().split()))
    h = np.zeros(M, dtype=int)
    w = np.zeros(M, dtype=int)

    sum_h = np.zeros(H, dtype=int)
    sum_w = np.zeros(W, dtype=int)

    ans = 0

    for m in range(M):
        tmp = list(map(int, input().split()))
        tmp_h = tmp[0]-1
        tmp_w = tmp[1]-1

        h[m] = tmp_h
        w[m] = tmp_w

        sum_h[tmp_h] += 1
        sum_w[tmp_w] += 1

    if H == 1:
        print(sum_w.sum())
    elif W == 1:
        print(sum_h.sum())


    ans_h = np.argmax(sum_h) # hについては決定
    ans += max(sum_h)

    for m in range(M):
        if h[m] == ans_h:
            sum_w[w[m]] -= 1

    ans_w = np.argmax(sum_w)
    ans += max(sum_w)

    print(ans)
    pass


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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


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


lh=collections.Counter(h)
lw=collections.Counter(w)

hmaxnum=lh.most_common()[0][0]
hmaxcount=lh.most_common()[0][1]

wmaxnum=lw.most_common()[0][0]
wmaxcount=lw.most_common()[0][1]

sum= hmaxcount+wmaxcount

if [hmaxnum,wmaxnum] in S:
    print(sum-1)
else:
    print(sum)

Submission status: Wrong Answer

Solution code:
h,w,m=map(int,input().split())
hw=[list(map(int,input().split())) for i in range(m)]
hs=[0]*h
ws=[0]*w
k=0
for h,w in hw:
  hs[h-1]+=1
  ws[w-1]+=1
hmax=max(hs)
wmax=max(ws)
hindexs=[i for i, x in enumerate(hs) if x == hmax]
windexs=[i for i, x in enumerate(ws) if x == wmax]
#print(hindexs,windexs)
for x in hindexs:
  for y in hindexs:
    if [x+1,y+1] in hw:
      k=1
      break
if k==1:
  print(hmax+wmax-1)
else:
  print(hmax+wmax)

Submission status: Wrong Answer

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

from collections import defaultdict
from collections import Counter
h_dic = defaultdict(int)#h[i]にいくつ爆発物があるか
w_dic = defaultdict(int)#w[i]にいくつ爆発物があるか

bomb = defaultdict(lambda:defaultdict(int))


for i in range(M):
  h,w = map(int,input().split())
  h_dic[h] += 1
  w_dic[w] += 1
  bomb[h][w] = 1
now_x = 0

firsth, num = max(h_dic.items(), key = lambda x:x[1])
for i,j in sorted(w_dic.items(), key = lambda x:x[1], reverse=True):
  if j <= now_x:
    break
  if bomb[firsth][i] == 1:
    x = j-1
  else:
    x = j
    now_x = x
    break
  now_x = x
fhans = num + now_x

firstw, num = max(w_dic.items(), key = lambda x:x[1])
for i,j in sorted(h_dic.items(), key = lambda x:x[1], reverse=True):
  if j <= now_x:
    break
  if bomb[i][firstw] == 1:
    x = j-1
  else:
    x = j
    now_x = x
    break
  now_x = x
fwans = num + now_x
print(max(fhans,fwans))

Submission status: Wrong Answer

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

h = [-1]
w = [-1]
hw = []
for _ in range(M):
    hi,wi = map(int,input().split())
    h.append(hi)
    w.append(wi)
    hw.append([hi,wi])
# print(h)
# print(w)
# print(hw)
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
for i in range(1,M+1):
    h_cnt[h[i]]+=1
    w_cnt[w[i]]+=1
# print(h_cnt)
# print(w_cnt)

h_max = max(h_cnt)
w_max = max(w_cnt)

h_max_idx = []
w_max_idx = []


for i in range(1,H+1):
    if len(h_max_idx)>=10**2:
        break
    if h_cnt[i]==h_max:
        h_max_idx.append(i)

for i in range(1,W+1):
    if len(w_max_idx)>=10**2:
        break
    if w_cnt[i]==w_max:
        w_max_idx.append(i)

# print(h_max_idx)
# print(w_max_idx)

# if len(h_max_idx)>=10**2:
#     h_max_idx = h_max_idx[:10**2]
# if len(w_max_idx)>=10**2:
#     w_max_idx = w_max_idx[:10**2]

ans = 0

for i in h_max_idx:
    for j in w_max_idx:
        tmp =  h_cnt[i]+w_cnt[j]
        if [i,j] in hw:
            tmp -=1
        ans = max(ans,tmp)
print(ans)

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]
    if [int(a[0]),int(b[0])] in hw:
        ans -= 1

    
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

row = [ 0 for _ in range(h)]
col = [ 0 for _ in range(w)]
pos = [[ 0 for c in range(w)] for r in range(h)]

for _ in range(m):
    py, px = map(int, input().split())
    row[py - 1] += 1
    col[px - 1] += 1
    pos[py - 1][px - 1] += 1

mrow = np.argmax(row)
mcol = np.argmax(col)
if pos[mrow][mcol] == 1:
    print(max(row) + max(col) - 1)
else:
    print(max(row) + max(col))