alexjercan/bugnet huggingface dataset:
Problem p02577 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-

# Input#
n = list(input())
# n, k = map(int, input().split())
# a = list(map(int, input().split()))
sum = 0
for i in n:
    sum += int(i)

if sum % 9 == 0:
    print("Yes")
else:
    print("No")


# print("{}".format(ans))


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-

# Input#
n = list(input())
# n, k = map(int, input().split())
# a = list(map(int, input().split()))

sum = 0
while len(n) > 1:
    sum += int(n.pop(0))


sum += int(n[0])
if sum % 9 == 0:
    print("Yes")
else:
    print("No")


# print("{}".format(ans))
Problem p02577 (Python) — buggy submission, verdict: Runtime Error

n = int(input())


def solve1(n: int) -> str:
    k = 0
    for i in range(len(n)):
        k += int(n[i])

    if k % 9 == 0:
        return "Yes"
    else:
        return "No"


def solve2(n: int) -> str:
    if n % 9 == 0:
        return "Yes"
    else:
        return "No"


print(solve2(n))


Error: TypeError: not all arguments converted during string formatting
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02577/Python/s983642794.py", line 22, in <module>
    solve2(n)
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02577/Python/s983642794.py", line 16, in solve2
    if n % 9 == 0:
TypeError: not all arguments converted during string formatting


Fixed submission:

n = input()


def solve1(n: int) -> str:
    k = 0
    for i in range(len(n)):
        k += int(n[i])

    if k % 9 == 0:
        return "Yes"
    else:
        return "No"


def solve2(n: int) -> str:
    if n % 9 == 0:
        return "Yes"
    else:
        return "No"


solve2(n)
Problem p02577 (Python) — buggy submission, verdict: Time Limit Exceeded

a = input()

a = int(a)

if a % 9 == 0:
    print("Yes")
else:
    print("No")


Error: TLE

Fixed submission:

a = input()

a = int(a)

b = a

b = int(b)

if a % 9 == 0:

    for i in range(a):
        b += b % pow(10, i)

else:
    print("No")
    exit()

if b % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02577 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
if N % 9 == 0:
    print("Yes")
else:
    print("No")


Error: TLE

Fixed submission:

N = int(input())
summer = 0

while N > 0:
    digit = N % 10
    summer += digit
    N = N // 10
if summer % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02577 (Python) — buggy submission, verdict: Time Limit Exceeded

N = input()

hantei = 0

for i in range(len(N)):
    hantei += int(N[i])

if hantei % 9 == 0:
    ans = "Yes"
else:
    ans = "No"

print(ans)


Error: TLE

Fixed submission:

N = int(input())

hantei = 0

while N != 0 or N < 1:
    hantei += N % 10
    N = N // 10

if hantei % 9 == 0:
    ans = "Yes"
else:
    ans = "No"

print(ans)
Problem p02578 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/usr/local/bin/python3
N = int(input())
A = list(map(int, input().split()))

m = ans = 0
for i in range(N):
    m = max(m, A[i])
    ans += m - A[i]

print(ans)


Error: TLE

Fixed submission:

#!/usr/local/bin/python3
N = int(input())
A = list(map(int, input().split()))[::-1]

ans = 0
while N != 0:
    m = max(A)
    idx = A.index(m) + 1
    ans += (len(A[:idx]) * m) - sum(A[:idx])
    A = A[idx:]
    N -= idx

print(ans)
Problem p02578 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))

res = 0
max_val = -1
for a in A:
    if a >= max_val:
        max_val = a
    else:
        res += max_val - a

print(res)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))

res = []
for i in range(len(A) - 1, 0, -1):
    val = A[i]
    max_val = -1
    for j in A[:i]:
        if max_val < j:
            max_val = j

    if max_val > val:
        res.append(max_val - val)
    else:
        res.append(0)

print(sum(res))
Problem p02580 (Python) — buggy submission, verdict: Runtime Error

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

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1

h_mx = max(h_cnt)
w_mx = max(w_cnt)

cnt = h_cnt.count(h_mx) * w_cnt.count(w_mx)
for h, w in hw:
    val = h_cnt[h] + w_cnt[w]
    if val == h_mx + w_mx:
        cnt -= 1

if cnt:
    ans = h_mx + w_mx
else:
    ans = h_mx + w_mx - 1

print(ans)


Error: 0

Fixed submission:

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

board = [[0] * (W + 1) for _ in range(H + 1)]

