Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03063 (python)

Fixed submission:
n = int(input())
s = input()

f = [0]
tmp = 0
for c in s:
    if c == '#':
        tmp += 1
    f.append(tmp)

b = [0]
tmp = 0
for c in s[::-1]:
    if c == '.':
        tmp += 1
    b.append(tmp)
b.reverse()

# print(f)
# print(b)
print(min(map(sum, zip(f, b))))

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict

n = int(input())
aaa = list(map(int, sys.stdin))
MOD = 998244353

d2 = [1]
tmp = 1
for i in range(n):
    tmp = tmp * 2 % MOD
    d2.append(tmp)

s = sum(aaa)
dp = [defaultdict(lambda: 0) for _ in [0] * (s + 1)]
dp[0][0] = 1
tmp_sum = 0
for a in aaa:
    for i in range(tmp_sum, -1, -1):
        dd = dp[i]
        if not dd:
            continue
        for k, p in dd.items():
            dp[i + a][k + 1] += p
    tmp_sum += a

ans = pow(3, n, MOD)
sub = 0
h = (s + 1) // 2
for dd in dp[h:]:
    for k, p in dd.items():
        sub += d2[n - k] * p * 3
    sub %= MOD
if s % 2 == 0:
    dd = dp[h]
    for k, p in dd.items():
        sub -= p * 3

ans = (ans - sub) % MOD
print(ans)
Problem p03081 (python)

Fixed submission:
import sys

n, q = map(int, input().split())
s = input()
commands = [line.rstrip().split() for line in sys.stdin]
commands.reverse()

l, r = 0, n - 1
for t, d in commands:
    if s[l] == t and d == 'L':
        l += 1
    elif 0 < l and s[l - 1] == t and d == 'R':
        l -= 1
    if s[r] == t and d == 'R':
        r -= 1
    elif r < n - 1 and s[r + 1] == t and d == 'L':
        r += 1
    if l > r:
        break

print(r - l + 1)

Buggy submission (verdict: Runtime Error):
import sys


def simulate(i, check_out_bound):
    for t, d in commands:
        if t == s[i]:
            if d == 'L':
                i -= 1
            else:
                i += 1
        if check_out_bound(i):
            return False
    return True


def check(is_left, check_out_bound):
    l, r = 0, n - 1
    while l < r:
        m = (l + r) // 2
        if simulate(m, check_out_bound):
            if is_left:
                r = m
            else:
                l = m
        else:
            if is_left:
                l = m + 1
            else:
                r = m - 1
        # print(is_left, l, r)
    return l


n, q = map(int, input().split())
s = input()
commands = [line.rstrip().split() for line in sys.stdin]

check_out_bound_l = lambda i: i < 0
check_out_bound_r = lambda i: i >= n
if simulate(0, check_out_bound_l):
    bl = 0
else:
    bl = check(True, check_out_bound_l)
if simulate(n - 1, check_out_bound_r):
    br = n - 1
else:
    br = check(False, check_out_bound_r)
print(br - bl + 1)

Buggy submission (verdict: Runtime Error):
import sys

n, q = map(int, input().split())
s = input()
commands = [line.rstrip().split() for line in sys.stdin]
commands.reverse()
lim_l, lim_r = 0, n - 1
ans = 0
for t, d in commands:
    if d == 'L':
        if t == s[lim_l]:
            ans += 1
            lim_l += 1
        elif lim_r < n - 1 and t == s[lim_r + 1]:
            ans -= 1
            lim_r += 1
    else:
        if t == s[lim_r]:
            ans += 1
            lim_r -= 1
        elif lim_l > 0 and t == s[lim_l - 1]:
            ans -= 1
            lim_l -= 1
    # print(t, d, lim_l, lim_r, ans)
print(n - ans)
Problem p03092 (python)

Fixed submission:
from bisect import bisect
from operator import itemgetter

n, a, b = map(int, input().split())
ppp = map(int, input().split())
qqq = [i for i, p in sorted(enumerate(ppp, start=1), key=itemgetter(1))]
INF = 10 ** 15

