Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
h, w, k = map(int, readline().split())
s = [readline().rstrip() for _ in range(h)]
ans = [[0] * w for _ in range(h)]
peace = 1
not_strawberry = []
for i in range(h):
    strawberry = 0
    for j in range(w):
        if s[i][j] == '#':
            if strawberry == 1:
                peace += 1
                strawberry = 1
            else:
                strawberry = 1
        ans[i][j] = str(peace)
    if not strawberry:
        not_strawberry.append(i)
    else:
        for j in not_strawberry:
            ans[j] = ans[i]
        peace += 1
i = min(not_strawberry) - 1
for j in not_strawberry:
    ans[j] = ans[i]

print('\n'.join(' '.join(i) for i in ans))


Fixed submission:
import sys

readline = sys.stdin.readline
h, w, k = map(int, readline().split())
s = [readline().rstrip() for _ in range(h)]
ans = [[0] * w for _ in range(h)]
peace = 1
not_strawberry = []
for i in range(h):
    strawberry = 0
    for j in range(w):
        if s[i][j] == '#':
            if strawberry == 1:
                peace += 1
                strawberry = 1
            else:
                strawberry = 1
        ans[i][j] = str(peace)
    if not strawberry:
        not_strawberry.append(i)
    else:
        for j in not_strawberry:
            ans[j] = ans[i]
        not_strawberry = []
        peace += 1
if not_strawberry:
    i = min(not_strawberry) - 1
    for j in not_strawberry:
        ans[j] = ans[i]

print('\n'.join(' '.join(i) for i in ans))
Buggy python submission (verdict: Time Limit Exceeded):
print(sum(range(int(input()))))