h_cnt = [0] * (H + 1)
w_cnt = [0] * (W + 1)

for h, w in hw:
    h_cnt[h] += 1
    w_cnt[w] += 1
    board[h][w] = 1

h_mx = max(h_cnt)
w_mx = max(w_cnt)

cnt = h_cnt.count(h_mx) * w_cnt.count(w_mx)
for h, w in hw:
    val = h_cnt[h] + w_cnt[w]
    if val == h_mx + w_mx:
        cnt -= 1

if cnt:
    ans = h_mx + w_mx
else:
    ans = h_mx + w_mx - 1

print(ans)
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys


def solve():
    readline = sys.stdin.readline
    H, W, M = map(int, readline().split())
    h = [0] * H
    w = [0] * W
    b = set()
    for _ in range(M):
        y, x = map(int, readline().split())
        x -= 1
        y -= 1
        h[y] += 1
        w[x] += 1
        b.add(y * W + x)
    h = sorted(zip(h, range(H)), reverse=True)
    ans = 0
    for i in range(W):
        x = w[i]
        for y, j in h:
            if x + y > ans:
                if j * W + i in b:
                    ans = x + y - 1
                else:
                    ans = x + y
                    break
            else:
                break
    print(ans)


if __name__ == "__main__":
    solve()


Error: TLE

Fixed submission:

from collections import defaultdict


def solve(H, M, W, bombs):
    count_h = defaultdict(int)
    count_w = defaultdict(int)
    for b in bombs:
        h = str(b[0])
        count_h[h] += 1
        w = str(b[1])
        count_w[w] += 1
    max_h = max(count_h.values())
    max_w = max(count_w.values())
    points_h = [int(k) for k in count_h.keys() if count_h[k] == max_h]
    points_w = [int(k) for k in count_w.keys() if count_w[k] == max_w]
    ans = max_h + max_w
    if _find_cross_bomb(points_h, points_w, bombs):
        ans -= 1
    print(ans)


def _find_cross_bomb(points_h, points_w, bombs):
    c = 0
    for b in bombs:
        if (b[0]) in points_h:
            if (b[1]) in points_w:
                c += 1
    return c == len(points_h) * len(points_w)


if __name__ == "__main__":
    H, W, M = map(int, input().split())
    bombs = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]
    solve(H, M, W, bombs)
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

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


max_h = max(sum_h)
max_w = max(sum_w)

new_H = [h for h in range(H) if sum_w[h] == max_w]
new_W = [w for w in range(W) if sum_h[w] == max_h]

max_num = max_h + max_w - 1
for i in new_H:
    for j in new_W:
        if (i + 1, j + 1) not in hw:
            print(max_h + max_w)
            exit()
        else:
            continue
        break

print(max_num)


Error: TLE

Fixed submission:

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


max_h = max(sum_h)
max_w = max(sum_w)

new_H = [h for h in range(H) if sum_w[h] == max_w]
new_W = [w for w in range(W) if sum_h[w] == max_h]

max_num = max_h + max_w - 1
for i in new_H:
    for j in new_W:
        if [i + 1, j + 1] not in hw:
            print(max_h + max_w)
            exit()
        else:
            continue
        break

print(max_num)
Problem p02580 (Python) — buggy submission, verdict: Runtime Error

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

B = [list(map(int, input().split())) for _ in range(M)]

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0] - 1] == row_max and bombs_col[b[1] - 1] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02580/Python/s510602402.py", line 25, in <module>
    if bombs_row[b[0]] == row_max and bombs_col[b[1]] == col_max:
IndexError: list index out of range


Fixed submission:

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

B = [list(map(int, input().split())) for _ in range(M)]

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0]] == row_max and bombs_col[b[1]] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.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 = []
C = []
for h, x in enumerate(X):
    if x == maxX:
        R.append(h)
for w, y in enumerate(Y):
    if y == maxY:
        C.append(w)

if len(R) * len(C) > M:
    ans = maxX + maxY
else:
    done = set()
    for r in R:
        for c in C:
            done.add((r, c))
    for b in bomb:
        if b in done:
            done.remove(b)
    if len(done) > 0:
        ans = maxX + maxY
    else:
        ans = maxX + maxY - 1
print(ans)


Error: TLE

Fixed submission:

import sys


H, W, M = map(int, input().split())
X = [set() for _ in range(H)]
Y = [set() for _ in range(W)]
for s in sys.stdin.readlines():
    h, w = map(lambda x: int(x) - 1, s.split())
    X[h].add(w)
    Y[w].add(h)
