TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given are integers a,b,c and d. If x and y are integers and a \leq x \leq b and c\leq y \leq d hold, what is the maximum possible value of x \times y?

Submission attempts (in order):
a = list(map(int,input().split()))

tmp = a[2]
flag = True
flag2 = True
result = []

if a[0] < 10 ** 5 and a[2] < 10 ** 5 and a[1] < 10 ** 5 and a[3] < 10 ** 5:
  print(a[0] * a[2])
  exit(0)

while flag:
  flag2 = True
  if a[0] < a[1]:
    while flag2:
      result.append(a[0] * tmp)
      if tmp == a[3]:
        flag2 = False
        a[0] += 1
        tmp = a[2]
      else:
        tmp += 1
  else:
    flag = False

print(max(result))

a = list(map(int,input().split()))

result =[]
result.append(a[0] * a[2])
result.append(a[0] * a[3])
result.append(a[1] * a[2])
result.append(a[1] * a[3])
print(max(result))



Verdicts: Wrong Answer

Accepted
Problem: Given are integers a,b,c and d. If x and y are integers and a \leq x \leq b and c\leq y \leq d hold, what is the maximum possible value of x \times y?

Submission attempts (in order):
a,b,c,d = map(int,input().split())
l = [a*c,a*d,b*c,b*d]
max(l)

a,b,c,d = map(int,input().split())
l = [a*c,a*d,b*c,b*d]
print(max(l))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
H, W, M = map(int, input().split())
hsum = [0 for i in range(H)]
wsum = [0 for i in range(W)]
s = set()
for i in range(M):
    h, w = map(int, input().split())
    h, w = h-1, w-1
    s.add((h, w))
    hsum[h] += 1
    wsum[w] += 1
if (hsum.index(max(hsum)), wsum.index(max(wsum))) in s:
    print(max(hsum) + max(wsum) - 1)
else:
    print(max(hsum) + max(wsum))

import sys
from itertools import product
H, W, M = map(int, input().split())
hsum = [0 for i in range(H)]
wsum = [0 for i in range(W)]
s = set()
for i in range(M):
    h, w = map(int, input().split())
    h, w = h-1, w-1
    s.add((h, w))
    hsum[h] += 1
    wsum[w] += 1

hmax = max(hsum)
wmax = max(wsum)

hmax_index = []
for i in range(H):
    if hsum[i] == hmax:
        hmax_index.append(i)
wmax_index = []
for i in range(W):
    if wsum[i] == wmax:
        wmax_index.append(i)

for x in hmax_index:
    for y in wmax_index:
        if (x, y) not in s:
            print(hmax+wmax)
            sys.exit()
print(hmax+wmax-1)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

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

h_sum = [0] * H
w_sum = [0] * W


import numpy as np

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

h_sum = [0] * H
w_sum = [0] * W

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

h_max = max(h_sum)
w_max = max(w_sum)

h_argmax = set()
w_argmax = set()

for i, h in enumerate(h_sum):
    if h == h_max:
        h_argmax.add(i) 

for i, w in enumerate(w_sum):
    if w == w_max:
        w_argmax.add(i)

ans = h_max + w_max

for h in h_argmax:
    for w in w_argmax:
        if map_[h, w] == 0:
            print(ans)
            exit()
print(ans - 1)


# import numpy as np

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

map_ = [[0] * W for _ in range(H)]

h_sum = [0] * H
w_sum = [0] * W

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

h_max = max(h_sum)
w_max = max(w_sum)

h_argmax = set()
w_argmax = set()

for i, h in enumerate(h_sum):
    if h == h_max:
        h_argmax.add(i) 

for i, w in enumerate(w_sum):
    if w == w_max:
        w_argmax.add(i)

ans = h_max + w_max

for h in h_argmax:
    for w in w_argmax:
        if map_[h, w] == 0:
            print(ans)
            exit()
print(ans - 1)

# import numpy as np

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


h_sum = [0] * H
w_sum = [0] * W
point_list = set()

