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

n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
    e.append((a - 1, b - 1))
c = list(map(int, input().split()))
c.sort(reverse=True)

def point(x, prev, turn=0):
    if turn > n:
        return
    dp[x] = c[n - dp.count(0)]
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

for i in range(n):
    if len(edge[i]) > 1:
        continue
    else:
        dp = [0] * n
        point(i, -1)
        break

ans = sum(c) - max(c)

print(ans)
print(" ".join(map(str, dp)))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
c = list(map(int, input().split()))
c.sort(reverse=True)

num = 0
def point(x, prev, turn=0):
    global num
    if turn > n:
        return
    dp[x] = c[num]
    num += 1
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

for i in range(n):
    if len(edge[i]) > 1:
        continue
    else:
        dp = [0] * n
        point(i, -1)
        break

ans = sum(c) - max(c)

print(ans)
print(" ".join(map(str, dp)))

Buggy python submission (verdict: Runtime Error):
n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
    e.append((a - 1, b - 1))
c = list(map(int, input().split()))
c.sort(reverse=True)

def point(x, prev, turn=0):
    if turn > n:
        return
    dp[x] = c[n - dp.count(0)]
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

ans = 0
for i in range(n):
    dp = [0] * n
    point(i, -1)

    m = 0
    for a, b in e:
        m += min(dp[a], dp[b])
    if m > ans:
        ans = m
        d = dp

print(ans)
print(" ".join(map(str, d)))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