cntX = []
cntY = []
for x in X:
    cntX.append((len(x), x))
for w, y in enumerate(Y):
    cntY.append((len(y), w))

cntX.sort(reverse=True)
cntY.sort(reverse=True)
maxX = cntX[0][0]
maxY = cntY[0][0]
ans = 0
for cnt, x in cntX:
    if cnt < maxX:
        break
    for tmp, w in cntY:
        if tmp < maxY:
            break
        tmp += cnt - (w in x)
        if ans < tmp:
            ans = tmp
    if cnt == maxX + maxY:
        break
print(ans)
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H  # X:各行の爆破対象の個数
Y = [0] * W  # Y:各列の爆破対象の個数
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]  # R:爆破対象の数が最大となる行の番号
C = [w for w, y in enumerate(Y) if y == maxY]  # C:爆破対象の数が最大となる列の番号

bomb = set(bomb)
for r in R:
    for c in C:
        # (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため,
        # 即座に探索を終了する.
        if (r, c) not in bomb:
            print(maxX + maxY)
            exit()
print(maxX + maxY - 1)


Error: TLE

Fixed submission:

import sys

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

h_bom = [0] * H
w_bom = [0] * W

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

    h_bom[h[i] - 1] += 1
    w_bom[w[i] - 1] += 1

h_max = max(h_bom)
w_max = max(w_bom)

h_list = []
w_list = []

for i in range(len(h_bom)):
    if h_bom[i] == h_max:
        h_list.append(i)

for i in range(len(w_bom)):
    if w_bom[i] == w_max:
        w_list.append(i)

for y in h_list:
    for x in w_list:
        flag = True
        for i in range(M):
            if y == (h[i] - 1) and x == (w[i] - 1):
                flag = False

        if flag:
            print(h_max + w_max)
            sys.exit()

print(h_max + w_max - 1)
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    H, W, M = map(int, input().split())
    cnth = [[0, i] for i in range(H)]
    cntw = [[0, i] for i in range(W)]
    L = set()
    for _ in range(M):
        h, w = map(lambda x: int(x) - 1, input().split())
        cnth[h][0] += 1
        cntw[w][0] += 1
        L.add((h, w))
    cnth.sort(reverse=True)
    cntw.sort(reverse=True)
    mh = set()
    ph = cnth[0]
    for h in cnth:
        if ph[0] == h[0]:
            mh.add(h[1])
        else:
            break
        ph = h
    mw = set()
    pw = cntw[0]
    for w in cntw:
        if pw[0] == w[0]:
            mw.add(w[1])
        else:
            break
        pw = w
    maxans = cnth[0][0] + cntw[0][0]
    for h in mh:
        for w in mw:
            if not ((h, w) in L):
                print(maxans)
                break
        else:
            continue
        break
    else:
        print(maxans - 1)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

H, W, M = map(int, input().split())
cnth = [[0, i] for i in range(H)]
cntw = [[0, i] for i in range(W)]
L = [[False for _ in range(W)] for _ in range(H)]
for _ in range(M):
    h, w = map(lambda x: int(x) - 1, input().split())
    cnth[h][0] += 1
    cntw[w][0] += 1
    L[h][w] = True
cnth.sort(reverse=True)
cntw.sort(reverse=True)
mh = set()
ph = cnth[0]
for h in cnth:
    if ph[0] == h[0]:
        mh.add(h[1])
    else:
        break
    ph = h
mw = set()
pw = cntw[0]
for w in cntw:
    if pw[0] == w[0]:
        mw.add(w[1])
    else:
        break
    pw = w
max = cnth[0][0] + cntw[0][0]
for h in mh:
    for w in mw:
        if not (L[h][w]):
            print(max)
            break
    else:
        continue
    break
else:
    print(max - 1)
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

h, w, m = map(int, input().split())
hw = []
h_cnt = [0] * h
w_cnt = [0] * w
hw = []
hw_set = set()
for _ in range(m):
    r, c = map(int, input().split())
    r -= 1
    c -= 1
    h_cnt[r] += 1
    w_cnt[c] += 1
    hw.append((r, c))
    hw_set.add((r, c))
mh = max(h_cnt)
mw = max(w_cnt)
cand_r = []
for i in range(h):
    if h_cnt[i] == mh:
        cand_r.append(i)
cand_c = []
for j in range(w):
    if w_cnt[j] == mw:
        cand_c.append(j)