Fixed submission:
n = int(input())
print((n - 1) * n // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

n, q = map(int, readline().split())
G = defaultdict(list)
for _ in range(n-1):
    a, b = map(int, readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
count = [0] * n
for _ in range(q):
    p, x = map(int, readline().split())
    count[p-1] += x


def dfs(root, x):
    ans[root] = count[root] + x
    for i in G[root]:
        if ans[i] == -1:
            dfs(i, ans[root])


ans = [-1] * n
dfs(0, 0)
print(*ans)


Fixed submission:
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

n, q = map(int, readline().split())
G = defaultdict(list)
for _ in range(n-1):
    a, b = map(int, readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
count = [0] * n
for _ in range(q):
    p, x = map(int, readline().split())
    count[p-1] += x


def dfs(root, x):
    ans[root] = count[root] + x
    for i in G[root]:
        if ans[i] == -1:
            dfs(i, ans[root])


ans = [-1] * n
dfs(0, 0)
print(*ans)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

S = input()
T = input()

ss = set(list(S))
st = set(list(T))
if not (st <= ss):
    print(-1)
    exit()
alpha = {chr(97+i): [] for i in range(26)}
for i, s in enumerate(S):
    alpha[s].append(i+1)
n = len(S)
now = 0
ans = 0
for t in T:
    if alpha[t][-1] < now:
        ans += (n - now) + alpha[t][0]
        now = alpha[t][0]
    else:
        i = bisect_left(alpha[t], now+1)
        ans += alpha[t][i] - now
        now = alpha[t][i]
print(ans)


Fixed submission:
from bisect import bisect_left

S = input()
T = input()

ss = set(list(S))
st = set(list(T))
if not (st <= ss):
    print(-1)
    exit()
alpha = {chr(97+i): [] for i in range(26)}
for i, s in enumerate(S):
    alpha[s].append(i+1)
n = len(S)
now = 0
ans = 0
for t in T:
    if alpha[t][-1] <= now:
        ans += (n - now) + alpha[t][0]
        now = alpha[t][0]
    else:
        i = bisect_left(alpha[t], now+1)
        ans += alpha[t][i] - now
        now = alpha[t][i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 10 ** 9 + 7
dp = [0] * 13
dp[0] = 1
for s in S:
    d = [0] * 13
    if s == '?':
        for i in range(13):
            for j in range(10):
                d[(10*i + j) % 13] += dp[i]
    else:
        for i in range(13):
            d[(10*i + int(s)) % 13] += dp[i]
    dp = [x % mod for x in d]
print(d[5] % mod)


Fixed submission:
S = input()
mod = 10 ** 9 + 7
dp = [0] * 13
dp[0] = 1
for s in S:
    d = [0] * 13
    if s == '?':
        for i in range(13):
            for j in range(10):
                d[(10*i + j) % 13] += dp[i]
    else:
        for i in range(13):
            d[(10*i + int(s)) % 13] += dp[i]
    dp = [x % mod for x in d]
print(d[5] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

read = sys.stdin.read

n, m, *a = map(int, read().split())
mod = 1000000007
dp = [0] * (n+1)
dp[0] = 1
if a and a[0] == 1:
    dp[1] = 0
    a.pop(0)
else:
    dp[1] = 1
for i in range(2, n+1):
    if a and i == a[0]:
        a.pop(0)
        dp[i] == 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])


Fixed submission:
import sys

read = sys.stdin.read

n, m, *a = map(int, read().split())
mod = 1000000007
dp = [0] * (n+1)
dp[0] = 1
if a and a[0] == 1:
    dp[1] = 0
    a.pop(0)
else:
    dp[1] = 1
for i in range(2, n+1):
    if a and i == a[0]:
        a.pop(0)
        dp[i] == 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
import sys

read = sys.stdin.read

n, m, *a = map(int, read().split())
mod = 1000000007
dp = [0] * (n+1)
dp[0] = 1
if a[0] == 1:
    dp[1] = 0
    a.pop(0)
else:
    dp[1] = 1
for i in range(2, n+1):
    if a and i == a[0]:
        a.pop(0)
        dp[i] == 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])


Fixed submission:
import sys

read = sys.stdin.read

n, m, *a = map(int, read().split())
mod = 1000000007
dp = [0] * (n+1)
dp[0] = 1
if a and a[0] == 1:
    dp[1] = 0
    a.pop(0)
else:
    dp[1] = 1
for i in range(2, n+1):
    if a and i == a[0]:
        a.pop(0)
        dp[i] == 0
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
h, w = map(int, readline().split())
grid = [readline() for _ in range(h)]
light = [[0] * w for _ in range(h)]

# row
for i in range(h):
    start = -1
    for j in range(w):
        if grid[i][j] == '.' and start == -1:
            start = j
        elif grid[i][j] == '#' and start != -1:
            length = j - start
            light[i][start:j] = [length] * length
            start = -1
    if start != -1:
        length = w - start
        light[i][start:w] = [length] * length
# column
for i in range(w):
    start = -1
    for j in range(h):
        if grid[j][i] == '.' and start == -1:
            start = j
        elif grid[j][i] == '#' and start != -1:
            length = j - start
            for k in range(start, j):
                light[k][i] += length
            start = -1
    if start != -1:
        length = h - start
        for k in range(start, h):
            light[k][i] += length
ans = max(max(row) for row in light)
print(ans-1)


Fixed submission:
import sys

readline = sys.stdin.readline
h, w = map(int, readline().split())
grid = [readline() for _ in range(h)]
light = [[0] * w for _ in range(h)]

# row
for i in range(h):
    start = -1
    for j in range(w):
        if grid[i][j] == '.' and start == -1:
            start = j
        elif grid[i][j] == '#' and start != -1:
            length = j - start
            light[i][start:j] = [length] * length
            start = -1
    if start != -1:
        length = w - start
        light[i][start:w] = [length] * length
# column
for i in range(w):
    start = -1
    for j in range(h):
        if grid[j][i] == '.' and start == -1:
            start = j
        elif grid[j][i] == '#' and start != -1:
            length = j - start
            for k in range(start, j):
                light[k][i] += length
            start = -1
    if start != -1:
        length = h - start
        for k in range(start, h):
            light[k][i] += length
ans = max(max(row) for row in light)
print(ans-1)
Buggy python submission (verdict: Runtime Error):
s = input()
front = int(s[:2])
back = int(s[2:])
if 0 in (front, back):
    ans = 'NA'
elif 0 < front < 13 and 0 < back < 13:
    ans = 'AMBIGUOUS'
elif 0 < front < 13:
    ans = 'MMYY'
elif 0 < back < 13:
    ans = 'YYMM'
print(ans)


Fixed submission:
s = input()
front = int(s[:2])
back = int(s[2:])
if 0 < front < 13 and 0 < back < 13:
    ans = 'AMBIGUOUS'
elif 0 < front < 13:
    ans = 'MMYY'
elif 0 < back < 13:
    ans = 'YYMM'
else:
    ans = 'NA'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N - r*R - g*G) / B
        if b >= 0 and b.is_integer():
            ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N - r*R - g*G) / B
        if b >= 0 and b.is_integer():
            ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N - r*R - g*G) / B
        if b >= 0 and b.is_integer():
            ans += 1
