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: Runtime Error

Solution code:
def main():
    h, w, m = map(int, input().split())
    L = [list(map(int,input().split())) for _ in range(m)]
    table = [[0] * w for _ in range(h)]
    for a, b in L:
        table[a-1][b-1] = -1
    col = [0] * w
    row = [0] * h
    for i in range(w):
        col[i] = -sum([T[i] for T in table])
    for j in range(h):
        row[j] = -sum(table[j])
    for i in range(h):
      for j in range(w):
        table[i][j] += col[j] + row[i]
    print(max(max(T) for T in table))
main()

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,M = map(int,input().split())
f = np.zeros((H,W),dtype=np.int64)
for i in range(M):
  h,w = map(lambda x: int(x)-1,input().split())
  f[:,w] += 1
  f[h,:] += 1
  f[h,w] -=1
print(np.amax(f))

Submission status: Runtime Error

Solution code:
#abc176-e
import sys,math,collections,itertools
import numpy as np
input = sys.stdin.readline
H,W,M=list(map(int,input().split()))
point_bom = [[0]*(W+1) for _ in range(H+1)]
for _ in range(M):
    h,w = map(int,input().split())
    point_bom[h][w]=1
point_bom = np.array(point_bom)
row_bom = point_bom.sum(axis=0)
col_bom = point_bom.sum(axis=1)
max_row = row_bom.max()
max_col = col_bom.max()

ind_max_row =[]
ind_max_col = []

for i in range(len(row_bom)):
    if row_bom[i] == max_row:
         ind_max_row.append(i)
for i in range(len(col_bom)):
    if col_bom[i] == max_col:
        ind_max_col.append(i)

flag = 1#爆破対象が置かれる　おかれている＝１　いない＝０
for mr in ind_max_row:
    for mc in ind_max_col:
        if point_bom[mc][mr] == 0:
            flag = 0
            break
    if flag == 0:
        break
print(max_row+max_col - flag)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
bomber = [[0]*m for _ in range(m)]
bomb = {}
bomb2 = {}
ans = 0
MAX = 0
MAX_key = None

for i in range(m):
    mh, mw = map(int, input().split())
    bomber[mh-1][mw-1] = 1
    if mh in bomb:
        bomb[mh] += 1
    else:
        bomb[mh] = 1
    if mw in bomb2:
        bomb2[mw]+= 1
    else:
        bomb2[mw] = 1

max_kv_list_h = [kv for kv in bomb.items() if kv[1] == max(bomb.values())]
#print(max_kv_list_h)
#print(max_kv_list_h[0][0])

max_kv_list_w = [kv for kv in bomb2.items() if kv[1] == max(bomb2.values())]
#print(max_kv_list_w)

for i in range(len(max_kv_list_h)):
    for j in range(len(max_kv_list_w)):   
        if bomber[max_kv_list_h[i][0]-1][max_kv_list_w[j][0]-1] == 0:
            ans = max(max_kv_list_h[i][1]+max_kv_list_w[j][1], ans)
        else:
            ans = max(max_kv_list_h[i][1]+max_kv_list_w[j][1]-1, ans)


print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    H,W,M = map(int,input().split())
    h = [[0,i] for i in range(H)]
    w = [[0,i] for i in range(W)]
    HW = np.zeros((H,W))
    for i in range(M):
        tmp_0,tmp_1 = map(int,input().split())
        tmp_0 -= 1
        tmp_1 -= 1
        h[tmp_0][0] += 1
        w[tmp_1][0] += 1
        HW[tmp_0][tmp_1] += 10
    
    list.sort(h, reverse=True)
    list.sort(w, reverse=True)
    max_h = h[0][0]
    max_w = w[0][0]
    ans = max_h + max_w
    for i in range(len(h)):
        if h[i][0] < max_h:
            break
        HW[h[i][1],:] += 1
        
    for i in range(len(w)):
        if w[i][0] < max_w:
            break
        HW[:,w[i][1]] += 1
    
    if 2 not in HW:
        ans -= 1
    
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
H,W,M = map(int,input().split())
h = [0] * 300000
w = [0] * 300000
hw = []
maxH = 0
maxW = 0
for i in range(M):
  hw.append(list(map(int,input().split())))
  h[hw[i][0]] += 1
  w[hw[i][1]] += 1
