Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
nodes = []
for _ in range(n):
    x, y = map(int, input().split())
    nodes.append((x, y))

nodes.sort(reverse=True)
ans = 0
while nodes:
    ans += 1
    x, y = nodes.pop()
    for i, j in nodes[::-1]:
        if x-i != 0 and y-j != 0:
            vect = (i-x, j-y)
            break
    p, q = vect
    rm_list = []
    for i, j in nodes:
        if i-x == 0 or j-y == 0:
            continue
        if (i-x) % p == 0 and (j-y) % q == 0:
            rm_list.append((i, j))
    for item in rm_list:
        nodes.remove(item)
print(ans)

Fixed submission:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xy.sort()
vectors = set()
for i in range(n-1):
    for j in range(i+1, n):
        xi, yi = xy[i]
        xj, yj = xy[j]
        if xj-xi == 0 and yj-yi == 0:
            continue
        unit_vector = (xj-xi, yj-yi)
        vectors |= {unit_vector}
ans = n
for vector in vectors:
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            xi, yi = xy[i]
            xj, yj = xy[j]
            if vector == (xj-xi, yj-yi):
                cnt += 1
    ans = min(ans, n-cnt)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    a, b = map(lambda x: int(x)-1, input().split())
    edges[a].append(b)
    edges[b].append(a)


cost = sorted(map(int, input().split()), reverse=True)

priority = [(len(edge), v) for v, edge in enumerate(edges)]
priority.sort(reverse=True)
ans = [None]*n
while priority:
    d, v = priority.pop()
    c = cost.pop()
    ans[v] = c

m = 0


def dfs(v, parent):
    if parent != -1:
        global m
        m += min(ans[v], ans[parent])

    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v)


dfs(0, -1)
print(m)
print(*ans)


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    a, b = map(lambda x: int(x)-1, input().split())
    edges[a].append(b)
    edges[b].append(a)


cost = sorted(map(int, input().split()))
m = 0
ans = [None]*n


def dfs(v, parent):
    ans[v] = cost.pop()
    if parent != -1:
        global m
        m += min(ans[v], ans[parent])
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v)


dfs(0, -1)
print(m)
print(*ans)
Buggy python submission (verdict: Runtime Error):
from itertools import product
n, m = map(int, input().split())
switch = []
for _ in range(m):
    k, *s = map(lambda x: int(x)-1, input().split())
    switch.append(s)
p = map(int, input().split())

ans = 0
for subset in product((0, 1), n):
    for j in range(m):
        on_cnt = sum(subset[s] for s in switch[j])
        if on_cnt % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)


Fixed submission:
n, m = map(int, input().split())
ls = []
for _ in range(m):
    k, *s, = map(lambda x: int(x)-1, input().split())
    ls.append(s)
p = list(map(int, input().split()))


def base_n(x, n, zero_padding=8):
    retval = [[], ['0']][x == 0]
    while x > 0:
        x, r = divmod(x, n)
        retval.append(str(r))
    cnt = zero_padding - len(retval)
    pad = ['', '0'*cnt][cnt > 0]
    return pad+''.join(retval[::-1])


ans = 0
for i in range(2**n):
    base_2 = base_n(i, 2, n)
    for j in range(m):
        switchs = ls[j]
        cond = p[j]

        on_cnt = 0
        for switch in switchs:
            if int(base_2[switch]):
                on_cnt += 1
        if on_cnt % 2 != cond:
            break

    else:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, q = map(int, input().split())
s = input()

score = [x+y == 'AC' for x, y in zip(s, s[1:])]

for _ in range(q):
    l, r = map(int, input().split())
    print(sum(score[l-1:r-1]))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, q = map(int, input().split())
s = input()

score = [0]*n
for i in range(n-1):
    score[i+1] = score[i]
    if s[i]+s[i+1] == 'AC':
        score[i+1] += 1