print(ans)


Fixed submission:
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N - r*R - g*G) / B
        if b >= 0 and b.is_integer():
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
from math import gcd

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


@lru_cache(None)
def func(*x):
    n = len(x)
    if n == 2:
        return gcd(x[0], x[1])
    elif n == 1:
        return x[0]
    return gcd(func(*x[:n//2]), func(*x[n//2:]))


ans = 0
for i in range(N):
    tmp = A[i]
    A[i] = A[i+1 if i < N-1 else 0]
    ans = max(ans, func(*A))
    A[i] = tmp
print(ans)

Fixed submission:
from itertools import accumulate
from math import gcd

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

l = list(accumulate(A[:-1], gcd, initial=0))
r = list(accumulate(A[::-1], gcd, initial=0))
print(max(gcd(l[i], r[N-i-1]) for i in range(N)))
Buggy python submission (verdict: Runtime Error):
from re import sub

n = int(input())
s = input()
k = int(input())

print(sub(f'[^{s[k-1]}]', '*', s))


Fixed submission:
from re import sub

n = int(input())
s = input()
k = int(input())

print(sub('[^{}]'.format(s[k-1]), '*', s))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
n, q = map(int, readline().split())
s = readline().rstrip()
ac = [False] * (n - 1)
for i, x in enumerate(zip(s, s[1:])):
    if x == ('A', 'C'):
        ac[i] = True
for _ in range(q):
    l, r = map(int, readline().split())
    print(sum(ac[l-1:r-1]))


Fixed submission:
import sys
from itertools import accumulate

readline = sys.stdin.readline
n, q = map(int, readline().split())
s = readline().rstrip()
ac = [False] * (n - 1)
for i, x in enumerate(zip(s, s[1:])):
    if x == ('A', 'C'):
        ac[i] = True
ac = [0] + list(accumulate(ac))
for _ in range(q):
    l, r = map(int, readline().split())
    print(ac[r-1] - ac[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline
n, q = map(int, readline().split())
s = readline().rstrip()
ac = [False] * (n - 1)
for i, x in enumerate(zip(s, s[1:])):
    if x == ('A', 'C'):
        ac[i] = True
for _ in range(q):
    l, r = map(int, readline().split())
    print(sum(ac[l-1:r-1]))


Fixed submission:
import sys
from itertools import accumulate

readline = sys.stdin.readline
n, q = map(int, readline().split())
s = readline().rstrip()
ac = [False] * (n - 1)
for i, x in enumerate(zip(s, s[1:])):
    if x == ('A', 'C'):
        ac[i] = True
ac = [0] + list(accumulate(ac))
for _ in range(q):
    l, r = map(int, readline().split())
    print(ac[r-1] - ac[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def solve():
    N, K, *H = map(int, sys.stdin.read().split())
    dp = [10**10] * N
    dp[0] = 0
    for i, h in enumerate(H):
        dp_i = dp[i]
        for k, dp_i_k in enumerate(dp[i+1:i+K+1], start=1):
            if i+k > N-1:
                break
            tmp_dp = dp_i + abs(h - H[i+k])
            if dp_i_k > tmp_dp:
                dp[i+k] = tmp_dp
    return dp[-1]


if __name__ == "__main__":
    answer = solve()
    print(answer)


Fixed submission:
import sys


def solve():
    N, K, *H = map(int, sys.stdin.read().split())
    dp = [0] * N
    for i in range(1, N):
        s = i-K if i-K > 0 else 0
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(s, i))
    return dp[-1]


if __name__ == "__main__":
    answer = solve()
    print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def solve():
    N, K, *H = map(int, sys.stdin.read().split())
    dp = [10**10] * N
    dp[0] = 0
    for i, h in enumerate(H):
        for k in range(1, K+1):
            if i+k > N-1:
                break
            tmp_dp = dp[i] + abs(h - H[i+k])
            if dp[i+k] > tmp_dp:
                dp[i+k] = tmp_dp
    return dp[-1]


if __name__ == "__main__":
    answer = solve()
    print(answer)


Fixed submission:
import sys


def solve():
    N, K, *H = map(int, sys.stdin.read().split())
    dp = [0] * N
    for i in range(1, N):
        s = i-K if i-K > 0 else 0
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(s, i))
    return dp[-1]


if __name__ == "__main__":
    answer = solve()
    print(answer)
Buggy python submission (verdict: Runtime Error):
import sys


def solve():
    readline = sys.stdin.readline
    N, W = map(int, readline().split())
    WV = (map(int, readline().split()) for _ in range(N))
    dp = [0] * (W+1)
    for w, v in WV:
        for i in range(W, w-1, -1):
            tmp_dp = dp[i-w] + v
            if dp[i] < tmp_dp:
                dp[i] = tmp_dp
    return max(dp)


if __name__ == "__main__":
    answer = solve()
    print(answer)


Fixed submission:
import sys


def solve():
    readline = sys.stdin.readline
    N, W = map(int, readline().split())
    WV = (map(int, readline().split()) for _ in range(N))
    INF = 10 ** 15
    MAX_V = 100 * 10**3 + 10
    dp = [INF] * MAX_V
    dp[0] = 0
    for w, v in WV:
        for i in range(MAX_V-1, v-1, -1):
            tmp_dp = dp[i-v] + w
            if dp[i] > tmp_dp:
                dp[i] = tmp_dp
    for v, w in enumerate(dp):
        if w <= W:
            ans = v
    return ans


if __name__ == "__main__":
    answer = solve()
    print(answer)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
burger  = [1] * (N+1)
patty = [1] * (N+1)
for i in range(1, N+1):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if burger[level-1] + 1 <= x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)
    if level == 0:
        return 0


print(func(N, X))


Fixed submission:
N, X = map(int, input().split())
burger  = [1] * N
patty = [1] * N
for i in range(1, N):
    burger[i] = burger[i-1] * 2 + 3
    patty[i] = patty[i-1] * 2 + 1


def func(level, x):
    if level == 0:
        return 0 if x <= 0 else 1
    if burger[level-1] + 1 < x:
        return func(level-1, x-burger[level-1]-2) + patty[level-1] + 1
    else:
        return func(level-1, x-1)


print(func(N, X))
Buggy python submission (verdict: Runtime Error):
n = int(input())
t, a =map(int, input().split())
h = list(map(int, input().split()))
d_degree = 100000j
ans = 0
for i in range(n):
    degree = t - h[i]*0.006
    if d_degree > abs(a - degree):
        d_degree = abs(a - degree)
        ans = i+1
print(ans)


Fixed submission:
n = int(input())
t, a =map(int, input().split())
h = list(map(int, input().split()))
d_degree = 100000
ans = 0
for i in range(n):
    degree = t - h[i]*0.006
    if d_degree > abs(a - degree):
        d_degree = abs(a - degree)
        ans = i+1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
import sys

readline = sys.stdin.readline
n, m = map(int, readline().split())
ken = [list() for _ in range(n)]
PY = []
for _ in range(m):
    p, y = map(int, readline().split())
    PY.append((p, y))
    ken[p-1].append(y)
for i in range(n):
    ken[i].sort()
for p, y in PY:
    print(str(p).zfill(6) + str(ken[p-1].index(y)+1).zfill(6)) 


Fixed submission:

from bisect import bisect_right
import sys

readline = sys.stdin.readline
n, m = map(int, readline().split())
ken = [list() for _ in range(n)]
PY = []
for _ in range(m):
    p, y = map(int, readline().split())
    PY.append((p, y))
    ken[p-1].append(y)
for i in range(n):
    ken[i].sort()

for p, y in PY:
    print(str(p).zfill(6) + str(bisect_right(ken[p-1],y)).zfill(6))
Buggy python submission (verdict: Runtime Error):
s = input()
ans = 'WA'
if s[0] == 'A' and s[2:-1].count('C') == 1\
   s.replace('A', '').replace('C', '').islower():
  ans = 'AC'
print(ans)

Fixed submission:
s = input()
ans = 'WA'
if s[0] == 'A' and s[2:-1].count('C') == 1\
   and s.replace('A', '').replace('C', '').islower():
  ans = 'AC'
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()
ans = 'WA'
if s[0] == 'A' and s[2:-1].count('C') == 1\
   s.replace('A', '').replace('C', '').islower():
  ans = 'AC'
print(ans)nn

Fixed submission:
s = input()
ans = 'WA'
if s[0] == 'A' and s[2:-1].count('C') == 1\
   and s.replace('A', '').replace('C', '').islower():
  ans = 'AC'
print(ans)
Buggy python submission (verdict: Runtime Error):
a = map(int, input().split())
a.sort()
ans = 0
for i, j in zip(a, a[1:]):
  ans += abs(j - i)
print(ans)

Fixed submission:
a = sorted(map(int, input().split()))
ans = 0
for i, j in zip(a, a[1:]):
  ans += abs(j - i)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
print(sum(x-1 for x in s))

Fixed submission:
n = int(input())
a = map(int, input().split())
print(sum(x-1 for x in a))
Buggy python submission (verdict: Time Limit Exceeded):
d, n = map(int, input().split())
cnt = 0
i = 0
while cnt < n:
  i += 1
  div, mod = divmod(i, 100**d)
  if mod == 0 and div == d:
    cnt += 1
print(i)


Fixed submission:
d, n = map(int, input().split())
cnt = 0
i = 0
while cnt < n:
  i += 1
  if i % 100**d == 0 and i % 100**(d+1) != 0:
    cnt += 1
print(i)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N < 1000:
  print('ABC{:03}'.format(N))
else:
  print('ABD{:03}'.format(str(N)[1:]))


Fixed submission:
N = int(input())
print('ABC' if N < 1000 else 'ABD')
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())
print(max(a-b, a+b, a*b))

Fixed submission:
a, b = map(int, input().split())
print(max(a-b, a+b, a*b))
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input())
print('Yes' if abs(a-c) <= d or max(abs(a-b), abs(b-c)) <= d else 'No')

Fixed submission:
a, b, c, d = map(int, input().split())
print('Yes' if abs(a-c) <= d or max(abs(a-b), abs(b-c)) <= d else 'No')
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque

readline = sys.stdin.readline
H, W = map(int, readline().split())
S = [['#'] * (W+2)] + [['#'] + list(readline().rstrip()) + ['#'] for _ in range(H)] + [['#'] * (W+2)] 
black = sum(row.count('#') for row in S) - 2*(W+2) - 2*H

# bfs
q = deque([(1, 1)])
S[1][1] = 1
direction = ((0, 1), (1, 0), (0, -1), (-1, 0))
while q:
    x, y = q.popleft()
    d = S[x][y]
    for dx, dy in direction:
        # print(x+dx, y+dy, S[x+dx][y+dy])
        if S[x+dx][y+dy] == '.':
            S[x+dx][y+dy] = d + 1
            q.append((x+dx, y+dy))
ans = -1
if S[H][W] != '#':
    ans = H*W - S[H][W] - black
print(ans)


Fixed submission:
import sys
from collections import deque

readline = sys.stdin.readline
H, W = map(int, readline().split())
S = [['#'] * (W+2)] + [['#'] + list(readline().rstrip()) + ['#'] for _ in range(H)] + [['#'] * (W+2)] 
black = sum(row.count('#') for row in S) - 2*(W+2) - 2*H

# bfs
q = deque([(1, 1)])
S[1][1] = 1
direction = ((0, 1), (1, 0), (0, -1), (-1, 0))
while q:
    x, y = q.popleft()
    d = S[x][y]
    for dx, dy in direction:
        # print(x+dx, y+dy, S[x+dx][y+dy])
        if S[x+dx][y+dy] == '.':
            S[x+dx][y+dy] = d + 1
            q.append((x+dx, y+dy))
ans = -1
if S[H][W] != '.':
    ans = H*W - S[H][W] - black
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(N):
    if i + 1 == P[i]:
        ans += 1
        P[i+1] = P[i]
print(ans)


Fixed submission:
N = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    if i + 1 == P[i]:
        ans += 1
        P[i+1] = P[i]
if N == P[-1]:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
import sys

lcm = lambda x, y : x*y // gcd(x, y)
N, *T = map(int, sys.stdin.read().split())
ans = reduce(lcm, T)
print(ans)


Fixed submission:
from fractions import gcd
from functools import reduce
import sys

lcm = lambda x, y : x*y // gcd(x, y)
N, *T = map(int, sys.stdin.read().split())
ans = reduce(lcm, T)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]

a = A[0]
B = A[:]
B.sort()

for i in range(1, n):
    C = [a, A[i]]
    for j in range(2, n):
        C.append(C[j - 2] ^ C[j - 1])
    if C[-2] ^ C[-1] == C[0]:
        C.sort()
        if C == B:
            print('Yes')
            exit()

print('No')

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

S = 0

for a in A:
    S ^= a

print('Yes' if S == 0 else 'No')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]