maxH = max(h)
maxW = max(w)
certainI = 0

for i in range(M):
  if maxH == h[i]:
    certainI = i
certainJ = 0
for j in range(M):
  if maxW == w[j]:
    certainJ = j

for i in range(M):
  if hw[i][0] == certainI and hw[i][1] == certainJ:
    print(maxH + maxW - 1)
    exit(0)
print(maxH + maxW)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
f = np.zeros([H, W])

for _ in range(M):
  h, w = map(int, input().split())
  f[h-1,w-1] -= 30000
  f[h-1,:] += 1
  f[:,w-1] += 1

print(np.max(f))

Submission status: Runtime Error

Solution code:
H,W,M=map(int,input().split())
dp=[[0]*W for i in range(H)]
dp_h=[0]*H
dp_w=[0]*W

for i in range(M):
  h,w=map(int,input().split())
  dp_h[h-1]+=1
  dp_w[w-1]+=1
  dp[h-1][w-1]+=1
max_h=max(dp_h)
max_w=max(dp_w)
max_dp_h=set([i for i, x in enumerate(dp_h) if x==max_h])
max_dp_w=set([i for i, x in enumerate(dp_w) if x==max_w])
flag=True
for i in max_dp_h:
  for j in max_dp_w:
    if dp[i][j]!=1:
      flag=False
      break
if flag:
  print(max_h+max_w-1)
else:
  print(max_h+max_w)

Submission status: Runtime Error

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)
Z2=sorted(Counter(Y).items(),key=lambda x:x[1],reverse=True)
maxmax=Z1[0][1]
sumsum=Z1[0][1]+Z2[0][1]
if (Z1[0][0],Z2[0][0]) in tt:
    sumsum-=1
i=1
while(1):
    if maxmax!=Z1[i][1]:
        break
    sumsum=Z1[i][1]+Z2[i][1]
    if (Z1[i][0],Z2[i][0]) in tt:
        sumsum-=1
    i+=1
print(sumsum)

Submission status: Runtime Error

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

listH=[]
for i in range(M):
  listH.append(0)

listW=[]
for i in range(M):
  listW.append(0)
  
for i in range(M):
  listH[R[i-1][0]-1]+=1
maxH=0
listHmax=[]
jH=0
for i in range(M):
  if listH[i]==max(maxH,listH[i]):
    maxH=listH[i]
    listHmax.append(i)
    jH+=1

for i in range(M):
  listW[R[i-1][1]-1]+=1
maxW=0
listWmax=[]
jW=0
for i in range(M):
  if listW[i]==max(maxW,listW[i]):
    maxW=listW[i]
    listWmax.append(i)
    jW+=1
print (maxW+maxH)

Submission status: Runtime Error

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).most_common()
wc = Counter(wl).most_common()
 
seth = []
setw = []

for s in range(m):
    if hc[0][1] == hc[s][1]:
        seth.append(hc[s][0])
    if wc[0][1] == wc[s][1]:
        setw.append(wc[0][1])
    
    if hc[0][1] != hc[s][1] and wc[0][1] != wc[s][1]:
        break
 
ans = 0

zp = list(zip(hl, wl))
 
for hei in seth:
    for wei in setw:
        if not (hei, wei) in zp:
            print(hc[0][1] + wc[0][1])
            exit()

else:
    print(hc[0][1] + wc[0][1]-1)

Submission status: Runtime Error

Solution code:
import itertools
H,W,M=list(map(int,input().split()))
AA=[list(map(int,input().split())) for _ in range(M)]

h=[0]*H
w=[0]*W

for i in range(M):
    h[(AA[i][0]-1)]+=1
    w[(AA[i][1]-1)]+=1
max_h=max(h)
max_w=max(w)