dp = [(0, 0)]
for i in qqq:
    ndp = []
    s = bisect(dp, (i,))
    tmp_min = INF
    for j, cost in dp[:s]:
        cost += b
        ndp.append((j, cost))
        tmp_min = cost
    stay_cost = dp[s - 1][1]
    if tmp_min > stay_cost:
        ndp.append((i, stay_cost))
        tmp_min = stay_cost
    for j, cost in dp[s:]:
        cost += a
        if tmp_min > cost:
            ndp.append((j, cost))
            tmp_min = cost
    dp = ndp

print(dp[-1][1])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from operator import itemgetter

n, a, b = map(int, input().split())
ppp = list(map(int, input().split()))
qqq = list(map(itemgetter(0), sorted(enumerate(ppp, start=1), key=itemgetter(1))))

dp = {0: 0}
for i in qqq:
    ndp = defaultdict(lambda: 1000_000_000_000_000)
    tmp_min_cost = 1000_000_000_000_000
    for j, cost in sorted(dp.items()):
        if cost >= tmp_min_cost:
            continue
        tmp_min_cost = cost
        if j < i:
            ndp[i] = min(ndp[i], cost)
            ndp[j] = min(ndp[j], cost + b)
        else:
            ndp[j] = min(ndp[j], cost + a)
    dp = ndp

print(min(dp.values()))
Problem p03113 (python)

Fixed submission:
def solve(n, k, aaa):
    buf = []
    prev_last = -1

    for t in range(k + 1):
        ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
        others = set(range(1, n + 1)) - {prev_last, mi}
        buf.extend(others)
        buf.append(mi)
        # print(buf)

        for i in range(n):
            if i + 1 != prev_last:
                aaa[i] -= 1
                if aaa[i] < 0:
                    print(-1)
                    return

        prev_last = mi

    print(len(buf))
    print(*buf)


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)

Buggy submission (verdict: Runtime Error):
def solve(n, k, aaa):
    buf = []
    prev_last = -1

    for t in range(k + 1):
        ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
        others = set(range(1, n + 1)) - {prev_last, mi}
        buf.extend(others)
        if t == k:
            aaa[mi] += 1
        else:
            buf.append(mi)

        for i in range(n):
            if i + 1 != prev_last:
                aaa[i] -= 1
                if aaa[i] < 0:
                    print(-1)
                    return

        prev_last = mi

    print(len(buf))
    print(*buf)


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)
Problem p03128 (python)

Fixed submission:
n, m = map(int, input().split())
needs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
usable = {}
for a in map(int, input().split()):
    na = needs[a]
    if na in usable:
        usable[na] = max(usable[na], a)
    else:
        usable[na] = a
use_keys = sorted(usable.keys())

dp = [-9] * (n + 1)
dp[0] = 0
for d in range(2, min(8, n + 1)):
    for u in use_keys:
        du = d - u
        if du < 0:
            break
        dp[d] = max(dp[d], dp[du] + 1)
for d in range(8, n + 1):
    for u in use_keys:
        dp[d] = max(dp[d], dp[d - u] + 1)

ans = ''
remain = n
rk = [(str(a), needs[a]) for a in sorted(usable.values(), reverse=True)]
for d in range(dp[n] - 1, -1, -1):
    for a, na in rk:
        ra = remain - na
        if ra < 0:
            continue
        if dp[ra] == d:
            ans += a
            remain = ra
            break

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
needs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
usable = {}
for a in map(int, input().split()):
    na = needs[a]
    if na in usable:
        usable[na] = max(usable[na], a)
    else:
        usable[na] = a
use_keys = sorted(usable.keys())

dp = [-9] * (n + 1)
dp[0] = 0
for d in range(2, n + 1):
    for u in use_keys:
        du = d - u
        if du < 0:
            break
        dp[d] = max(dp[d], dp[du] + 1)