a = A[0]
B = A[:]
B.sort()

for i in range(1, n):
    C = [a, A[i]]
    for j in range(2, n):
        C.append(C[j - 2] ^ C[j - 1])
    if C[-2] ^ C[-1] == C[0]:
        C.sort()
        if C == B:
            print('Yes')
            exit()

print('No')

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]

S = 0

for a in A:
    S ^= a

print('Yes' if S == 0 else 'No')
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for i in range(m)]

if m % 2 == 1:
    print(-1)
    exit()

E = [[] for i in range(n + 1)]
used_e = [False] * m
ans = []

for i, (a, b) in enumerate(A):
    E[a].append((b, i))
    E[b].append((a, i))

used = [False] * (n + 1)

def dfs(v):
    if used[v]:
        return
    used[v] = True
    cnt = 0

    for to, i in E[v]:
        dfs(to)
        if not used_e[i]:
            cnt += 1

    if cnt % 2 == 1:
        cnt -= 1

    for to, i in E[v]:
        if not used_e[i] and cnt > 0:
            ans.append((v, to))
            used_e[i] = True

dfs(1)

for a in ans:
    print(*a)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for i in range(m)]

if m % 2 == 1:
    print(-1)
    exit()

E = [[] for i in range(n + 1)]
used_e = [False] * m
ans = []

for i, (a, b) in enumerate(A):
    E[a].append((b, i))
    E[b].append((a, i))

used = [False] * (n + 1)

def dfs(prev, v):
    if used[v]:
        return
    used[v] = True
    cnt = 0

    for to, i in E[v]:
        dfs(v, to)
        if not used_e[i]:
            cnt += 1

    for to, i in E[v]:
        if cnt % 2 == 1 and to == prev:
            continue
        if not used_e[i]:
            ans.append((v, to))
            used_e[i] = True

dfs(0, 1)

for a in ans:
    print(*a)