for _ in range(M):
    h, w = map(int, input().split())
    # map_[h-1, w-1] = 1
    point_list.add((h-1, w-1))
    h_sum[h-1] += 1
    w_sum[w-1] += 1

h_max = max(h_sum)
w_max = max(w_sum)

h_argmax = set()
w_argmax = set()

for i, h in enumerate(h_sum):
    if h == h_max:
        h_argmax.add(i) 

for i, w in enumerate(w_sum):
    if w == w_max:
        w_argmax.add(i)

ans = h_max + w_max

for h in h_argmax:
    for w in w_argmax:
        if (h, w) not in point_list:
        # if map_[h, w] == 0:
            print(ans)
            exit()
print(ans - 1)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
H, W, M = map(int, input().split())

targets = []
n_target_h = [0] * H
n_target_w = [0] * W

for i in range(M):
    h, w = map(int, input().split())
    targets.append((h, w))
    n_target_h[h - 1] += 1
    n_target_w[w - 1] += 1
    h_max = max(h_max, n_target_h[h - 1])
    w_max = max(w_max, n_target_w[w - 1])

bomb_h = [i + 1 for i, h in enumerate(n_target_h) if h == h_max]
bomb_w = [i + 1 for i, w in enumerate(n_target_w) if w == w_max]

ans = h_max + w_max - 1
for h in bomb_h:
    for w in bomb_w:
        if not (h, w) in targets:
            ans = h_max + w_max
            break
    else:
        continue
    break

print(ans)

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

targets = []
n_target_h = [0] * H
n_target_w = [0] * W

for i in range(M):
    h, w = map(int, input().split())
    targets.append((h, w))
    n_target_h[h - 1] += 1
    n_target_w[w - 1] += 1

h_max = max(n_target_h)
w_max = max(n_target_w)

bomb_h = [i + 1 for i, h in enumerate(n_target_h) if h == h_max]
bomb_w = [i + 1 for i, w in enumerate(n_target_w) if w == w_max]

count = len(bomb_h) * len(bomb_w)
for target in targets:
    if (n_target_h[target[0] - 1] == h_max) and (n_target_w[target[1] - 1] == w_max):
        count -= 1

if count > 0:
    ans = h_max + w_max
else:
    ans = h_max + w_max - 1

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * 2 for i in range(M)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[i] = [hi-1, wi-1]

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

tmp = M
for i in range(M):
    if (DST[i][0] not in Hbomb) or (DST[i][1] not in Wbomb):
        tmp -= 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax)
else:
    print(Hdstmax + Wdstmax - 1)


H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * 2 for i in range(M)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[i] = [hi-1, wi-1]

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]


if len(Hbomb)*len(Wbomb) == M:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)


H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

Hchk = [False]*H
Wchk = [False]*W
for i in Hbomb:
    Hchk[i] = True
for i in Wbomb:
    Wchk[i] = True

tmp = 0
for i in range(M):
    if Hchk[DST[0][i]] and Wchk[DST[1][i]]:
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))
 