ans = ''
remain = n
rk = [(str(a), needs[a]) for a in sorted(usable.values(), reverse=True)]
for d in range(dp[n] - 1, -1, -1):
    for a, na in rk:
        if dp[remain - na] == d:
            ans += a
            remain -= na
            break

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
needs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
usable = {}
for a in map(int, input().split()):
    na = needs[a]
    if na in usable:
        usable[na] = max(usable[na], a)
    else:
        usable[na] = a
use_keys = sorted(usable.keys())

dp = [-9] * (n + 1)
dp[0] = 0
for d in range(2, min(8, n + 1)):
    for u in use_keys:
        du = d - u
        if du < 0:
            break
        dp[d] = max(dp[d], dp[du] + 1)
for d in range(8, n + 1):
    for u in use_keys:
        dp[d] = max(dp[d], dp[d - u] + 1)

ans = ''
remain = n
rk = [(str(a), needs[a]) for a in sorted(usable.values(), reverse=True)]
for d in range(dp[n] - 1, -1, -1):
    for a, na in rk:
        if dp[remain - na] == d:
            ans += a
            remain -= na
            break

print(ans)
Problem p03138 (python)

Fixed submission:
from itertools import accumulate

n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
bk = '{:041b}'.format(k)
bbb = list(map('{:041b}'.format, aaa))
ks = 0
best = []
thr = []
base = []
for i, c in enumerate(bk):
    d = 1 << (40 - i)
    c1 = list(b[i] for b in bbb).count('1')
    d0, d1 = c1 * d, (n - c1) * d
    best.append(max(d0, d1))
    thr.append(d0 if c == '0' else d1)
    base.append(d0)

best.reverse()
best = list(accumulate(best))
best.reverse()
best.append(0)
thr = list(accumulate(thr))

ans = thr[-1]
for i, c in enumerate(bk):
    if c == '0':
        continue
    ans = max(ans, thr[i - 1] + base[i] + best[i + 1])

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

n, k = list(map(int, input().split()))
aaa = list(map(int, input().split()))
bk = '{:041b}'.format(k)
bbb = list(map('{:041b}'.format, aaa))
ans = 0
ks = 0
for ks, c in enumerate(bk):
    if c == '1':
        break
    d = 1 << (40 - ks)
    ans += list(b[ks] for b in bbb).count('1') * d
ideal = 0
best = []
thr = []
base = []
for i, c in enumerate(bk[ks:], start=ks):
    d = 1 << (40 - i)
    c1 = list(b[i] for b in bbb).count('1')
    d0, d1 = c1 * d, (n - c1) * d
    if d0 < d1:
        ideal += d
        best.append(d1)
    else:
        best.append(d0)
    thr.append(d0 if c == '0' else d1)
    base.append(d0)

if ideal <= k:
    print(ans + sum(best))
    exit()

best = list(accumulate(best))
thr = list(accumulate(thr))
sb = best[-1]
best.append(sb)

ans2 = sum(base)
for i, c in enumerate(bk):
    if c == '0':
        continue
    ans2 = max(ans2, thr[i - 1] + base[i] + sb - best[i])

print(ans + ans2)
Problem p03142 (python)

Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 5 + 100)

n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
root = set(range(n))
for line in sys.stdin.readlines():
    a, b = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add(b)
    root.discard(b)
root = root.pop()

parents = [set() for _ in range(n)]
q = deque([(root, -1)])

while q:
    v, p = q.popleft()
    parents[v].add(p)
    if len(parents[v]) > 1:
        continue
    q.extend((c, v) for c in links[v])

fixed = [-1] * n

# print(parents)

q = deque([(root, -1)])
while q:
    v, p = q.popleft()
    pv = parents[v]
    pv.remove(p)
    if len(pv) == 0:
        fixed[v] = p
        q.extend((c, v) for c in links[v])

print('\n'.join(str(p + 1) for p in fixed))

Buggy submission (verdict: Runtime Error):
import sys

n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
root = set(range(n))
for line in sys.stdin.readlines():
    a, b = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add(b)
    root.discard(b)
root = root.pop()

parent = [-1] * n
depth = [-1] * n