n = int(input())
edge = [[] for _ in range(n)]
e = []
for i in range(n - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
c = list(map(int, input().split()))
c.sort(reverse=True)

num = 0
def point(x, prev, turn=0):
    global num
    if turn > n:
        return
    dp[x] = c[num]
    num += 1
    for i in edge[x]:
        if dp[i] != 0:
            continue
        if i == prev:
            continue
        else:
            point(i, x, turn + 1)
    return

for i in range(n):
    if len(edge[i]) > 1:
        continue
    else:
        dp = [0] * n
        point(i, -1)
        break

ans = sum(c) - max(c)

print(ans)
print(" ".join(map(str, dp)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

n, q = map(int, input().split())
cons = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

cons.sort(key=lambda x: x[2])
for i in range(n):
    cons[i][0] -= cons[i][2]
    cons[i][1] -= cons[i][2]

ans = [-1] * q
for i in range(n):
    s = bisect.bisect_left(d, cons[i][0])
    t = bisect.bisect_left(d, cons[i][1])
    while s < t:
        if ans[s] != -1:
            s += 1
        else:
            ans[s] = cons[i][2]
            s += 1
print(*ans, sep="\n")

Fixed submission:
import sys
import bisect
input = sys.stdin.readline

n, q = map(int, input().split())
cons = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

cons.sort(key=lambda x: x[2])
for i in range(n):
    cons[i][0] -= cons[i][2]
    cons[i][1] -= cons[i][2]

ans = [-1] * q
l = [-1] * q
for i in range(n):
    s = bisect.bisect_left(d, cons[i][0])
    t = bisect.bisect_left(d, cons[i][1])
    while s < t:
        if l[s] != -1:
            s = l[s]
        else:
            ans[s] = cons[i][2]
            l[s] = t
            s += 1
print(*ans, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(1 << n):
    value = 0
    cost = 0
    for j in range(n):
        if i >> j & 1:
            value += v[j]
            cost += c[j]
    ans = max(ans, value - cost)

print(ans)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    if v[i] > c[i]:
        ans += v[i] - c[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
sr = s[::-1]

if s == "." * n or s == "#" * n:
    print(0)
else:
    ans = n
    for i in range(n):
        num = s[:i].count("#") + s[i:].count(".")
        ans = min(num, ans)
    print(ans)

Fixed submission:
n = int(input())
s = input()
sr = s[::-1]

ans = s.count(".")
num = ans
for i in range(n):
    if s[i] == ".":
        num -= 1
    else:
        num += 1
    ans = min(num, ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

if s == "." * n:
    print(0)
else:
    black = s.index("#")
    white = [i for i, x in enumerate(s) if x == "."]
    wb = [i for i, x in enumerate(s[black:]) if x == "."]
    bw = [i for i, x in enumerate(s[:white[-1]]) if x == "#"]
    print(min(len(wb), len(bw)))

Fixed submission:
n = int(input())
s = input()
sr = s[::-1]

ans = s.count(".")
num = ans
for i in range(n):
    if s[i] == ".":
        num -= 1
    else:
        num += 1
    ans = min(num, ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

if s == "." * n:
    print(0)
else:
    black = [i for i, x in enumerate(s) if x == "#"]
    wb = [i for i, x in enumerate(s[black[0]:]) if x == "."]
    bw = [i for i, x in enumerate(s[:wb[-1]]) if x == "#"]
    print(min(len(wb), len(bw)))

Fixed submission:
n = int(input())
s = input()
sr = s[::-1]

ans = s.count(".")
num = ans
for i in range(n):
    if s[i] == ".":
        num -= 1
    else:
        num += 1
    ans = min(num, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = []
for i in range(x):
  for j in range(y):
    ab.append(a[i] + b[j])
ab = sorted(ab, reverse=True)

abc = []
for i in range(min(k, len(ab))):
  for j in range(z):
    abc.append(ab[i] + c[j])
abc = sorted(abc, reverse=True)

for i in range(k):
  print(abc[i])


Fixed submission:
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = []
for i in range(x):
  for j in range(y):
    ab.append(a[i] + b[j])
ab = sorted(ab, reverse=True)

abc = []
for i in range(min(k, len(ab))):
  for j in range(z):
    abc.append(ab[i] + c[j])
abc = sorted(abc, reverse=True)

for i in range(k):
  print(abc[i])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 1)

dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1)

num = []
k = n
for i in range(dp[n]):
    for j in a:
        if dp[k - match[j - 1]] == dp[k] - 1:
            num.append(j)
            k -= match[j - 1]
            break
print("".join(map(str, num)))

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (n + 1)

dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i < match[j - 1]:
            continue
        else:
            dp[i] = max(dp[i], dp[i - match[j - 1]] + 1)

num = []
k = n
for i in range(dp[n]):
    for j in a:
        if k >= match[j - 1]:
            if dp[k - match[j - 1]] == dp[k] - 1:
                num.append(j)
                k -= match[j - 1]
                break
print("".join(map(str, num)))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 4 * n] * n

if k >= n:
    ans = abs(h[0] - h[n - 1])
else:
    dp[0] = 0
    for i in range(n - 1):
        j = 1
        while i + j < n:
            if j == k + 1:
                break
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
            j += 1
    ans = dp[n - 1]
print(ans)

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 4 * n] * n

if k >= n:
    ans = abs(h[0] - h[n - 1])
else:
    dp[0] = 0
    for i in range(n - 1):
        j = 1
        while i + j < n:
            if j == k + 1:
                break
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
            j += 1
    ans = dp[n - 1]
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n, W = map(int, input().split())
dp = np.zeros((n + 1, W + 1))

for i in range(n):
    w, v = map(int, input().split())
    dp[i + 1] = dp[i]
    if w <= W:
        dp[i + 1][w:] = np.maximum(dp[i][:W - w + 1] + v, dp[i][w:])
print(int(dp[n][W]))

Fixed submission:
n, W = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(n + 1)]

dp[0][W] = 0
for i in range(n):
    w, v = map(int, input().split())
    for j in range(W + 1):
        if j >= w:
            dp[i + 1][j] = max(dp[i][j - w] + v, dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][W])

Buggy python submission (verdict: Time Limit Exceeded):
n, W = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(n + 1)]

dp[0][W] = 0
for i in range(n):
    w, v = map(int, input().split())
    for j in range(W + 1):
        if j >= w:
            dp[i + 1][j] = max(dp[i][j - w] + v, dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][W])

Fixed submission:
n, W = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(n + 1)]