maxh=max(sumh)
maxw=max(sumw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==len(qh)*len(qw):
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

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

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict

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

y_to_num = defaultdict(int)
x_to_num = defaultdict(int)

y_indexes = set()
x_indexes = set()

for _ in range(m):
    h, w = map(lambda x: int(x), input().split())
    y_to_num[h] += 1
    x_to_num[w] += 1
    
    y_indexes.add(h)
    x_indexes.add(w)
    
# print(y_to_num, x_to_num)
    
# for y, num_y in y_to_num:
#     for x, num_x in x_to_num:

max_num = 0
  
for y in range(h):
    for x in range(w):
        num = y_to_num[y+1] + x_to_num[x+1]
        if (y+1 in y_indexes) & (x+1 in x_indexes):
            num -= 1
        max_num = max(max_num, num)
        
print(max_num)

from collections import defaultdict
import sys

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

y_to_num = [0] * h
x_to_num = [0] * w
existing_h_to_w = defaultdict(set)


for _ in range(m):
    hh, ww = map(lambda x: int(x), input().split())
    y_to_num[hh-1] += 1
    x_to_num[ww-1] += 1
    existing_h_to_w[hh-1].add(ww-1)

max_vertical_num = max(y_to_num)
max_horizontal_num = max(x_to_num)

y_coor_with_max_num = [i for i, num in enumerate(y_to_num) if num == max_vertical_num]
x_coor_with_max_num = [i for i, num in enumerate(x_to_num) if num == max_horizontal_num]

# print(y_coor_with_max_num, x_coor_with_max_num, existing_h_to_w)

for y in y_coor_with_max_num:
    for x in x_coor_with_max_num:
        if x not in existing_h_to_w[y]:
            print(max_vertical_num + max_horizontal_num)
            sys.exit()

print(max_vertical_num + max_horizontal_num - 1)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
h,w,m = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
bomb = set()
h_list = [0] * (h+1)
w_list = [0] * (w+1)
for H,W in hw:
  h_list[H] += 1
  w_list[W] += 1
  bomb.add((H,W))
max_h = max(h_list)
max_w = max(w_list)
maxh_list = []
maxw_list = []
for k,v in enumerate(h_list):
  if v == max_h:
    maxh_list.append(k)
for k,v in enumerate(w_list):
  if v == max_w:
    maxw_list.append(k)
if len(maxh_list) * len(maxv_list) > m:
  ans = max_h * max_w
else:
  ans = max_h * max_w - 1
  for i in maxh_list:
    for j in maxw_list:
      if (i,j) not in bomb:
        ans = max_h * max_w
        break
print(ans)
      

h,w,m = map(int, input().split())
hw = [list(map(int, input().split())) for i in range(m)]
bomb = set()
h_list = [0] * (h+1)
w_list = [0] * (w+1)
for H,W in hw:
  h_list[H] += 1
  w_list[W] += 1
  bomb.add((H,W))
max_h = max(h_list)
max_w = max(w_list)
maxh_list = []
maxw_list = []
for k,v in enumerate(h_list):
  if v == max_h:
    maxh_list.append(k)
for k,v in enumerate(w_list):
  if v == max_w:
    maxw_list.append(k)
if len(maxh_list) * len(maxw_list) > m:
  ans = max_h + max_w
else:
  ans = max_h + max_w - 1
  for i in maxh_list:
    for j in maxw_list:
      if (i,j) not in bomb:
        ans = max_h + max_w
        break
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

import sys
from collections import defaultdict
import numpy as np
input = sys.stdin.readline  
H,W,M = map(int, input().split())
bomb =np.zeros(H+1,W+1)
posision =defaultdict(int)

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

index =np.unravel_index(np.argmax(bomb), bomb.shape)
bom_max =np.max(bomb)
ans =0
if posision[index] ==1:
    ans =bom_max -1
else:
    ans =bom_max
print(ans)



import sys
from collections import defaultdict
input = sys.stdin.readline  
H,W,M = map(int, input().split())

bom_H =defaultdict(int)
bom_W =defaultdict(int)
posision =set()
for i in range(M):
    h,w = map(int, input().split())
    bom_H[h] +=1
    bom_W[w] +=1
    posision.add((h,w))
temp_H =max(bom_H.values())
temp_W =max(bom_W.values())
indx_H = [k for k,v in bom_H.items() if v == temp_H]
indx_W = [k for k,v in bom_W.items() if v == temp_W]
set_max_H = set(indx_H)
set_max_W = set(indx_W)


flag =False
for h in set_max_H:
    for w in set_max_W:
        if (h,w) not in posision:
            flag =True
            break
    if flag==True:
        break

if flag ==True:
    print(temp_H +temp_W )
else:
    print(temp_H +temp_W -1)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import collections

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


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


if __name__ == "__main__":
    main()


import sys
import collections

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


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


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def main():
    h, w, m, *BOM = map(int, open(0).read().split())
    row = [0] * h
    col = [0] * w
    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        row[i] += 1
        col[j] += 1

    p, q = max(row), max(col)
    rr = {i for i in range(h) if row[i] == p}
    rl = {i for i in range(w) if col[i] == q}

    ans = p + q
    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        if (row[i], col[j]) == (p, q) and not (i in rr and j in rl):
            break
    else:
        ans -= 1

    print(ans)


if __name__ == '__main__':
    main()


def main():
    h, w, m, *BOM = map(int, open(0).read().split())
    row = [0] * h
    col = [0] * w
    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        row[i] += 1
        col[j] += 1

    p, q = max(row), max(col)
    rr = sum(1 for i in range(h) if row[i] == p)
    rl = sum(1 for i in range(w) if col[i] == q)

    cnd = rr * rl

    for i, j in zip(BOM[::2], BOM[1::2]):
        i -= 1
        j -= 1
        if (row[i], col[j]) == (p, q):
            cnd -= 1

    if cnd > 0:
        ans = p + q
    else:
        ans = p + q - 1

    print(ans)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):