X=[i for i, x in enumerate(h) if x == max_h]
Y=[i for i, x in enumerate(w) if x == max_w]

for i,j in itertools.product(X,Y):
    if [i+1,j+1] in AA:
        flag=0
        break
print(max_h+max_w-flag)

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import Counter

H, W, M = [int(n) for n in input().split()]
h = []
w = []
table = np.zeros((H, W))
for m in range(M):
    tmp = [int(n) for n in input().split()]
    h.append(tmp[0])
    w.append(tmp[1])
    table[tmp[0]][tmp[1]] = 1

h_counter = Counter(h)
w_counter = Counter(w)

most_common_h_list = []
most_common_w_list = []

most_common_h_count = 0
for k, v in h_counter.most_common():
    if v < most_common_h_count:
        break
    most_common_h_list.append(k)
    most_common_h_count = v

most_common_w_count = 0
for k, v in w_counter.most_common():
    if v < most_common_w_count:
        break
    most_common_w_list.append(k)
    most_common_w_count = v

ans = 0
finished = False
for hh in most_common_h_list:
    if finished:
        break
    for ww in most_common_w_list:
        if table[hh][ww] == 1:
            tt = most_common_h_count + most_common_w_count - 1
            if tt > ans:
                ans = tt
        else:
            tt = most_common_h_count + most_common_w_count
            if tt > ans:
                ans = tt
            break
            finished = True
            break

print(ans)

Submission status: Runtime Error

Solution code:
#e
h,w,m = map(int, input().split())
bc = [list(map(int, input().split())) for _ in range(m)]
bomb=[[0]* w for i in range(h)]
for i in bc:
    for j in range(h):
        bomb[j][i[1]-1] += 1 
    for j in range(w):
        bomb[i[0]-1][j] += 1
ans = 0
for i in bomb:
    if max(i)> ans:
        ans = max(i)
print(ans)

Submission status: Runtime Error

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

h, w, m = map(int, input().split())
mapa = [[0]*w for i in range(h)]
strings = [[0, i+1] for i in range(h)]
rows = [[0, i+1] for i in range(w)]
maxs = 0
maxr = 0
for i in range(m):
    h1, w1 = map(int, input().split())
    mapa[h1-1][w1-1] = 1
    strings[h1-1][0] += 1
    rows[w1-1][0] += 1
    if strings[h1-1][0] > maxs:
        maxs = strings[h1-1][0]
    if rows[w1-1][0] > maxr:
        maxr = rows[h1-1][0]
summa = maxs + maxr - 1
for i in range(h):
    if strings[i][0] == maxs:
        for j in range(w):
            if rows[j][0] == maxr:
                x = maxs + maxr
                if mapa[i][j] == 1:
                    x -= 1
                if x > summa:
                    summa = x
                    print(summa)
                    exit()
print(summa)

Submission status: Runtime Error

Solution code:
import sys
H,W,M=map(int, input().split())
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B = [[0 for i in range(W)] for j in range(H)] ##掛け算で書いてはいけない

for i in range(M):
    hi,wi=map(int, input().split())
    h.append(hi)
    w.append(wi)
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
    B[hi-1][wi-1]=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if B[h_max[ii]][w_max[ii]]==0:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)
'''for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        h_cand=[k for k, v in enumerate(h) if v == h_max[ii]+1]
        w_cand=[l for l, v in enumerate(w) if v == w_max[jj]+1]
        h_set = set(h_cand)
        w_set = set(w_cand)
        matched_list = list(h_set & w_set)
        #print(h_cand,w_cand)
        #print(matched_list)
        if len(matched_list)==0:
            print(max(Hcount)+max(Wcount))
            sys.exit()
print(max(Hcount)+max(Wcount)-1)
'''

Submission status: Runtime Error

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
  continue
    break
print(ans)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
hwList = [[0] * (w + 1) for i in range(h + 1)]
hList = [0] * (h + 1)
wList = [0] * (w + 1)
for x in range(m):
    h_i, w_i = map(int, input().split())
    hList[h_i] += 1
    wList[w_i] += 1
    hwList[h_i][w_i] += 1