dp[0][W] = 0
for i in range(n):
    w, v = map(int, input().split())
    for j in range(W + 1):
        if j >= w:
            dp[i + 1][j] = max(dp[i][j - w] + v, dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][W])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
s_num = len(s)
t_num = len(t)
dp = [[""] * (t_num + 1) for _ in range(s_num + 1)]

for i in range(s_num):
    for j in range(t_num):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + s[i], dp[i + 1][j], dp[i][j + 1], key=len)
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1], key=len)
print(dp[s_num][t_num])

Fixed submission:
s = input()
t = input()
s_num = len(s)
t_num = len(t)
dp = [[0] * (t_num + 1) for _ in range(s_num + 1)]

for i in range(s_num):
    for j in range(t_num):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
ans = ""
i = s_num
j = t_num
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    elif dp[i][j] == dp[i - 1][j - 1] + 1:
        ans = s[i - 1] + ans
        i -= 1
        j -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
s_num = len(s)
t_num = len(t)
dp = [[""] * (t_num + 1) for _ in range(s_num + 1)]

for i in range(s_num):
    for j in range(t_num):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + s[i], dp[i + 1][j], dp[i][j + 1], key=len)
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1], key=len)
print(dp[s_num][t_num])

Fixed submission:
s = input()
t = input()
s_num = len(s)
t_num = len(t)
dp = [[0] * (t_num + 1) for _ in range(s_num + 1)]

for i in range(s_num):
    for j in range(t_num):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
ans = ""
i = s_num
j = t_num
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    elif dp[i][j] == dp[i - 1][j - 1] + 1:
        ans = s[i - 1] + ans
        i -= 1
        j -= 1
print(ans)
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
dp[1][1] = p[0]
for i in range(n):
    dp[i + 1][0] = dp[i][0] * (1 - p[i])

for i in range(1, n):
    for j in range(i):
        dp[i + 1][j + 1] = dp[i][j] * p[i] + dp[i][j + 1] * (1 - p[i])
    dp[i + 1][i + 1] = dp[i][i] * p[i]