def LI():
    return list(map(int,input().split()))
    
def OPEN():
    return map(int,open(0).read().split())
import numpy   
h,w,m=LI()
S=[[0]*w for i in range(h)]
for i in range(m):
    h,w=LI()
    S[h-1][w-1]=1
S=numpy.array(S)
now=0
ind_x=[]
ind_y=[]
Ssumx=[sum(i) for i in S]
SS=S.T
Ssumy=[sum(i) for i in SS]



mx=max(Ssumx)
for i,j in enumerate(Ssumx):
    if j==mx:
        ind_x.append((i,j))
my=max(Ssumy)
for i,j in enumerate(Ssumy):
    if j==my:
        ind_y.append((i,j))
        
        

from collections import*
h,w,m=map(int,input().split())
d=defaultdict(int)
a=[0]*h
b=[0]*w
for _ in range(m):
  x,y=map(int,input().split())
  x-=1
  y-=1
  a[x]+=1
  b[y]+=1
  d[(x,y)]+=1

ma=max(a)
mb=max(b)

ind_x=[i for i,j in enumerate(a) if j==ma]
ind_y=[i for i,j in enumerate(b) if j==mb]


for x in ind_x:
  for y in ind_y:
    if d[(x,y)]==0:
      print(ma+mb)
      exit()
print(ma+mb-1)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
h, w, m = map(int, input().split())
lsh = [0] * h
lsw = [0] * w
for _ in range(m):
    m1, m2 = map(int, input().split())
    lsh[m1 - 1] += 1
    lsw[m2 - 1] += 1

print(max(lsh) + max(lsw) -1)

def main():
    h, w, m = map(int, input().split())
    lsh = [0] * h
    lsw = [0] * w

    bom = set()
    for _ in range(m):
        m1, m2 = map(int, input().split())
        lsh[m1 - 1] += 1
        lsw[m2 - 1] += 1
        bom.add((m1-1, m2-1))

    lshmax = max(lsh)
    lswmax = max(lsw)

    hin = [i for i in range(h) if lsh[i] == lshmax]
    win = [i for i in range(w) if lsw[i] == lswmax]

    for i in hin:
        for j in win:
            if (i, j) not in bom:
                print(lshmax + lswmax)
                exit(0)
    else:
        print(lshmax + lswmax -1)


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
h,w,m=map(int,input().split())
bomb=[list(map(int,input().split())) for i in range(m)]

num_h = [0] * (h+1)
num_w = [0] * (w+1)
for hi,wi in bomb:
  num_h[hi] += 1
  num_w[wi] += 1
  
max_hs = [k for k,v in enumerate(num_h) if v == max(num_h)]
max_ws = [k for k,v in enumerate(num_w) if v == max(num_w)]

result = max(num_h) + max(num_w)
for i in max_hs:
  for j in max_ws:
    if [i,j] in bomb:
      result -= 1
      print(result)
      exit(0)
print(result)

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

num_h = [0] * (h+1)
num_w = [0] * (w+1)
bomb_set = set()
for hi,wi in bomb:
  num_h[hi] += 1
  num_w[wi] += 1
  bomb_set.add((hi,wi))
  