h_max = max(hList)
w_max = max(wList)
h_maxid = [i for i, v in enumerate(hList) if v == h_max]
w_maxid = [i for i, v in enumerate(wList) if v == w_max]
isminus = 1
if len(h_maxid) * len(w_maxid) > 3 * (10 ** 5): isminus = 0
else:
    for a in h_maxid:
        if isminus == 0: break
        for b in w_maxid:
            if hwList[a][b] == 1: continue
            isminus = 0
            break
print(h_max + w_max - isminus)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split())
boms = [[] for i in range(m)]
Hs = [0] * m
Ws = [0] * m
for i in range(m):
  _h, _w = map(int, input().split())
  boms[i] = [_h-1, _w-1]
  Hs[_h - 1] += 1
  Ws[_w - 1] += 1

Submission status: Runtime Error

Solution code:
H,W,M=list(map(int, input().split()))
h = [0] * M
w = [0] * M
R_B = [[0] * W for i in range(H)]
R_B_T = [[0] * H for i in range(W)]
A_B = [[0] * W for i in range(H)]
for i in range(M):
    h[i], w[i] = map(int, input().split())
    R_B[h[i]-1][w[i]-1]=1
    R_B_T[w[i]-1][h[i]-1]=1
for hei in range(H):
    for wid in range(W):
        A_B[hei][wid]=R_B[hei][:].count(1)+R_B_T[:][hei].count(1)-R_B[hei][wid]
print(max(max(A_B)))

Submission status: Runtime Error

Solution code:
H,W,M=map(int,input().split())
mine=[list(map(int,input().split()))for i in range(M)]
mine_h=[0]*H
mine_w=[0]*W
ans=0
for i in range(M):
    mine_h[mine[i][0]-1]+=1
max_h=max(mine_h)
for i in mine_h:
    tmp=0
    if i ==max_h:
        mine_w=[0]*W
        for j in range(M):
            if mine[j][0]-1!=i:
                mine_w[mine[j][0]-1]+=1
        tmp=max_h+max(mine_w)
        if tmp>ans:
            ans=tmp
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

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

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

h_count = collections.Counter(h)
w_count = collections.Counter(w)

h_count_max = h_count.most_common()[1]
w_count_max = w_count.most_common()[1]

max = 0
for i in range(1, H + 1):
    if (h_count[i] != h_count_max):
        continue

    for j in range(1, W + 1):
        if (w_count[j] != w_count_max):
            continue

        count = h_count[i] + w_count[j]

        if ((i, j) in point):
            count = count - 1

        if (count > max):
            max = count

print(max)

Submission status: Runtime Error

Solution code:
h,w,m=map(int, input().split())
r = [0]*10
c = [0]*10

for i in range(m):
    x,y=map(int, input().split())
    r[x]+=1
    c[y]+=1

print(max(r)+max(c))

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h = np.zeros(H)
w = np.zeros(W)
m = np.zeros((H, W))
ans = 0
for _ in range(M):
    tmp_h, tmp_w = map(int, input().split())
    h[tmp_h-1] += 1
    w[tmp_w-1] += 1
    m[tmp_h-1, tmp_w-1] = 1.

h_max = np.max(h)
h_max_index = list(zip(*np.where(h == h_max)))
w_max = np.max(w)
w_max_index = list(zip(*np.where(w == w_max)))


for i in h_max_index:
    for j in w_max_index:
        try:
            if m[i[0]][j[0]] == 1.:
                tmp = h_max + w_max -1
            else:
                tmp = h_max + w_max
            if ans < tmp:
                ans = tmp
        except IndexError:
            pass
print(int(ans))

Submission status: Runtime Error

Solution code:
import sys, math, heapq, bisect