for _ in range(q):
    l, r = map(int, input().split())
    print(score[r-1]-score[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

a = []
for _ in range(q):
    l, r = map(int, input().split())
    a.append(s[l-1:r])

print(*(x.count('AC') for x in a), sep='\n')


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, q = map(int, input().split())
s = input()

score = [0]*n
for i in range(n-1):
    score[i+1] = score[i]
    if s[i]+s[i+1] == 'AC':
        score[i+1] += 1

for _ in range(q):
    l, r = map(int, input().split())
    print(score[r-1]-score[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

for _ in range(q):
    l, r = map(int, input().split())
    print(s[l-1:r].count('AC'))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, q = map(int, input().split())
s = input()

score = [0]*n
for i in range(n-1):
    score[i+1] = score[i]
    if s[i]+s[i+1] == 'AC':
        score[i+1] += 1

for _ in range(q):
    l, r = map(int, input().split())
    print(score[r-1]-score[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
sys.setrecursionlimit(10**7)
n = int(input())
B = list(map(int, input().split()))
c = Counter(B)
A = []
history = []


def dfs(i):
    if i == n+1:
        if A == B:
            print(*history, sep='\n')
            exit()
        return 0
    for j in reversed(range(1, i+1)):
        if not c[j]:
            continue
        c[j] -= 1
        history.append(j)
        A.insert(j-1, j)
        dfs(i+1)
        A.pop(j-1)
        history.pop()
        c[j] += 1


dfs(1)
print(-1)

Fixed submission:
n = int(input())
B = list(map(int, input().split()))
A = []
for b in B:
    A.insert(b-1, b)
if all(A[i] <= i+1 for i in range(n)):
    C = []
    for a in A:
        C.insert(a-1, a)
    if B == C:
        print(*A, sep='\n')
    else:
        print(-1)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import sys
sys.setrecursionlimit(10**7)
n = int(input())
B = list(map(int, input().split()))
c = Counter(B)
A = []
ans = -1
history = []


def dfs(i):
    if i == n+1:
        if A == B:
            global ans
            ans = history[::]
        return 0
    for j in range(1, i+1):
        if not c[j]:
            continue
        c[j] -= 1
        history.append(j)
        A.insert(j-1, j)
        dfs(i+1)
        A.pop(j-1)
        history.pop()
        c[j] += 1


dfs(1)
if ans == -1:
    print(ans)
else:
    print(*ans, sep='\n')


Fixed submission:
n = int(input())
B = list(map(int, input().split()))
A = []
for b in B:
    A.insert(b-1, b)
if all(A[i] <= i+1 for i in range(n)):
    C = []
    for a in A:
        C.insert(a-1, a)
    if B == C:
        print(*A, sep='\n')
    else:
        print(-1)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
# O(10**8)くらいあるんだけど...
from collections import Counter
from itertools import combinations
MOD = 10**9+7
n = int(input())
s = input()
c = Counter(s)
abc = set(s)
ans = n
for i in range(2, len(abc)+1):
    for comb in combinations(abc, i):
        tmp = 1
        for x in comb:
            tmp *= c[x]
            tmp %= MOD
        ans += tmp
        ans %= MOD
print(ans)


Fixed submission:
from collections import Counter
MOD = 10**9+7
n = int(input())
s = input()
c = Counter(s)
ans = 1
for v in c.values():
    ans *= v+1
    ans %= MOD
print((ans-1) % MOD)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
s = {*range(1, m+1)}
for _ in range(n):
    k, *a = map(int, input().split())
    s &= set(a)
print(len(s))

Fixed submission:
from collections import defaultdict
n, m = map(int, input().split())
s = []
for _ in range(n):
    k, *a = map(int, input().split())
    s.append(a)
dd = defaultdict(int)
for l in s:
    for k in l:
        dd[k] += 1

print(sum(1 if v == n else 0 for k, v in dd.items()))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
s = {*range(1, m+1)}
for _ in range(n):
    k, *a = map(int, input().split())
    s &= set(a)
print(len(s))

Fixed submission:
from collections import defaultdict
n, m = map(int, input().split())
s = []
for _ in range(n):
    k, *a = map(int, input().split())
    s.append(a)
dd = defaultdict(int)
for l in s:
    for k in l:
        dd[k] += 1

print(sum(1 if v == n else 0 for k, v in dd.items()))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF]*n
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if n <= i+j:
            continue
        dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(i, k)+1))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(i, k)+1))
print(dp[-1])


Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(i, k)+1))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
weights, values = zip(*[tuple(map(int, input().split())) for _ in range(n)])
UV = 10**5
INF = 10**10
dp = [INF]*(UV+1)
dp[0] = 0