max_h = max(num_h)
max_w = max(num_w)
max_hs = [k for k,v in enumerate(num_h) if v == max_h]
max_ws = [k for k,v in enumerate(num_w) if v == max_w]

result = max_h + max_w
for i in max_hs:
  for j in max_ws:
    if (i,j) not in bomb_set:
      print(result)
      exit(0)
print(result-1)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W
S = set()
for _ in range(M):
    h, w = map(int,input().split())
    S.add((h-1, w-1))
for i in range(M):
    h, w = S[i]
    R[h] += 1
    C[w] += 1

r = max(R)
c = max(C)

for h in [i for i in range(H) if R[i] == r]:
    for w in [i for i in range(W) if C[i] == c]:
        if not (h, w) in S:
            print(r + c)
            sys.exit()

print(r + c - 1)

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W

L = []

for _ in range(M):
    h, w = map(int,input().split())
    R[h-1] += 1
    C[w-1] += 1
    L.append([h-1, w-1])

r = max(R)
c = max(C)

print(r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L))

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W

L = []

for _ in range(M):
    h, w = map(int,input().split())
    R[h-1] += 1
    C[w-1] += 1
    L.append([h-1, w-1])

r = max(R)
c = max(C)

print(r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L)))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    row = [0] * H
    column = [0] * W
    grid = [[0] * W for _ in range(H)]

    for _ in range(M):
        h, w = map(int, readline().split())
        row[h-1] += 1
        column[w-1] += 1
        grid[h-1][w-1] += 1

    max_row = [i for i,x in enumerate(row) if x == max(row)]
    max_column = [i for i,x in enumerate(column) if x == max(column)]
    ans = 0
    for h in max_row:
        for w in max_column:
            tmp = row[h] + column[w] - grid[h][w]
            ans = max(tmp,ans)
    print(tmp)

if __name__ == '__main__':
    main()


import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, M = map(int, readline().split())
    row = [0] * H
    column = [0] * W
    grid = set()

    for _ in range(M):
        h, w = map(int, readline().split())
        row[h-1] += 1
        column[w-1] += 1
        grid.add((h-1,w-1))

    max_row = max(row)
    max_column = max(column)

    idx_row = [i for i,x in enumerate(row) if x == max_row]
    idx_column = [i for i,x in enumerate(column) if x == max_column]

    ans = max_row+max_column
    flag = False

    for h in idx_row:
        for w in idx_column:
            if not (h,w) in grid:
                flag = True
                break

    if flag:
        print(ans)
    else:
        print(ans-1)


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
h, w, m = map(int, input().split())
h_list = [0] * h
w_list = [0] * w
lw = []
for i in range(m):
    h_tmp, w_tmp = map(int, input().split())
    h_list[h_tmp - 1] += 1
    w_list[w_tmp - 1] += 1
    lw.append(w_tmp)
mh = max(h_list)
id = h_list.index(mh)
mw = max(w_list)
# print(id)
if id+1 in lw:
    print(mh + mw - 1)
else:
    print(mh + mw)

h, w, m = map(int, input().split())
h_list = [0] * h
w_list = [0] * w
bomb = []
for i in range(m):
    h_tmp, w_tmp = map(int, input().split())
    h_list[h_tmp - 1] += 1
    w_list[w_tmp - 1] += 1
    bomb.append((h_tmp - 1, w_tmp - 1))
bomb = set(bomb)
mh = max(h_list)
id_h = []
for i, n in enumerate(h_list):
    if n == mh:
        id_h.append(i)

mw = max(w_list)
id_w = []
for i, n in enumerate(w_list):
    if n == mw:
        id_w.append(i)

for i in id_h:
    for j in id_w:
        if not (i, j) in bomb:
            print(mh + mw)
            exit()