if(__name__ == "__main__"):
    """
    N = int( input().strip() )
    Length = list( map(int, input().strip().split() ) )
    """
    H, W, N_bombs= map(int, input().strip().split() )

    H_N_bomb = [ [0, i]  for i in range(H) ]
    W_N_bomb = [ [0, i]  for i in range(W) ]
    bombs = [ [0]*W for _ in range(H)  ]


    for i in range(N_bombs):
        y, x = map(int, input().strip().split() )

        W_N_bomb[x-1][0] += 1
        H_N_bomb[y-1][0] += 1
        bombs[y-1][x-1] = 1


    W_N_bomb.sort(key = lambda x: x[0])
    H_N_bomb.sort(key = lambda x: x[0])



    Ws = [0] * W
    Hs = [0] * H
    for i in range(W):
        Ws[i] = W_N_bomb[i][0]
    for i in range(H):
        Hs[i] = H_N_bomb[i][0]

    pos_x= bisect.bisect_left(Ws, Ws[-1])
    pos_y= bisect.bisect_left(Hs, Hs[-1])
    #print(W_N_bomb, H_N_bomb, pos_x, pos_y)
    flag = False
    value = Ws[i] + Hs[j]
    for i in range(pos_x, W):
        for j in range(pos_y, H):
            pos_i = W_N_bomb[i][1]
            pos_j = H_N_bomb[j][1]
            if(bombs[pos_j][pos_i]==0):
                flag=True
                break
    if(flag==True):
        print(value)
    else:
        print(value-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

h = [0] * W
w = [0] * H
Mem = []
for _ in range(M):
  i, j = map(int, input().split())
  Mem.append((i, j))
  h[i-1] += 1
  w[j-1] += 1

h_idx = h.index(max(h))
w_idx = w.index(max(w))

ans = max(h) + max(w)
if (h_idx + 1, w_idx + 1) in Mem:
  ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
#import random

def putmx(lis):
  ret=[]
  mx=max(lis)
  for i in range(len(lis)):
    if mx==lis[i]:
      ret.append(i)
  return ret
  

h,w,m=map(int,input().split())
#inp=[(random.randrange(1,h+1),random.randrange(1,w+1)) for i in range(m)]
hb=[0]*h
wb=[0]*w
bmb=[]
for i in range(h):
  bmb.append({-1})
for i in range(m):
  hh,ww=map(int,input().split())
  hh-=1
  ww-=1
  bmb[hh].add(ww)
  hb[hh]+=1
  wb[ww]+=1

#hmx=[i for i, x in enumerate(hb) if x == max(hb)]
#wmx=[i for i, x in enumerate(wb) if x == max(wb)]
hmx=putmx(hb)
wmx=putmx(wb)
mhb=max(hb)
mwb=max(wb)
#print(hb,wb,hmx,wmx)
if len(hmx)>len(wmx):
  ll=set(wmx)
  bl=hmx
else:
  ll=set(hmx)
  bl=wmx
fl=False
for i in bl:
  if len(bmb[i]&ll)>0:
      print(mhb+mwb-1)
      fl=True
      break
  if fl:
    break
else:
  print(mhb+mwb)

Submission status: Runtime Error

Solution code:
import collections

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

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

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

h_count = collections.Counter(h)
w_count = collections.Counter(w)

h_count_max = collection.most_common()[1]
w_count_max = collection.most_common()[1]

max = 0
for i in range(1, H + 1):
    if (h_count[i] != h_count_max):
        continue

    for j in range(1, W + 1):
        if (w_count[j] != w_count_max):
            continue

        count = h_count[i] + w_count[j]

        if ((i, j) in point):
            count = count - 1

        if (count > max):
            max = count

print(max)

Submission status: Runtime Error

Solution code:
import numpy as np

[H, W, M] = map(int, input().split())
mp = np.zeros((H+1, W+1), dtype=np.int64)
for i in range(M):
    [h, w] = map(int, input().split())
    mp[h][w] = 1

colsum = np.sum(mp, axis=0)
rowsum = np.sum(mp, axis=1)

maxcol = max(colsum)
maxrow = max(rowsum)

colchk = np.where(colsum==maxcol)
rowchk = np.where(rowsum==maxrow)

for i in range(len(rowchk[0])):
    for j in range(len(colchk[0])):
        if mp[rowchk[0][i]][colchk[0][j]] == 0:
            print(int(max(colsum)+max(rowsum)))
            quit()

print(int(max(colsum)+max(rowsum))-1)

Submission status: Runtime Error

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)