ans = mh + mw
for i in cand_r:
    for j in cand_c:
        if not (i, j) in hw_set:
            print(ans)
            exit()
print(ans - 1)


Error: TLE

Fixed submission:

h, w, m = map(int, input().split())
hw = []
h_cnt = [0] * h
w_cnt = [0] * w
hw = []
hw_set = set()
for _ in range(m):
    r, c = map(int, input().split())
    r -= 1
    c -= 1
    h_cnt[r] += 1
    w_cnt[c] += 1
    hw.append((r, c))
    hw_set.add((r, c))
mh = max(h_cnt)
mw = max(w_cnt)
ans = mh + mw
is_exist = False
for i in range(h):
    if h_cnt[i] != mh:
        continue
    for j in range(w):
        if w_cnt[j] == mw:
            if not (i, j) in hw_set:
                is_exist = True
                print(ans)
                exit()
print(ans - 1)
Problem p02580 (Python) — buggy submission, verdict: Runtime Error

H, W, m = map(int, input().split())
xs = [0] * H
ys = [0] * W
s = set()
for _ in range(m):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    xs[h] += 1
    ys[w] += 1
    s.add((h, w))

mx = max(xs)
my = max(ys)
mxs = set()
for i in range(H):
    if xs[i] == mx:
        mxs.add(i)
mys = set()
for i in range(W):
    if ys[i] == my:
        mys.add(i)
for x in mxs:
    for y in mys:
        if not (x, y) in s:
            print(mx + my)
            exit()
print(mx + my - 1)


Error: 0

Fixed submission:

H, W, m = map(int, input().split())
xs = [[0] * W for _ in range(H)]
for _ in range(m):
    h, w = map(int, input().split())
    xs[h - 1][w - 1] += 1

mxx = [0] * H
for i in range(H):
    sm = 0
    for j in range(W):
        sm += xs[i][j]
    mxx[i] = sm
mxy = [0] * W
for i in range(W):
    sm = 0
    for j in range(H):
        sm += xs[j][i]
    mxy[i] = sm
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, mxx[i] + mxy[j] - xs[i][j])
print(ans)
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys
from collections import Counter


def main():
    input = sys.stdin.buffer.readline
    h, w, m = map(int, input().split())
    h = [0] * m
    w = [0] * m
    object_set = set()
    for i in range(m):
        h[i], w[i] = map(int, input().split())
        object_set.add((h[i], w[i]))
    h_counter = Counter(h)
    w_counter = Counter(w)
    max_h_num = h_counter.most_common()[0][1]
    max_w_num = w_counter.most_common()[0][1]
    ans = max_h_num + max_w_num

    h_cand = set()
    w_cand = set()
    for e, n in h_counter.most_common():
        if n == max_h_num:
            h_cand.add(e)
    for e, n in w_counter.most_common():
        if n == max_w_num:
            w_cand.add(e)

    cnt = 0
    for h_e, w_e in object_set:
        if h_e in h_cand and w_e in w_cand:
            cnt += 1

    print(ans if cnt < len(h_cand) * len(w_cand) else ans - 1)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

import sys
from collections import Counter


def main():
    input = sys.stdin.buffer.readline
    h, w, m = map(int, input().split())
    h = [0] * m
    w = [0] * m
    object_set = set()
    for i in range(m):
        h[i], w[i] = map(int, input().split())
        object_set.add((h[i], w[i]))
    h_counter = Counter(h)
    w_counter = Counter(w)
    max_h_num = h_counter.most_common()[0][1]
    max_w_num = w_counter.most_common()[0][1]
    ans = max_h_num + max_w_num

    h_cand = []
    w_cand = []
    for e, n in h_counter.most_common():
        if n == max_h_num:
            h_cand.append(e)
    for e, n in w_counter.most_common():
        if n == max_w_num:
            w_cand.append(e)

    ok = False
    for h_e in h_cand:
        for w_e in w_cand:
            if (h_e, w_e) not in object_set:
                ok = True

    print(ans if ok else ans - 1)


if __name__ == "__main__":
    main()
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

from operator import itemgetter

h, w, m = (int(x) for x in input().split())
H = [0] * h
W = [0] * w
HW = []
for _ in range(m):
    h_, w_ = (int(x) - 1 for x in input().split())
    HW.append((h_, w_))
    H[h_] += 1
    W[w_] += 1
hmax = max(H)
wmax = max(W)
hindex = set()
windex = set()