print(mh + mw - 1)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections
H,W,M=map(int,input().split())
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=map(int,input().split())
c1=collections.Counter(h)
c2=collections.Counter(w)
for x in range(M):
    flag=True
    if h[x]==c1.most_common()[i][0] and w[x]==c2.most_common()[j][0]:
        print(c1.most_common()[i][1]+c2.most_common()[j][1]-1)
        exit()
print(c1.most_common()[i][1]+c2.most_common()[j][1])

import collections
H,W,M=map(int,input().split())
h=[None]*M
w=[None]*M
for i in range(M):
    h[i],w[i]=map(int,input().split())
c1=collections.Counter(h)
c2=collections.Counter(w)
ans=0
cnt=0
while cnt<len(c1)-1:
    cnt2=0
    while cnt2<len(c2)-1:
        flag=True
        for x in range(M):
            if h[x]==c1.most_common()[cnt][0] and w[x]==c2.most_common()[cnt2][0]:
                ans=max((ans,c1.most_common()[cnt][1]+c2.most_common()[cnt2][1]-1))
                flag=False
                break
        if flag:
            ans=max((ans,c1.most_common()[cnt][1]+c2.most_common()[cnt2][1]-1))
        if c2.most_common()[cnt][0]>c2.most_common()[cnt+1][0]:
            break
        cnt2+=1
    if c1.most_common()[cnt][0]>c1.most_common()[cnt+1][0]:
        break
    cnt+=1
print(ans)

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M = map(int, readline().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in readlines()]
X = [0] * H 
Y = [0] * W 
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = [h for h, x in enumerate(X) if x == maxX]  
C = [w for w, y in enumerate(Y) if y == maxY] 

bomb = set(bomb)
for r in R:
    for c in C:
        if (r, c) not in bomb:
            print(maxX + maxY)
            exit()