set_list=[]
for H in max_h_li:
  for W in max_w_li:
    set_list.append([H,W])

set_list=[str(pair) for pair in set_list]
hw_grid=[str(pair) for pair in hw_grid]

#print("set_list",set_list)
#print("hw_grid",hw_grid)

#print("set(set_list)-set(hw_grid)",list(set(set_list)-set(hw_grid)))

if len((set(set_list)-set(hw_grid)) !=0:
  print(max(h_obj)+max(w_obj))
else:
  print(max(h_obj)+max(w_obj)-1)

Submission status: Runtime Error

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

bom=[[0 for i in range(w+1)] for i in range(h+1)]

for i in range(m):
  h,w=list(map(int,input().split()))
  bom[h][w]=1


from itertools import accumulate
for i in range(h+2):
  bom[i]=list(accumulate(bom[i]))


for i in range(1,h+2):
  for j in range(w+1):
    bom[i][j]=bom[i][j]+bom[i-1][j]

ans=0  
for i in range(1,h+2):
  for j in range(1,w+1):
    ans=max(ans,bom[h][w]-(bom[i-1][j-1]+bom[i-1][w]-bom[i-1][j]+bom[h][j-1]-bom[i][j-1]+bom[h][w]-bom[i][w]-bom[h][j]+bom[i][j]))
print(ans)

Submission status: Runtime Error

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

ListH = [0 for i in range(H)]
ListW = [0 for i in range(W)]

for m in range(M):
  h,w = map(int,input().split())
  ListH[h] = ListH[h] + 1
  ListM[M] = ListH[M] + 1

maxcount = 0  
tmpcount = 0  

for pi in range(0,H-1):
  for pj in range(0,W-1):
    tmpcount =  ListH[pi] + ListM[pj]
    
    if maxcount < tmpcount:
      maxcount = tmpcount
print(maxcount)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h_t = [0]*H
w_t = [0]*W
t = np.zeros((300000, 300000))
for i in range(M):
    h, w = map(int, input().split())
    t[h-1][w-1] = 1
    h_t[h-1]+=1
    w_t[w-1]+=1
h_max = max(h_t)
h_max_list = [i for i in range(len(h_t)) if h_t[i] == h_max]
w_max = max(w_t)
w_max_list = [i for i in range(len(w_t)) if w_t[i] == w_max]

for h in h_max_list:
    for w in w_max_list:
        if t[h][w] == 0:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)

Submission status: Runtime Error

Solution code:
import numpy as np

H,W,M = map(int,input().split())
G = np.array([[0 for i in range(W)] for j in range(H)])
for i in range(M):
    h,w = map(int,input().split())
    G[h-1][w-1] = 1

h_max = 0
for i in range(H):
    if sum(G[i]) > h_max:
        h_max = sum(G[i])
        y = i

G = G.T
w_max = 0
for j in range(W):
    if sum(G[j]) > w_max + G[y][j]:
        x = j
        w_max = sum(G[j]) - G[y][j]

print(h_max + w_max)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

H, W, M = [int(x) for x in input().split()]
init = np.zeros((H,W))

#print(init)
for i in range(M):
  x, y = [int(x)-1 for x in input().split()]
  init[x,y] = 1

#print(init)

row = np.sum(init, axis=1)
col = np.sum(init, axis=0)

max_H = np.where(row == row.max())[0]
max_W = np.where(col == col.max())[0]

before_point = 0
max_point = 0

if len(max_H) > 1 or len(max_W) > 1:
  for h in max_H:
    for w in max_W:
      point = row[h] + col[w]
      if init[h,w] == 0:
        pass
      else:
        point -= 1
      if point > before_point:
        max_point = point
      before_point = point