print(sum(dp[n][(n + 1) // 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
dp[1][1] = p[0]
for i in range(n):
    dp[i + 1][0] = dp[i][0] * (1 - p[i])

for i in range(1, n):
    for j in range(i):
        dp[i + 1][j + 1] = dp[i][j] * p[i] + dp[i][j + 1] * (1 - p[i])
    dp[i + 1][i + 1] = dp[i][i] * p[i]

print(sum(dp[n][(n + 1) // 2:]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * n for _ in range(n)]

for i in range(n):
    dp[i][i] = a[i]
for l in range(1, n):
    for s in range(n - l):
        dp[s][s + l] = max(a[s] - dp[s + 1][s + l], a[s + l] - dp[s][s + l - 1])
print(dp[0][n - 1])

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * n for _ in range(n)]

for i in range(n):
    dp[i][i] = a[i]
for l in range(1, n):
    for s in range(n - l):
        dp[s][s + l] = max(a[s] - dp[s + 1][s + l], a[s + l] - dp[s][s + l - 1])
print(dp[0][n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(k + 1)]

for i in range(n + 1):
    dp[0][i] = 1
for i in range(a[0] + 1):
    dp[i][1] = 1

for i in range(1, k + 1):
    for j in range(2, n + 1):
        for w in range(min(a[j - 1], i) + 1):
            dp[i][j] += dp[i - w][j - 1]
        dp[i][j] %= (10 ** 9 + 7)
print(dp[k][n])

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
dp = [[0] * (k + 1) for _ in range(n + 1)]

for i in range(n + 1):
    dp[i][0] = 1
for i in range(a[0] + 1):
    dp[1][i] = 1

for i in range(2, n + 1):
    for j in range(1, k + 1):
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
        if j > a[i - 1]:
            dp[i][j] -= (dp[i - 1][j - a[i - 1] - 1]) % mod
        dp[i][j] %= mod
print(dp[n][k])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = np.zeros((k + 1, n + 1))

for i in range(n + 1):
    dp[0][i] = 1
for i in range(a[0] + 1):
    dp[i][1] = 1

for i in range(1, k + 1):
    for j in range(2, n + 1):
        dp[i][j] = sum(dp[max(0, i - a[j - 1]):i + 1, j - 1]) % (10 ** 9 + 7)
print(int(dp[k][n]))

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
dp = [[0] * (k + 1) for _ in range(n + 1)]

for i in range(n + 1):
    dp[i][0] = 1
for i in range(a[0] + 1):
    dp[1][i] = 1

for i in range(2, n + 1):
    for j in range(1, k + 1):
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
        if j > a[i - 1]:
            dp[i][j] -= (dp[i - 1][j - a[i - 1] - 1]) % mod
        dp[i][j] %= mod
print(dp[n][k])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(500000)

n = int(input())
mod = 10 ** 9 + 7
node = [[] for _ in range(n)]
memo_f, memo_g = [0] * n, [0] * n
for i in range(n - 1):
    x, y = map(int, input().split())
    node[x - 1].append(y - 1)
    node[y - 1].append(x - 1)

def f(x, prev):
    if memo_f[x]:
        return memo_f[x]
    memo_f[x] = 1
    for i in node[x]:
        if i == prev:
            continue
        memo_f[x] = (memo_f[x] * g(i, x)) % mod
    memo_f[x] = (memo_f[x] + g(x, prev)) % mod
    return memo_f[x]

def g(x, prev):
    if memo_g[x]:
        return memo_g[x]
    memo_g[x] = 1
    for i in node[x]:
        if i == prev:
            continue
        memo_g[x] = (memo_g[x] * f(i, x)) % mod
    return memo_g[x]

print(f(0, -1))

Fixed submission:
import sys
sys.setrecursionlimit(500000)

n = int(input())
mod = 10 ** 9 + 7
node = [[] for _ in range(n)]
memo_f, memo_g = [0] * n, [0] * n
for i in range(n - 1):
    x, y = map(int, input().split())
    node[x - 1].append(y - 1)
    node[y - 1].append(x - 1)

def f(x, prev):
    if memo_f[x]:
        return memo_f[x]
    memo_f[x] = 1
    for i in node[x]:
        if i == prev:
            continue
        memo_f[x] = (memo_f[x] * g(i, x)) % mod
    memo_f[x] = (memo_f[x] + g(x, prev)) % mod
    return memo_f[x]

def g(x, prev):
    if memo_g[x]:
        return memo_g[x]
    memo_g[x] = 1
    for i in node[x]:
        if i == prev:
            continue
        memo_g[x] = (memo_g[x] * f(i, x)) % mod
    return memo_g[x]

print(f(0, -1))

Buggy python submission (verdict: Runtime Error):
n = int(input())
mod = 10 ** 9 + 7
node = [[] for _ in range(n)]
for i in range(n - 1):
    x, y = map(int, input().split())
    node[x - 1].append(y - 1)
    node[y - 1].append(x - 1)

def f(x, prev):
    cnt = 1
    for i in node[x]:
        if i != prev:
            cnt *= g(i, x)
            cnt %= mod
    return g(x, prev) + cnt

def g(x, prev):
    cnt = 1
    for i in node[x]:
        if i != prev:
            cnt *= f(i, x)
            cnt %= mod
    return cnt

print(f(0, -1))

Fixed submission:
import sys
sys.setrecursionlimit(500000)

n = int(input())
mod = 10 ** 9 + 7
node = [[] for _ in range(n)]
memo_f, memo_g = [0] * n, [0] * n
for i in range(n - 1):
    x, y = map(int, input().split())
    node[x - 1].append(y - 1)
    node[y - 1].append(x - 1)

def f(x, prev):
    if memo_f[x]:
        return memo_f[x]
    memo_f[x] = 1
    for i in node[x]:
        if i == prev:
            continue
        memo_f[x] = (memo_f[x] * g(i, x)) % mod
    memo_f[x] = (memo_f[x] + g(x, prev)) % mod
    return memo_f[x]

def g(x, prev):
    if memo_g[x]:
        return memo_g[x]
    memo_g[x] = 1
    for i in node[x]:
        if i == prev:
            continue
        memo_g[x] = (memo_g[x] * f(i, x)) % mod
    return memo_g[x]

print(f(0, -1))
Buggy python submission (verdict: Runtime Error):
n = int(input())
pyr = []
for i in range(n):
    x, y, h = map(int, input().split())
    if h != 0:
        pyr.append((x, y, h))

if len(pyr) == 1:
    print(*pyr[0])
    exit()

for i in range(101):
    for j in range(101):
        cx, cy = (i, j)
        h_list = []
        for k in range(n):
            x, y, h = pyr[k]
            h_list.append(h + abs(x - cx) + abs(y - cy))
        if len(set(h_list)) != 1:
            continue
        else:
            print(cx, cy, h_list[0])
            exit()



Fixed submission:
n = int(input())
pyr = []
for i in range(n):
    x, y, h = map(int, input().split())
    if h != 0:
        pyr.append((x, y, h))

if len(pyr) == 1:
    print(*pyr[0])
    exit()

for i in range(101):
    for j in range(101):
        cx, cy = (i, j)
        h_list = []
        for k in range(len(pyr)):
            x, y, h = pyr[k]
            h_list.append(h + abs(x - cx) + abs(y - cy))
        if len(set(h_list)) != 1:
            continue
        else:
            print(cx, cy, h_list[0])
            exit()

Buggy python submission (verdict: Runtime Error):
n = int(input())
pyr = []
for i in range(n):
    x, y, h = map(int, input().split())
    if h != 0:
        pyr.append((x, y, h))

if len(pyr) == 1:
    print(*pyr[0])
    exit()

for i in range(101):
    for j in range(101):
        cx, cy = (i, j)
        h_list = []
        for k in range(n):
            x, y, h = pyr[k]
            if h != 0:
                h_list.append(h + abs(x - cx) + abs(y - cy))
        if len(set(h_list)) != 1:
            continue
        else:
            print(cx, cy, h_list[0])
            exit()


Fixed submission:
n = int(input())
pyr = []
for i in range(n):
    x, y, h = map(int, input().split())
    if h != 0:
        pyr.append((x, y, h))

if len(pyr) == 1:
    print(*pyr[0])
    exit()

for i in range(101):
    for j in range(101):
        cx, cy = (i, j)
        h_list = []
        for k in range(len(pyr)):
            x, y, h = pyr[k]
            h_list.append(h + abs(x - cx) + abs(y - cy))
        if len(set(h_list)) != 1:
            continue
        else:
            print(cx, cy, h_list[0])
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ch = n - 1
for i in range(n):
  ch = min(ch, sum(x == "W" for x in s[:i]) + sum(x == "E" for x in s[i + 1:]))
print(ch)

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

w = [0] * n
e = [0] * n

cnt_w = 0
cnt_e = 0
for i in range(n):
  if s[i] == "W":
    cnt_w += 1
    w[i] = cnt_w
    e[i] = cnt_e
  else:
    w[i] = cnt_w
    cnt_e += 1
    e[i] = cnt_e
    
ch = n - 1
for i in range(n):
  if i >= 1:
    ch = min(ch, w[i - 1] + e[-1] - e[i])
  else:
    ch = min(ch, e[-1] - e[0])
print(ch)
Buggy python submission (verdict: Runtime Error):
nt = len(t)

if ns < nt:
    print("UNRESTORABLE")
else:
    for i in range(ns - nt + 1):
        if all([s[i + j] == "?" or s[i + j] == t[j] for j in range(nt)]):
            ans = s[:i] + t + s[i + nt:]
            ans = ans.replace("?", "a")
            print(ans)
            exit()
print("UNRESTORABLE")

Fixed submission:
s = input()
t = input()
ns = len(s)
nt = len(t)

ans = "UNRESTORABLE"
for i in range(ns - nt + 1):
    if all([s[i + j] == "?" or s[i + j] == t[j] for j in range(nt)]):
        ans = s[:i] + t + s[i + nt:]
        ans = ans.replace("?", "a")
print(ans)