for i in range(1, n+1):
    for j in reversed(range(1, UV+1)):
        if j-values[i-1] < 0:
            continue
        dp[j] = min(dp[j], dp[j-values[i-1]]+weights[i-1])

ans = 0
for j in reversed(range(UV+1)):
    if dp[j] <= w:
        ans = j
        break
print(ans)

Fixed submission:
n, w = map(int, input().split())
weights, values = zip(*[tuple(map(int, input().split())) for _ in range(n)])
UV = 10**5
INF = float('inf')
dp = [[0]+[INF]*UV for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(1, UV+1):
        dp[i][j] = dp[i-1][j]
        if 0 <= j-values[i-1]:
            dp[i][j] = min(dp[i][j], dp[i-1][j-values[i-1]]+weights[i-1])

ans = 0
for i in range(UV+1):
    if dp[-1][i] <= w:
        ans = max(ans, i)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        dp[i][j] = max(dp[i][j], dp[i][j-1])
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1)

ans = ""
i = len(s)
j = len(t)
while 0 < i and 0 < j:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans += s[i]
print(ans[::-1])

Fixed submission:
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        dp[i][j] = max(dp[i][j], dp[i][j-1])
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1)

ans = ""
i = len(s)
j = len(t)
while 0 < i and 0 < j:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans += s[i]
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(float, input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1, n+1):
    for j in range(n+1):
        dp[i][j] += dp[i-1][j-1]*p[i-1]
        dp[i][j] += dp[i-1][j]*(1-p[i-1])