print(int(max_point))

Submission status: Runtime Error

Solution code:
def LI():return list(map(int,input().split()))
h,w,m=LI()
S=[[0]*w for i in range(h)]
a=[0]*(h+50)
b=[0]*(w+50)
for i in range(m):
    h,w=LI()
    S[h-1][w-1]=1
    a[h-1]+=1
    b[w-1]+=1

mx=max(a)
my=max(b)
ind_x=[i for i,j in enumerate(a) if j==mx]
ind_y=[i for i,j in enumerate(b) if j==my]

ans=0
for x in ind_x:
    for y in ind_y:
        if S[x][y]==0:
            tmp=mx+my
            print(tmp)
            exit()
        else:
            tmp=mx+my-1

        ans=max(ans,tmp)
        
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input(split()))
if H==1 and W == 1:
  print(1)
  exit()
else:
  hwlist = []
  a = []
  b = []
  for h in range(H):
      a.append(0)
  for w in range(W):
      b.append(0)
  for m in range(M):
    append.list = (list(map(int, input().split())))
    hwlist.append(append_list)
    a[append_list[0]-1] += 1
    b[append_list[1]-1] += 1
  max_a = max(a)
  a_max_id = [i for i, v in enumerate(a) if v == max_a]
  max_b = max(b)
  b_max_id = [i for i, v in enumerate(b) if v == max_b]
  for i in range(len(a_max_id)):
    for j in range(len(a_max_id)):
      if not [a_max_id, b_max_id] in hwlist:
        print(max_a + max_b)
        exit()
  print(max_a + max_b - 1)

Submission status: Runtime Error

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

for i in range(M):
    h, w = map(int, input().split())
    hlst[h] += 1
    wlst[w] += 1
    hwlst.append([h,w])

h = max(hlst)
w = max(wlst)
hmax = [i for i in range(H+1) if hlst[i] == h]
wmax = [i for i in range(W+1) if wlst[i] == w]
ans = h + w -1


for i in hmax:
    for j in wmax:
        if [i, j]  not in hwlst:
            ans += 1
            break

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

for _ in range(M):
    h,w=map(int,input().split())
    map_[h-1,w-1]=1

y_score = np.sum(map_, axis=1)
x_score = np.sum(map_, axis=0)

y_arg = np.argmax(y_score)
y_args = np.where(y_score==y_score[y_arg])[0]
x_arg = np.argmax(x_score)
x_args = np.where(x_score==x_score[x_arg])[0]


def score(x, y):
    return sum(map_[:, x])+sum(map_[y,:])-map_[y,x]

max_score = 0
for x_arg in x_args:
    for y_arg in y_args:
        current_score = score(x_arg,y_arg)
        if max_score<current_score:
            max_score = current_score
print(int(max_score))

Submission status: Runtime Error

Solution code:
H, W, M = map(int, input().split())
bom = [[0]*W for _ in range(H)]
row = [0] * H
col = [0] * W

for _ in range(M):
    h, w = map(int, input().split())
    bom[h-1][w-1] += 1
    row[h-1] += 1
    col[w-1] += 1

max_row = max(row)
max_col = max(col)
ans = max_row + max_col - 1

max_ix_row = [i for i, v in enumerate(row) if v == max_row]
max_ix_col = [i for i, v in enumerate(col) if v == max_col]

flag = False
"""
for i in max_ix_row:
    for j in max_ix_col:
        if not bom[i][j]:
            ans += 1
            flag = True
            break
    
    if flag:
        break"""

print(ans)

Submission status: Runtime Error

Solution code:
import sys
H, W, M = map(int, input().split())
Hb = [0] * H
Wb = [0] * W
B = [[0] * W for _ in range(H)]
for _ in range(M):
    h, w = map(int, input().split())
    Hb[h - 1] += 1
    Wb[w - 1] += 1
    B[h - 1][w - 1] = 1