print(maxX + maxY - 1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
########### E
H, W, M = map(int, input().split())
bombs = []
for _ in range(M):
    bomb = list(map(int, input().split()))
    bombs.append(bomb)

H_list = [0]*H
W_list = [0]*W
sign = True
for i in range(M):
    H_list[bombs[i][0]-1] += 1
    W_list[bombs[i][1]-1] += 1

max_H = [i for i,k in enumerate(H_list) if k == max(H_list)]
max_W = [i for i,k in enumerate(W_list) if k == max(W_list)]

cross = []

for i in max_H:
    for k in max_W:
        if [i+1,k+1] not in bombs:
            sign = False
            print(max(H_list) + max(W_list))
            break
    break

if sign:

########### E
H, W, M = map(int, input().split())
bombs = []
for _ in range(M):
    bomb = tuple(map(lambda x:int(x)-1, input().split()))
    bombs.append(bomb)

H_list = [0]*H
W_list = [0]*W
for h,w in bombs:
    H_list[h] += 1
    W_list[w] += 1
    
maxX = max(H_list)
maxY = max(W_list)

max_H = [i for i,k in enumerate(H_list) if k == maxX]
max_W = [i for i,k in enumerate(W_list) if k == maxY]

bombs = set(bombs)
for i in max_H:
    for k in max_W:
        if (i,k) not in bombs:
            print(maxX + maxY)
            exit()

print(maxX + maxY -1)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys


def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = [0] * H
    target_w = [0] * W
    for h, w in targets:
        target_h[h - 1] += 1
        target_w[w - 1] += 1

    ans = 0
    for h, w in targets:
        ans = max(ans, target_h[h - 1] + target_w[w - 1] - 1)
    
    return ans

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


import sys
import itertools


def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = {}
    target_w = {}
    target_hw = set()
    for h, w in targets:
        target_h[h] = target_h.setdefault(h, 0) + 1
        target_w[w] = target_w.setdefault(w, 0) + 1
        target_hw.add((h, w))

    max_h = max(target_h.values())
    max_w = max(target_w.values())

    h_set = {h for h, v in target_h.items() if max_h == v}
    w_set = {w for w, v in target_w.items() if max_w == v}

    ans = max_h + max_w - 1
    for hw in itertools.product(h_set, w_set):
        if hw not in target_hw:
            ans += 1
            break
    
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
H, W, M = map(int, input().split())
targets = [list(map(int, input().split())) for _ in range(M)]
x_counter = [0 for _ in range(W + 1)]
y_counter = [0 for _ in range(H + 1)]
y_index = []
x_index = []
dup = True

for target in targets:
    y_counter[target[0]] += 1
    x_counter[target[1]] += 1

y_max, x_max = max(y_counter), max(x_counter)

for i in range(H + 1):
    if y_counter[i] == y_max:
        y_index.append(i)

for j in range(W + 1):
    if x_counter[j] == x_max:
        x_index.append(j)

for k in y_index:
    for l in x_index:
        if [k, l] not in targets:
            dup == False

if dup:
    print(y_max + x_max - 1)
else:
    print(y_max + x_max)


H, W, M = map(int, input().split())
targets = [list(map(int, input().split())) for _ in range(M)]
x_counter = [0 for _ in range(W + 1)]
y_counter = [0 for _ in range(H + 1)]
y_index = []
x_index = []
check = 0

for i in range(M):
    x, y = targets[i]
    y_counter[x] += 1
    x_counter[y] += 1

y_max, x_max = max(y_counter), max(x_counter)

for i in range(H + 1):
    if y_counter[i] == y_max:
        y_index.append(i)

for j in range(W + 1):
    if x_counter[j] == x_max:
        x_index.append(j)

y_index = set(y_index)
x_index = set(x_index)

check = len(y_index) * len(x_index)
for k in range(M):
    r, c = targets[k]
    if r in y_index and c in x_index:
        check -= 1

print(y_max + x_max if check > 0 else y_max + x_max -1)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
H,W,M = map(int,input().split())
HW = []
for i in range(M):
	HW.append(list(map(int,input().split())))


Hmax = 0
Hmax_temp = 0
y_max = []
for y in range(1,H+1):
	for j in HW:
		if y == j[0]:
			Hmax_temp += 1
	if Hmax_temp >= Hmax:
		Hmax = Hmax_temp
		y_max.append(y)
	Hmax_temp = 0


Wmax = 0
Wmax_temp = 0
x_max = []
for x in range(1,W+1):
	for j in HW:
		if x == j[1]:
			Wmax_temp += 1
	if Wmax_temp >= Wmax:
		Wmax = Wmax_temp
		x_max.append(x)
	Wmax_temp = 0


flag = False
for i in y_max:
	for  j in x_max:
		if [i,j] not in HW:
			flag = True
			break
	if flag:
		break


if flag:
	ans = Wmax + Hmax
elif :
	ans = Wmax + Hmax - 1
print(ans)



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

Hmax_temp = [0]*(H+1)
Wmax_temp = [0]*(W+1)
Hmax = 0
Wmax = 0
Bomb = dict()
for i in range(M):
	H_M,W_M = map(int,input().split())
	Hmax_temp[H_M] += 1
	Wmax_temp[W_M] += 1
	Bomb[(H_M,W_M)] = 1

Hmax = max(Hmax_temp)
Wmax = max(Wmax_temp)


y_max = []
for i in range(H+1):
	if Hmax == Hmax_temp[i]:
		y_max.append(i)
		

x_max = []
for j in range(W+1):
	if Wmax == Wmax_temp[j]:
		x_max.append(j)


flag = False
for i in y_max:
	for  j in x_max:
		if (i,j) not in Bomb:
			flag = True
			break
	if flag:
		break


if flag:
	ans = Wmax + Hmax
else:
	ans = Wmax + Hmax - 1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
H, W, M = list(map(int, input().split()))
HW = set()
hd = {}
wd = {}
for i in range(M):
	h, w = tuple(map(int, input().split()))
	HW.add((h, w))
	if h in hd:
		hd[h] += 1
	else:
		hd[h] = 1
	if w in wd:
		wd[w] += 1
	else:
		wd[w] = 1

hm = [kv[0] for kv in hd.items() if kv[1] == max(hd.values())]
wm = [kv[0] for kv in wd.items() if kv[1] == max(wd.values())]
ans = 0
for h in hm:
	for w in wm:
		if (h, w) in HW:
			ans = max(ans, (hd[h] + wd[w] + 1))
		else:
			ans = max(ans, (hd[h] + wd[w]))
print(ans)


H, W, M = list(map(int, input().split()))
HW = set(tuple(int(x) - 1 for x in input().split()) for _ in range(M))
h = [0] * H
w = [0] * W
for hi, wi in HW:
	h[hi] += 1
	w[wi] += 1
hm = max(h)
wm = max(w)

hh = [i for i, v in enumerate(h) if v == hm]
ww = [i for i, v in enumerate(w) if v == wm]

ans = hm + wm - 1
for h in hh:
	for w in ww:
		if (h, w) not in HW:
			ans += 1
			break 	
	else:
		continue
	break
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    
    bomb_pos = set()
    
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(bomb_row) if v == bomb_col_max]
    col_index = [i for i, v in enumerate(bomb_col) if v == bomb_row_max]
    ans = bomb_col_max + bomb_row_max
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