HW.sort(key=itemgetter(0, 1))
for y in range(h):
    if H[y] == hmax:
        hindex.add(y)
for x in range(w):
    if W[x] == wmax:
        windex.add(x)

count = 0
for h, w in HW:
    if h in hindex and w in windex:
        count += 1

if count == len(hindex) * len(windex):
    ans = hmax + wmax - 1
else:
    ans = hmax + wmax

print(ans)


Error: TLE

Fixed submission:

from operator import itemgetter

h, w, m = (int(x) for x in input().split())
H = [0] * h
W = [0] * w
HW = []
for _ in range(m):
    h_, w_ = (int(x) - 1 for x in input().split())
    HW.append((h_, w_))
    H[h_] += 1
    W[w_] += 1
hmax = max(H)
wmax = max(W)
hindex = []
windex = []
ans = hmax + wmax - 1

HW.sort(key=itemgetter(0, 1))
for y in range(h):
    if H[y] == hmax:
        hindex.append(y)
for x in range(w):
    if W[x] == wmax:
        windex.append(x)

HW_set = set(HW)
for y in hindex:
    for x in windex:
        if not (y, x) in HW_set:
            ans = hmax + wmax

print(ans)
Problem p02580 (Python) — buggy submission, verdict: Runtime Error

H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

row, col = [0] * H, [0] * W
for h, w in hw:
    row[h - 1] += 1
    col[w - 1] += 1

rowmax, colmax = max(row), max(col)
cnt = row.count(rowmax) * col.count(colmax)
for h, w in hw:
    if row[h - 1] == rowmax and col[w - 1] == colmax:
        cnt -= 1
print(rowmax + colmax - (cnt == 0))


Error: WA

Fixed submission:

H, W, m = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(m)]

mat = [[0] * W for _ in range(H)]
for h, w in hw:
    mat[h - 1][w - 1] = 1

rowcnt = [sum(row) for row in mat]
colcnt = []
for col in range(W):
    colcnt.append(sum(row[col] for row in mat))

rowmax, colmax = max(rowcnt), max(colcnt)
print(rowmax + colmax - 1)
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

h, w, m = map(int, input().split())
target_points = {tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)}

row_points = [0] * h
col_points = [0] * w
for row, col in target_points:
    row_points[row] += 1
    col_points[col] += 1

row_max = max(row_points)
col_max = max(col_points)

row_max_indexes = [i for i in range(h) if row_points[i] == row_max]
col_max_indexes = [i for i in range(w) if col_points[i] == col_max]

empty_crossing_exist = False
for row in row_max_indexes:
    for col in col_max_indexes:
        if (row, col) not in target_points:
            empty_crossing_exist = True
            break
    if empty_crossing_exist:
        break

print(row_max + col_max - (not empty_crossing_exist))


Error: TLE

Fixed submission:

h, w, m = map(int, input().split())
target_points = {tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)}

row_points = [0] * h
col_points = [0] * w
for row, col in target_points:
    row_points[row] += 1
    col_points[col] += 1

row_max = max(row_points)
col_max = max(col_points)

row_max_indexes = [i for i in range(h) if row_points[i] == row_max]
col_max_indexes = [i for i in range(w) if col_points[i] == col_max]

crossing_points = {(row, col) for row in row_max_indexes for col in col_max_indexes}

print(row_max + col_max - (not (crossing_points - target_points)))
Problem p02580 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

input = sys.stdin.buffer.readline

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

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

for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map.append((h, w))

MX = max(X)
MY = max(Y)
ans = MX + MY
Xans = set()
Yans = set()
for i, x in enumerate(X):
    if x == MX:
        Xans.add(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.add(i)
cnt = 0
for h, w in Map:
    if h in Yans and w in Xans:
        cnt += 1
if cnt == len(Xans) * len(Yans):
    ans -= 1
print(ans)


Error: TLE

Fixed submission:

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

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

for _ in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    Y[h] += 1
    X[w] += 1
    Map.append((h, w))

MX = max(X)
MY = max(Y)
ans = MX + MY
Xans = []
Yans = []
for i, x in enumerate(X):
    if x == MX:
        Xans.append(i)
for i, y in enumerate(Y):
    if y == MY:
        Yans.append(i)
flag = False
cnt = 0
for h, w in Map:
    if h in Yans and w in Xans:
        cnt += 1
if cnt == len(Xans) * len(Yans):
    ans -= 1
print(ans)