HB = max(Hb)
WB = max(Wb)
print(HB + WB)
BB = [0] * W
for i in range(H):
    if Hb[i] == HB:
        for j in range(W):
            if B[i][j] == 1:
                BB[j] = 1
for i in range(W):
    if Wb[i] == WB:
        if BB[i] == 0:
            print(HB + WB)
            sys.exit()
print(HB + WB - 1)

Submission status: Runtime Error

Solution code:
h, w, m = map(int, input().split(' '))
grid = {}

h_max = 0
w_max = 0
h_max_grid = '0'
w_max_grid = '0'

for i in range(m):
    hi, wi = input().split(' ')
    grid[(hi, wi)] = 1
    grid[(hi, '0')] = grid.get((hi, '0'), 0) + 1
    grid[('0', wi)] = grid.get(('0', wi), 0) + 1

    if h_max < grid[(hi,'0')]:
        h_max = grid[(hi,'0')]
        h_max_grid = hi

    if w_max < grid[('0',wi)]:
        w_max = grid[('0',wi)]
        w_max_grid = wi

    t = h_max + w_max - grid[(h_max_grid,w_max_grid)]
    grid[('0','0')] = t if grid.get(('0','0'), 0) < t else grid.get(('0','0'), 0)

print(grid[('0','0')])

Submission status: Runtime Error

Solution code:
from collections import Counter

pas = 0

H, W, M = map(int, input().split())
hn = []
wn = []
tli = []
for _ in range(M):
    h, w = map(int, input().split())
    tli.append([h,w])
    hn.append(h)
    wn.append(w)

hcnt = Counter(hn)
wcnt = Counter(wn)

ha, cha = zip(*hcnt.most_common())
wa, cwa = zip(*wcnt.most_common())

hli = [int(ha[0])]
wli = [int(wa[0])]
for i in range(len(cha)-1):
    if cha[i] == cha[i+1]:
        hli.append(int(ha[i+1]))
    else:
        break
for i in range(len(wha)-1):
    if cwa[i] == cwa[i+1]:
        wli.append(int(wa[i+1]))
    else:
        break

for i in range(len(hli)):
    if pas == 1:
        break
    for k in range(len(wli)):
        if [hli[i], wli[k]] not in tli:
            ans = cha[i] + cwa[k]
            pas = 1
            break

if pas == 0:
    print(cha[0] + cwa[0] - 1)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

H, W, M = map(int, input().split())
h_t = [0]*300000
w_t = [0]*300000
t = np.zeros((H, W))
for i in range(M):
    h, w = map(int, input().split())
    t[h-1][w-1] = 1
    h_t[h-1]+=1
    w_t[w-1]+=1
h_max = max(h_t)
h_max_list = [i for i in range(len(h_t)) if h_t[i] == h_max]
w_max = max(w_t)
w_max_list = [i for i in range(len(w_t)) if w_t[i] == w_max]

for h in h_max_list:
    for w in w_max_list:
        if t[h][w] == 0:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin
H , W ,M= map(int , input().split())
count = np.zeros((H,W))
x_y = [list(map(int, stdin.readline().split())) for _ in range(M)]
for i in range(M):
  count[x_y[i][0]-1,:] +=1
  count[:,x_y[i][1]-1] +=1
  count[x_y[i][0]-1,x_y[i][1]-1]-=1
  
  
print(int(np.max(count)))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
H, W, M = map(int, input().split())
d = [[0]*H for _ in range(W)]
d = np.array(d)
for _ in range(M):
    h, w = map(int, input().split())
    d[h-1, w-1] = 1


tate = np.sum(d, axis=0)
yoko = np.sum(d, axis=1)
tate_max = tate.max()
yoko_max = yoko.max()

ans_tate, ans_yoko = [], []

for i in range(W):
    if tate[i] == tate_max:
        ans_tate.append(i)

for i in range(H):
    if yoko[i] == yoko_max:
        ans_yoko.append(i)

for h in ans_yoko:
    for w in ans_tate:
        if not d[h, w]:
            print(tate_max+yoko_max)
            sys.exit()
print(tate_max+yoko_max-1)