import sys
input = sys.stdin.readline

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    
    bomb_pos = set()
    
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split())]
        bomb_col[r] += 1
        bomb_row[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(col) if v == bomb_col_max]
    col_index = [i for i, v in enumerate(row) if v == bomb_row_max]
    ans = max(col) + max(row)
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

import sys
input = sys.stdin.readline

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    
    bomb_pos = set()
    
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(bomb_row) if v == bomb_row_max]
    col_index = [i for i, v in enumerate(bomb_col) if v == bomb_col_max]
    ans = bomb_col_max + bomb_row_max
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
H, W, M = map(int,input().split())

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

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

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

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

ans = False
for a, b in A:
    if not C[(a, b)]: ans = True

cnt = xm + ym         
print(cnt if ans else cnt - 1)

import sys

input = sys.stdin.readline
H, W, M = map(int,input().split())
q=set(tuple(map(lambda x :int(x)-1,input().split())) for _ in range(M))

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

for i, j in q:
    X[i] += 1
    Y[j] += 1
    
def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

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

ans = xm + ym - 1

bl = False
for i in xms:
    for j in yms:
        if not (i, j) in q:
            print(ans + 1)
            sys.exit()
            bl = True
            
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
h,w,m=map(int,input().split())
a=[0]*h
b=[0]*w
for i in range (m):
    x,y=map(int,input().split())
    a[x-1]+=1
    b[y-1]+=1
r1=max(a)
r2=max(b)
r=min(m,r1+r2)

h,w,m=map(int,input().split())
a=dict()
b=dict()
points=set()
for i in range (m):
    x,y=map(int,input().split())
    points.add((x,y))
    if x in a:
        a[x]+=1
    else:
        a[x]=1
    if y in b:
        b[y]+=1
    else:
        b[y]=1
m1=max(a.values())
m2=max(b.values())
s1=set()
s2=set()
for i in a:
    if a[i]==m1:
        s1.add(i)
for i in b:
    if b[i]==m2:
        s2.add(i)
r=set()
for i in points:
    if i[0] in s1 and i[1] in s2:
        r.add(i)
if len(r)==len(s1)*len(s2):
    print(m1*m2-1)
else:
    print(m1*m2)

h,w,m=map(int,input().split())
a=dict()
b=dict()
points=set()
for i in range (m):
    x,y=map(int,input().split())
    points.add((x,y))
    if x in a:
        a[x]+=1
    else:
        a[x]=1
    if y in b:
        b[y]+=1
    else:
        b[y]=1
m1=max(a.values())
m2=max(b.values())
s1=set()
s2=set()
for i in a:
    if a[i]==m1:
        s1.add(i)
for i in b:
    if b[i]==m2:
        s2.add(i)
r=set()
for i in points:
    if i[0] in s1 and i[1] in s2:
        r.add(i)
if len(r)==len(s1)*len(s2):
    print(m1+m2-1)
else:
    print(m1+m2)

Verdicts: Wrong Answer

Wrong Answer

Accepted