def dfs(v, p, d):
    # print(v, p, d, parent, depth)
    if depth[v] != -1 and depth[v] > d:
        return
    parent[v] = p
    depth[v] = d
    for c in links[v]:
        dfs(c, v, d + 1)


dfs(root, -1, 0)

print('\n'.join(str(p + 1) for p in parent))
Problem p03158 (python)

Fixed submission:
import sys

n, q = list(map(int, input().split()))
aaa = list(map(int, input().split()))
xxx = sorted(((int(line), i) for i, line in enumerate(sys.stdin.readlines())), reverse=True)
total = sum(aaa)
tmp = sum(aaa[n // 2:])
ans = [sum(aaa[-1::-2])] * q
if n % 2 == 0:
    l, r = 1, n // 2
else:
    l, r = 0, n // 2
while l < r:
    al, ar = aaa[l], aaa[r]
    m = (al + ar) // 2
    while xxx and xxx[-1][0] <= m:
        x, i = xxx.pop()
        ans[i] = tmp
    if not xxx:
        break
    tmp += al - ar
    l += 2
    r += 1
print('\n'.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import sys

n, q = list(map(int, input().split()))
aaa = list(map(int, input().split()))
xxx = sorted(((int(line), i) for i, line in enumerate(sys.stdin.readlines())), reverse=True)
total = sum(aaa)
tmp = sum(aaa[n // 2:])
ans = [sum(aaa[-1::-2])] * q
if n % 2 == 0:
    l, r = 1, n // 2
else:
    l, r = 0, n // 2
while l < r:
    al, ar = aaa[l], aaa[r]
    m = (al + ar) // 2
    while xxx[-1][0] <= m:
        x, i = xxx.pop()
        ans[i] = tmp
    tmp += al - ar
    l += 2
    r += 1
print('\n'.join(map(str, ans)))
Problem p03165 (python)

Fixed submission:
s = input()
t = input()
dp = [0]
lcs = ['']
for b in t:
    search_idx = 0
    ncs = lcs[:]
    for i, curr_idx in enumerate(dp):
        char_idx = s.find(b, search_idx)
        if char_idx == -1:
            break
        next_idx = char_idx + 1
        if next_idx < curr_idx:
            dp[i] = next_idx
            ncs[i] = lcs[i - 1] + b
        search_idx = curr_idx
    else:
        char_idx = s.find(b, search_idx)
        if char_idx > -1:
            dp.append(char_idx + 1)
            ncs.append(lcs[-1] + b)
    lcs = ncs
print(lcs[-1])

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
dp = [0]
lcs = ['']
for b in t:
    search_idx = 0
    ncs = lcs.copy()
    for i, curr_idx in enumerate(dp):
        char_idx = s.find(b, search_idx)
        if char_idx == -1:
            break
        next_idx = char_idx + 1
        if next_idx < curr_idx:
            dp[i] = next_idx
            ncs[i] = lcs[i - 1] + b
        search_idx = curr_idx
    else:
        char_idx = s.find(b, search_idx)
        if char_idx > -1:
            dp.append(char_idx + 1)
            ncs.append(lcs[-1] + b)
    lcs = ncs
print(lcs[-1])
Problem p03166 (python)

Fixed submission:
import sys
from functools import lru_cache

sys.setrecursionlimit(1000000)


@lru_cache(maxsize=None)
def dfs(v):
    lv = links[v]
    return max(map(dfs, lv)) + 1 if lv else 0


n, m = map(int, input().split())
sss = set(range(n))
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    sss.discard(y)
    links[x].add(y)

print(max(map(dfs, sss)))

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache

sys.setrecursionlimit(100000)


@lru_cache(maxsize=None)
def dfs(v):
    lv = links[v]
    return max(map(dfs, lv)) + 1 if lv else 0


n, m = map(int, input().split())
sss = set(range(n))
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    sss.discard(y)
    links[x].add(y)

print(max(map(dfs, sss)))

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache


@lru_cache(maxsize=None)
def dfs(v):
    lv = links[v]
    return max(dfs(u) for u in lv) + 1 if lv else 0


n, m = map(int, input().split())
sss = set(range(n))
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    sss.discard(y)
    links[x].add(y)

print(max(dfs(v) for v in sss))

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache


@lru_cache(maxsize=None)
def dfs(v):
    return max((dfs(u) for u in links[v]), default=-1) + 1


n, m = map(int, input().split())
sss = set(range(n))
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    sss.discard(y)
    links[x].add(y)

print(max(dfs(v) for v in sss))
Problem p03169 (python)

Fixed submission:
from collections import Counter

n = int(input())
cnt = Counter(input().split())
c1, c2, c3 = cnt['1'], cnt['2'], cnt['3']
total = c1 + 2 * c2 + 3 * c3
c23 = c2 + c3
dp = [[[0.0] * (c3 + 1) for _ in range(c2 + c3 + 1)] for _ in range(n + 2)]

for k in range(1, n + 1):
    still = n / k
    for a1 in range(k, max(-1, 2 * k - total - 1, k - c23 - 1), -1):
        dpap, dpac, dpan = dp[a1 - 1], dp[a1], dp[a1 + 1]
        for a2 in range(min(k - a1, c2 + c3), max(-1, 3 * k - 2 * a1 - total - 1, k - a1 - c3 - 1), -1):
            a3 = k - a1 - a2
            tmp = 0
            if a1:
                tmp += dpap[a2][a3] * a1
            if a2:
                tmp += dpan[a2 - 1][a3] * a2
            if a3:
                tmp += dpac[a2 + 1][a3 - 1] * a3
            dpac[a2][a3] = tmp / k + still
print(dp[c1][c2][c3])

Buggy submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
cnt = Counter(input().split())
c1, c2, c3 = cnt['1'], cnt['2'], cnt['3']
total = c1 + 2 * c2 + 3 * c3
dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]

for k in range(1, n + 1):
    still = n / k
    for a1 in range(k, -1, -1):
        dpap, dpac, dpan = dp[a1 - 1], dp[a1], dp[a1 + 1]
        for a2 in range(min(k - a1, (total - a1) // 2), -1, -1):
            a3 = k - a1 - a2
            if a1 + 2 * a2 + 3 * a3 > total:
                break
            tmp = 0
            if a1:
                tmp += dpap[a2][a3] * a1
            if a2:
                tmp += dpan[a2 - 1][a3] * a2
            if a3:
                tmp += dpac[a2 + 1][a3 - 1] * a3
            dpac[a2][a3] = tmp / k + still
print(dp[c1][c2][c3])
Problem p03239 (python)

Fixed submission:
n, m = map(int, input().split())
ans = 999999
for _ in range(n):
    c, t = map(int, input().split())
    if t > m:
        continue
    ans = min(ans, c)
if ans == 999999:
    print('TLE')
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = 999999
for _ in range(n):
  c, t = map(int, input().split())
  if t > m:
    continue
  ans = min(ans, c)
if ans = 999999:
  print('TLE')
else:
  print(ans)
Problem p03240 (python)

Fixed submission:
def solve(n):
    can = [[[-1, float('inf')] for _ in range(101)] for _ in range(101)]
    for k in range(n):
        x, y, h = map(int, input().split())
        for i in range(101):
            for j in range(101):
                if can[i][j] is None:
                    continue
                hh = h + abs(x - i) + abs(y - j)
                hl = 1 if h == 0 else hh
                nl, nh = max(can[i][j][0], hl), min(can[i][j][1], hh)
                if nl > nh:
                    can[i][j] = None
                else:
                    can[i][j][0] = nl
                    can[i][j][1] = nh

    for i in range(101):
        for j in range(101):
            if can[i][j] is None:
                continue
            return i, j, can[i][j][0]


n = int(input())
print(*solve(n))

Buggy submission (verdict: Runtime Error):
n = int(input())
can = [[0] * 101 for _ in range(101)]


def solve(n, can):
    for k in range(n):
        x, y, h = map(int, input().split())
        if k == 0:
            for i in range(101):
                for j in range(101):
                    can[i][j] = h + abs(x - i) + abs(y - j)
        else:
            for i in range(101):
                for j in range(101):
                    if can[i][j] is None:
                        continue
                    if h + abs(x - i) + abs(y - j) != can[i][j]:
                        can[i][j] = None
    for i in range(101):
        for j in range(101):
            if can[i][j] is None:
                continue
            return i, j, can[i][j]


print(*solve(n, can))

Buggy submission (verdict: Runtime Error):
n = int(input())
can = [[[0, 0]] * 101 for _ in range(101)]


def solve(n, can):
    for k in range(n):
        x, y, h = map(int, input().split())
        if k == 0:
            for i in range(101):
                for j in range(101):
                    can[i][j] = h + abs(x - i) + abs(y - j)
        else:
            for i in range(101):
                for j in range(101):
                    if can[i][j] is None:
                        continue
                    gg = h + abs(x - i) + abs(y - j)
                    gh = can[i][j]
                    if gg != gh:
                        can[i][j] = None
    for i in range(101):
        for j in range(101):
            if can[i][j] is None:
                continue
            return i, j, can[i][j]


print(*solve(n, can))
Problem p03256 (python)

Fixed submission:
import sys

sys.setrecursionlimit(200000)


def add_link(a, b):
    la = links[a]
    i, j = [(0, 1), (1, 0)][s[b] == 'B']
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)


def close(v, i):
    j = int(s[v] == 'B')
    for u in links[v][i].copy():
        if not able[u]:
            continue
        links[u][j].discard(v)
        if not links[u][j]:
            able[u] = False
            close(u, j ^ 1)


n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for line in sys.stdin.readlines():
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    add_link(a, b)
    add_link(b, a)

for v in range(n):
    if able[v]:
        continue
    close(v, bool(links[v][1]))

print('Yes' if any(able) else 'No')

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(200000)


def close(v, i):
    j = int(s[v] == 'B')
    for u in links[v][i].copy():
        links[u][j].remove(v)
        if not links[u][j]:
            able[u] = False
            close(u, j ^ 1)


n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    la, lb = links[a], links[b]
    i, j = [(0, 1), (1, 0)][s[b] == 'B']
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)
    i, j = [(0, 1), (1, 0)][s[a] == 'B']
    if not lb[i] and lb[j]:
        able[b] = True
    lb[i].add(a)

for v in range(n):
    if able[v]:
        continue
    close(v, bool(links[v][1]))

print('Yes' if any(able) else 'No')

Buggy submission (verdict: Runtime Error):
def close(v, i):
    j = int(s[v] == 'B')
    for u in links[v][i].copy():
        links[u][j].remove(v)
        if not links[u][j]:
            able[u] = False
            close(u, j ^ 1)


n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    la, lb = links[a], links[b]
    i, j = [(0, 1), (1, 0)][s[b] == 'B']
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)
    i, j = [(0, 1), (1, 0)][s[a] == 'B']
    if not lb[i] and lb[j]:
        able[b] = True
    lb[i].add(a)

for v in range(n):
    if able[v]:
        continue
    close(v, bool(links[v][1]))

print('Yes' if any(able) else 'No')
Problem p03262 (python)

Fixed submission:
n, s = map(int, input().split())
xxx = [abs(s - y) for y in map(int, input().split())]
d = 0
while True:
    xxx = [x for x in xxx if x > 0]
    d = min(xxx)
    xxx = [x % d for x in xxx]
    if all(x == 0 for x in xxx):
        break
print(d)

Buggy submission (verdict: Runtime Error):
n, s = map(int, input().split())
xxx = [abs(s - y) for y in map(int, input().split())]
d = 0
while True:
    d = min(xxx)
    xxx = [x % d for x in xxx]
    if all(x == 0 for x in xxx):
        break
print(d)
Problem p03308 (python)

Fixed submission:
n, *aaa = map(int, open(0).read().split())
print(max(aaa) - min(aaa))

Buggy submission (verdict: Runtime Error):
n, aaa = map(int, open(0).split())
print(max(aaa) - min(aaa))