print(sum(dp[-1][-(-n//2):]))


Fixed submission:
n = int(input())
p = list(map(float, input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1, n+1):
    for j in range(n+1):
        dp[i][j] += dp[i-1][j-1]*p[i-1]
        dp[i][j] += dp[i-1][j]*(1-p[i-1])
print(sum(dp[-1][-(-n//2):]))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list(map(int, input().split()))
# dp[i] i個の石で手番の時の勝ち負け
dp = [0]*(k+1)
# 貰う
for i in range(1, k+1):
    for j in range(n):
        if i-A[j] < 0:
            continue
        dp[i] = max(dp[i], 1 if dp[i-A[j]] == 0 else 0)
print('First' if dp[k] else 'Second')


Fixed submission:
n, k = map(int, input().split())
A = list(map(int, input().split()))
# dp[i] i個の石で手番の時の勝ち負け
dp = [0]*(k+1)
# 貰う
for i in range(1, k+1):
    for j in range(n):
        if i-A[j] < 0:
            continue
        dp[i] = max(dp[i], 1 if dp[i-A[j]] == 0 else 0)
print('First' if dp[k] else 'Second')
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(level, x):
    if x <= 1:
        return 0
    else:
        ai_1 = a(level-1)
        if 1 < x <= 1 + ai_1:
            return f(level-1, x-1)
        else:
            pi_1 = p(level-1)
            return 1 + pi_1+f(level-1, x-2-ai_1)


print(f(n, x))

Fixed submission:
n, x = map(int, input().split())


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a(N-1):
        return f(N-1, X-1)
    else:
        return p(N-1) + 1 + f(N-1, X-2-a(N-1))



print(f(n, x))

Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(level, x):
    if x == 1:
        return 0
    else:
        ai_1 = a(level-1)
        if 1 < x < 1 + ai_1:
            return f(level-1, x-1)
        else:
            pi_1 = p(level-1)
            if x == 2 + ai_1:
                return 1 + pi_1
            elif 2+ai_1 < x < 2 + 2*ai_1:
                return 1 + pi_1+f(level-1, x-2-ai_1)
            elif x == 3 + 2*ai_1:
                return 1 + 2*pi_1


print(f(n, x))

Fixed submission:
n, x = map(int, input().split())


def p(level):
    if level == 0:
        return 1
    return 2*p(level-1)+1


def a(level):
    if level == 0:
        return 1
    return 2*a(level-1)+3


def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a(N-1):
        return f(N-1, X-1)
    else:
        return p(N-1) + 1 + f(N-1, X-2-a(N-1))



print(f(n, x))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from itertools import accumulate
n, k = map(int, input().split())
A = list(map(int, input().split()))
Acum = [0]
Acum.extend(accumulate(A))
cnt = defaultdict(int)
for i in range(n):
    for j in range(i+1, n+1):
        beauty = Acum[j]-Acum[i]
        cnt[beauty] += 1

x = 0
for t in reversed(range(41)):
    y = 1 << t
    cnt_k = 0
    for beauty, c in cnt.items():
        if (x+y) & beauty == (x+y):
            cnt_k += c
    if k <= cnt_k:
        x += y

print(x)

Fixed submission:
from collections import defaultdict
from itertools import accumulate
n, k = map(int, input().split())
A = list(map(int, input().split()))
Acum = [0]
Acum.extend(accumulate(A))
cnt = defaultdict(int)
for i in range(n):
    for j in range(i+1, n+1):
        beauty = Acum[j]-Acum[i]
        cnt[beauty] += 1

x = 0
for t in reversed(range(41)):
    y = 1 << t
    cnt_k = 0
    for beauty, c in cnt.items():
        if (x+y) & beauty == (x+y):
            cnt_k += c
    if k <= cnt_k:
        x += y

print(x)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort_left, bisect_left
n, m = map(int, input().split())
d = [[] for _ in range(n + 1)]
m = [tuple(map(int, input().split())) for _ in range(m)]

for p, y in m:
    insort_left(d[p], y)

for p, y in m:
    print('{:06}{:06}'.format(p, bisect_left(d[p], y)+1))


Fixed submission:
from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
m = [tuple(map(int, input().split())) for _ in range(m)]

d = defaultdict(list)
for p, y in sorted(m):
    d[p] += [y]


for p, y in m:
    i = bisect_left(d[p], y)
    print('{:06}{:06}'.format(p, i+1))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort_left
n, m = map(int, input().split())
d = [[] for _ in range(n + 1)]
m = [tuple(map(int, input().split())) for _ in range(m)]

for p, y in m:
    insort_left(d[p], y)

for i, row in enumerate(d):
    d[i] = {x: i+1 for i, x in enumerate(row)}

for p, y in m:
    print('{:06}{:06}'.format(p, d[p][y]))

Fixed submission:
from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
m = [tuple(map(int, input().split())) for _ in range(m)]

d = defaultdict(list)
for p, y in sorted(m):
    d[p] += [y]


for p, y in m:
    i = bisect_left(d[p], y)
    print('{:06}{:06}'.format(p, i+1))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort_left
n, m = map(int, input().split())
d = [[] for _ in range(n + 1)]
m = [tuple(map(int, input().split())) for _ in range(m)]

for p, y in m:
    insort_left(d[p], y)
for p, y in m:
    print('{:06}{:06}'.format(p, d[p].index(y)+1))

Fixed submission:
from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
m = [tuple(map(int, input().split())) for _ in range(m)]

d = defaultdict(list)
for p, y in sorted(m):
    d[p] += [y]


for p, y in m:
    i = bisect_left(d[p], y)
    print('{:06}{:06}'.format(p, i+1))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
d = [[] for _ in range(n + 1)]
m = [tuple(map(int, input().split())) for _ in range(m)]
for p, y in m:
    d[p].append(y)
d = [sorted(s) for s in d]
for p, y in m:
    print('{:06}{:06}'.format(p, d[p].index(y)+1))


Fixed submission:
from bisect import bisect_left
from collections import defaultdict
n, m = map(int, input().split())
m = [tuple(map(int, input().split())) for _ in range(m)]

d = defaultdict(list)
for p, y in sorted(m):
    d[p] += [y]


for p, y in m:
    i = bisect_left(d[p], y)
    print('{:06}{:06}'.format(p, i+1))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
U = 10**9
for i in range(n, U+1):
    if m % i == 0:
        print(m//i)
        break


Fixed submission:
n, m = map(int, input().split())
divisors = set()
for i in range(1, int(m**.5)+1):
    if m % i == 0:
        divisors |= {i, m//i}
divisors = sorted(divisors)
for div in divisors:
    if n <= div:
        print(m//div)
        break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [list(map(int, list('{:020b}'.format(a))))
     for a in map(int, input().split())]

ans = 0
R = -1
X = [0]*20
for L in range(n):
    if R < L:
        R += 1
        for i in range(20):
            X[i] += A[R][i]

    while R+1 < n and all(x+y != 2 for x, y in zip(X, A[R+1])):
        for i in range(20):
            X[i] += A[R+1][i]
        R += 1
    ans += R-L+1
    for i in range(20):
        X[i] -= A[L][i]
print(ans)

Fixed submission:
n = int(input())
A = [list(map(int, list('{:020b}'.format(a))))
     for a in map(int, input().split())]

ans = 0
R = -1
X = [0]*20
for L in range(n):
    if R < L:
        R += 1
        for i in range(20):
            X[i] += A[R][i]

    while R+1 < n and all(x+y != 2 for x, y in zip(X, A[R+1])):
        for i in range(20):
            X[i] += A[R+1][i]
        R += 1
    ans += R-L+1
    for i in range(20):
        X[i] -= A[L][i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [list(map(int, list('{:020b}'.format(a))))
     for a in map(int, input().split())]

ans = 0
for L in range(n):
    R = L+1
    tmp = A[L]
    while R < n:
        for i in range(20):
            tmp[i] += A[R][i]
        if 2 in tmp:
            break
        R += 1
    ans += R-L
print(ans)


Fixed submission:
n = int(input())
A = [list(map(int, list('{:020b}'.format(a))))
     for a in map(int, input().split())]

ans = 0
R = -1
X = [0]*20
for L in range(n):
    if R < L:
        R += 1
        for i in range(20):
            X[i] += A[R][i]

    while R+1 < n and all(x+y != 2 for x, y in zip(X, A[R+1])):
        for i in range(20):
            X[i] += A[R+1][i]
        R += 1
    ans += R-L+1
    for i in range(20):
        X[i] -= A[L][i]
print(ans)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
m = [list(input()) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            cnt = 0
            # left
            if 0 <= i-1:
                if m[i-1][j] != '#':
                    cnt += 1
            # right
            if i+1 < w:
                if m[i+1][j] != '#':
                    cnt += 1
            # up
            if 0 >= j-1:
                if m[i][j-1] != '#':
                    cnt += 1
            # down
            if j+1 < h:
                if m[i][j+1] != '#':
                    cnt += 1
            if cnt == 4:
                print('No')
                exit(0)
            cnt = 0
else:
    print('Yes')


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

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            cnt = sum([0 <= i-1, i+1 < h, 0 <= j-1, j+1 < w])

            # up
            if 0 <= i-1:
                if m[i-1][j] != '#':
                    cnt -= 1

            # down
            if i+1 < h:
                if m[i+1][j] != '#':
                    cnt -= 1
            # left
            if 0 <= j-1:
                if m[i][j-1] != '#':
                    cnt -= 1

            # right
            if j+1 < w:
                if m[i][j+1] != '#':
                    cnt -= 1

            if cnt == 0:
                print('No')
                exit(0)
else:
    print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
r = [x for x in range(a, b + 1)]
for x in sorted(set(r[:k]) | set(r[-k:])):
    print(x)


Fixed submission:
a, b, k = map(int, input().split())
r = range(a, b + 1)
for x in sorted(set(r[:k]) | set(r[-k:])):
    print(x)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
b = [input() for _ in range(n)]
m = int(input())
r = [input() for _ in range(m)]

db, dr = [Counter(x) for x in (b, r)]
print(max(*[v-dr[k] for k, v in db.items()]+[0]))


Fixed submission:
a, b, c = map(int, input().split())
print('Yes' if a+b >= c else 'No')
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
b = [input() for _ in range(n)]
m = int(input())
r = [input() for _ in range(m)]

db, dr = [Counter(x) for x in (b, r)]

print(max(*(v-dr[k] for k, v in db.items()), 0))


Fixed submission:
from collections import Counter

n = int(input())
b = [input() for _ in range(n)]
m = int(input())
r = [input() for _ in range(m)]

db, dr = [Counter(x) for x in (b, r)]
print(max(*[v-dr[k] for k, v in db.items()]+[0]))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
b = [input() for _ in range(n)]
m = int(input())
r = [input() for _ in range(m)]

db = Counter(b)
dr = Counter(r)

print(max(*(v-dr[k] for k, v in db.items()), 0))


Fixed submission:
from collections import Counter

n = int(input())
b = [input() for _ in range(n)]
m = int(input())
r = [input() for _ in range(m)]

db, dr = [Counter(x) for x in (b, r)]
print(max(*[v-dr[k] for k, v in db.items()]+[0]))