Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def dfs(N, L, s):
    depth = [-1] * N

    stack = [(0, s)]
    while stack:
        d, p = stack.pop()
        depth[p] = d

        for q in L[p]:
            if depth[q] != -1:
                continue
            stack.append((d + 1, q))
    return depth

    
def main():
    N, u, v = read_values()
    u -= 1
    v -= 1
    L = [set() for _ in range(N)]
    for _ in range(N - 1):
        A, B = read_values()
        A -= 1
        B -= 1
        L[A].add(B)
        L[B].add(A)
    
    depth_A = dfs(N, L, v)

    res = 0
    stack = [(0, u)]
    while stack:
        d, p = stack.pop()
        if d == depth_A[p]:
            res = max(res, d)
            continue

        for q in L[p]:
            if depth_A[q] == d:
                res = max(res, d)
                continue
            
            stack.append((d + 1, q))
    
    print(res)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, u, v = read_values()
    u -= 1
    v -= 1
    F = [set() for _ in range(N)]
    for _ in range(N - 1):
        a, b = read_index()
        F[a].add(b)
        F[b].add(a)

    D = [-1] * N
    S = deque()
    S.append((0, v))
    D[v] = 0
    while S:
        c, p = S.popleft()
        for q in F[p]:
            if D[q] != -1:
                continue
            D[q] = c + 1
            S.append((c + 1, q))

    E = [-1] * N
    S.append((0, u))
    E[u] = 0
    while S:
        c, p = S.popleft()
        for q in F[p]:
            if E[q] != -1  or D[q] < c + 1:
                continue
            E[q] = c + 1
            S.append((c + 1, q))
    
    res = 0
    for i in range(N):
        if E[i] < 0:
            continue
        res = max(res, D[i])
    print(res - 1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
res = ""
for s in S:
    res += chr((ord(s) - ord("A") + n) % 26)
print(res)

Fixed submission:
N = int(input())
S = input()
res = ""
for s in S:
    res += chr((ord(s) - ord("A") + N) % 26 + ord("A"))
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect as bis

N = int(input())
L = sorted(list(map(int, input().split())))

res = 0
for i, a in enumerate(L):
    for k, b in enumerate(L[i + 1:]):
        j = k + i + 1

        left = b - a
        right = a + b

        index_l = bis.bisect_right(L, left, j)
        index_r = bis.bisect_left(L, right, j)
        res += index_r - index_l - 1
print(res)



Fixed submission:
import bisect as bis

N = int(input())
L = sorted(list(map(int, input().split())))

res = 0
for i, a in enumerate(L):
    for k, b in enumerate(L[i + 1:]):
        j = k + i + 1

        left = b - a
        right = a + b

        index_l = bis.bisect_right(L, left, j)
        index_r = bis.bisect_left(L, right, j)
        if index_l == N - 1:
            break

        res += index_r - index_l - 1
print(res)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()

res = 0
pre = None
add = {2: 0}
if S[0] == S[-1] and S[0] == "L":
    add[0] = 1
else:
    add[0] = 0
for s in S:
    if pre is None:
        pass
    elif pre == s:
        res += 1
    elif pre == "R":
        add[2] += 1
    pre = s

if add[2] > K:
    res += 2 * K
    print(res)
else:
    res += 2 * add[2]
    K -= add[2]
    if K > 0:
        res += add[1]
    print(res)





Fixed submission:
N, K = map(int, input().split())
S = input()

res = 0
pre = None
add = {2: 0}
add[1] = 0 if S[0] == S[-1] else 1
for s in S:
    if pre is None:
        pass
    elif pre == s:
        res += 1
    elif pre == "R":
        add[2] += 1

    pre = s

if add[2] > K:
    res += 2 * K
    print(res)
else:
    res += 2 * add[2]
    K -= add[2]
    if add[1] == 1 and S[-1] == "L":
        res -= 2
    if K > 0:
        res += add[1]
    print(res)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()

res = 0
pre = None
add = {2: 0}
if S[0] == S[-1] and S[0] == "L":
    add[0] = 1

for s in S:
    if pre is None:
        pass
    elif pre == s:
        res += 1
    elif pre == "R":
        add[2] += 1
    pre = s

if add[2] > K:
    res += 2 * K
    print(res)
else:
    res += 2 * add[2]
    K -= add[2]
    if K > 0:
        res += add[1]
    print(res)





Fixed submission:
N, K = map(int, input().split())
S = input()

res = 0
pre = None
add = {2: 0}
add[1] = 0 if S[0] == S[-1] else 1
for s in S:
    if pre is None:
        pass
    elif pre == s:
        res += 1
    elif pre == "R":
        add[2] += 1

    pre = s

if add[2] > K:
    res += 2 * K
    print(res)
else:
    res += 2 * add[2]
    K -= add[2]
    if add[1] == 1 and S[-1] == "L":
        res -= 2
    if K > 0:
        res += add[1]
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
M = 0
for i in range(N - 1):
    M += (i + 1) % (i + 2)
print(M)

Fixed submission:
N = int(input())
print(N * (N + 1) // 2 - N)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10 ** 9 + 7
S = input()[::-1]
W = [1, 10, 9, 12, 3, 4]

dp = [[0] * 13 for _ in range(len(S))]

for i, s in enumerate(S):
    if i == 0:
        if s == "?":
            for j in range(10):
                dp[0][j] = 1
        else:
            dp[0][int(s)] = 1
        continue

    w = W[i % 6]
    if s == "?":
        for n in range(10):
            for j in range(13):
                r = (j + n * w) % 13
                dp[i][r] = (dp[i][r] + dp[i - 1][j]) % mod

    else:
        n = int(s)
        for j in range(13):
            r = (j + n * w) % 13
            dp[i][r] = (dp[i][r] + dp[i - 1][j]) % mod

print(dp[len(S) - 1][5])


Fixed submission:

mod = 10 ** 9 + 7
S = input()[::-1]
W = [1, 10, 9, 12, 3, 4]

dp = [[0] * 13 for _ in range(len(S))]

for i, s in enumerate(S):
    if i == 0:
        if s == "?":
            for j in range(10):
                dp[0][j] = 1
        else:
            dp[0][int(s)] = 1
        continue

    w = W[i % 6]
    if s == "?":
        for n in range(10):
            r = (n * w) % 13
            for j in range(13):
                dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

    else:
        n = int(s)
        r = (n * w) % 13
        for j in range(13):
            dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

print(dp[len(S) - 1][5])

Buggy python submission (verdict: Time Limit Exceeded):

mod = 10 ** 9 + 7
S = input()[::-1]
W = [1, 10, 9, 12, 3, 4]

dp = [[0] * 13 for _ in range(len(S))]

for i, s in enumerate(S):
    if i == 0:
        if s == "?":
            for j in range(10):
                dp[0][j] = 1
        else:
            dp[0][int(s)] = 1
        continue

    if s == "?":
        for n in range(10):
            r = (n * W[i % 6]) % 13
            for j in range(13):
                dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

    else:
        n = int(s)
        r = (n * W[i % 6]) % 13
        for j in range(13):
            dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

print(dp[len(S) - 1][5])


Fixed submission:

mod = 10 ** 9 + 7
S = input()[::-1]
W = [1, 10, 9, 12, 3, 4]

dp = [[0] * 13 for _ in range(len(S))]

for i, s in enumerate(S):
    if i == 0:
        if s == "?":
            for j in range(10):
                dp[0][j] = 1
        else:
            dp[0][int(s)] = 1
        continue

    w = W[i % 6]
    if s == "?":
        for n in range(10):
            r = (n * w) % 13
            for j in range(13):
                dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

    else:
        n = int(s)
        r = (n * w) % 13
        for j in range(13):
            dp[i][(j + r) % 13] = (dp[i][(j + r) % 13] + dp[i - 1][j]) % mod

print(dp[len(S) - 1][5])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())

L = [int(input())]
for _ in range(N - 1):
    a = int(input())
    if a <= L[0]:
        L.insert(0, a)
        continue

    i = bisect.bisect_left(L, a)
    L[i - 1] = a

print(len(L))

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

N = int(input())
L = [-1 * int(input())]
for _ in range(N - 1):
    a = -1 * int(input())
    if a >= L[-1]:
        L.append(a)
        continue

    i = bisect.bisect_right(L, a)
    L[i] = a

print(len(L))
Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: int(x) - 1, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)


def main():
    N, K = read_values()
    dp = [
        [[0 for i in range(N ** 2 + 1)] for ii in range(N + 1)] for iii in range(N + 1)
    ]
    dp[0][0][0] = 1

    for i in range(1, N + 1):
        for j in range(N + 1):
            for k in range(K + 1):
                if k - 2 * j < 0:
                    continue

                dp[i][j][k] = (
                    (2 * j + 1) * dp[i - 1][j][k - 2 * j]
                    + (j + 1) * (j + 1) * dp[i - 1][j + 1][k - 2 * j]
                    + dp[i - 1][j - 1][k - 2 * j]
                ) % mod

    print(dp[N][0][K])


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: int(x) - 1, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)


def main():
    N, K = read_values()
    dp = [
        [[0 for i in range(N ** 2 + 1)] for ii in range(N + 1)] for iii in range(N + 1)
    ]
    dp[0][0][0] = 1

    for i in range(1, N + 1):
        for j in range(N + 1):
            for k in range(K + 1):
                if k - 2 * j < 0:
                    continue

                dp[i][j][k] = (
                    (2 * j + 1) * dp[i - 1][j][k - 2 * j]
                    + (
                        (j + 1) * (j + 1) * dp[i - 1][j + 1][k - 2 * j]
                        if j + 1 <= N
                        else 0
                    )
                    + dp[i - 1][j - 1][k - 2 * j]
                ) % mod

    print(dp[N][0][K])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import queue as qu

mod = 10 ** 9 + 7
N, K = map(int, input().split())
D = {n: set() for n in range(N)}
for n in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    D[a].add(b)
    D[b].add(a)

res = 1
F = [0] * N
already = [False] * N

q = qu.Queue()
q.put(0)
for _ in range(N):
    n = q.get()
    res = (res * (K - F[n])) % mod
    already[n] = True

    if res == 0:
        break

    for i in D[n]:
        if not already[i]:
            F[i] += 1
            q.put(i)
        for b in D[i]:
            if not already[b]:
                F[b] += 1
print(res)


Fixed submission:
import queue as qu

mod = 10 ** 9 + 7
N, K = map(int, input().split())
D = {n: set() for n in range(N)}
for n in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    D[a].add(b)
    D[b].add(a)

res = 1
F = [0] * N
already = [False] * N

q = qu.Queue()
q.put(0)
for _ in range(N):
    n = q.get()
    already[n] = True
    d = D[n]

    m = 2 if n else 1
    for b in d:
        if already[b]:
            continue
        F[b] = m
        m += 1
        q.put(b)
        
if max(F) >= K:
    print(0)
else:
    res = 1
    for f in F:
        res = (res * (K - f)) % mod
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    H, W = read_values()
    S = [input() for _ in range(H)]
    X = [[0 for _ in range(W)] for __ in range(H)]
    Y = [[0 for _ in range(W)] for __ in range(H)]

    for h in range(H):
        for w in range(W):
            if S[h][w] == ".":
                X[h][w] = 1 if w == 0 else X[h][w - 1] + 1
                Y[h][w] = 1 if h == 0 else Y[h - 1][w] + 1

    res = 0
    for h in range(H - 1, -1, -1):
        for w in range(W - 1, -1, -1):
            if S[h][w] == "#":
                continue
            if w != W - 1:
                X[h][w] = max(X[h][w + 1], X[h][w]) 
            if h != H - 1:
                Y[h][w] = max(Y[h + 1][w], Y[h][w])
            res = max(res, X[h][w] + Y[h][w] - 1)
    print(res)

        
if __name__ == "__main__":
    main()



Fixed submission:
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    H, W = read_values()
    S = [input() for _ in range(H)]
    X = [[0 for _ in range(W)] for __ in range(H)]
    Y = [[0 for _ in range(W)] for __ in range(H)]

    for h in range(H):
        for w in range(W):
            if S[h][w] == ".":
                X[h][w] = 1 if w == 0 else X[h][w - 1] + 1
                Y[h][w] = 1 if h == 0 else Y[h - 1][w] + 1

    res = 0
    for h in range(H - 1, -1, -1):
        for w in range(W - 1, -1, -1):
            if S[h][w] == "#":
                continue
            if w != W - 1:
                X[h][w] = max(X[h][w + 1], X[h][w]) 
            if h != H - 1:
                Y[h][w] = max(Y[h + 1][w], Y[h][w])
            res = max(res, X[h][w] + Y[h][w] - 1)
    print(res)

        
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import heapq as hq

def f():
    # N = int(input())
    N, M = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    H = []
    for m in range(M):
        B, C = map(int, input().split())
        hq.heappush(H, (-C, B))

    index = 0
    res = sum(A)
    for n in range(M):
        c, b = hq.heappop(H)
        c *= -1

        for _ in range(b):
            if A[index] < c:
                res += (c - A[index])
                index += 1
            else:
                return res
    return res

print(f())


Fixed submission:
import heapq as hq

def f():
    # N = int(input())
    N, M = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    H = []
    for m in range(M):
        B, C = map(int, input().split())
        hq.heappush(H, (-C, B))

    index = 0
    res = sum(A)
    for n in range(M):
        c, b = hq.heappop(H)
        c *= -1

        for _ in range(b):
            if A[index] < c:
                res += (c - A[index])
                index += 1
                if index == N:
                    return res
            else:
                return res
    return res

print(f())
Buggy python submission (verdict: Runtime Error):
A, B, T = map(int, input().split())
pritn(B * (T // A))

Fixed submission:
A, B, T = map(int, input().split())
print(B * (T // A))
Buggy python submission (verdict: Runtime Error):
import math

A, B = map(int, input().split())

# 右からi bit(0-index)について、何番目にいるかをかんがえる
# 0: 0 ~ 2^i - 1
# k: 2^(ki) ~ 2^((k + 1)i) - 1
# k_A = int(log(2^i)(A))
# 間で変換される回数は、K = k_B - k_A 回
# K: 偶数→ 0、奇数→1

b = (B - A + 1) // 2
if A % 2 + B % 2 == 0:
    b = max(0, b - 1)
res = str(b % 2)

k_a = A
k_b = B
for i in range(1, int(math.log2(B)) + 1):
    k_a //= 2
    k_b //= 2
    num_bit = 0
    if k_a % 2:
        num_bit += 2 ** i - A % (2 ** i)
    if k_b % 2:
        num_bit += B % (2 ** i) + 1

    res = str(num_bit % 2) + res

print(int(res, 2))


Fixed submission:
A, B = map(int, input().split())

res = 0
if A % 2:
    res ^= A
    A += 1

if B % 2 == 0:
    res ^= B
    B -= 1

K = (B - A + 1) // 2
res ^= K % 2
print(res)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
can_cost = sorted([cost[a] for a in A])
D = {}
for a in A:
    c = cost[a]
    D[c] = max(a, D.setdefault(c, -1))

min_cost = can_cost[0]
min_cost_num = D[min_cost]


def f2(v, l, num):
    L = list(str(v))
    min_cost = cost[int(num)]
    num = D.setdefault(min_cost + l, -1)
    if num == -1:
        return -1

    min_cost_num = D[min_cost]
    L[L.index(str(min_cost_num))] = str(num)
    L.sort(reverse=True)
    return int("".join(L))


def f(v, l):
    L = list(str(v))
    set_L = set(L)
    L2 = [f2(v, l, num) for num in set_L]
    return max(L2)

def g(K, r)

    temp = int("".join([str(min_cost_num)] * K))
    dp = [[-1 for _ in range(min(r, K) + 1)] for __ in range(r + 1)]
    dp[0][0] = temp

    for k in range(min(r, K)):
        for n in range(r):
            v = dp[n][k]
            if v == -1:
                continue
            for l in range(1, r - n + 1):
                dp[n + l][k + 1] = max(dp[n + l][k + 1], f(v, l))
    return max(dp[r])

K = N // min_cost
r = N - K * min_cost
res = g(K, r)
if g(K, r) == -1:
    res = g(K - 1, r + min_cost)
print(res)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
can_cost = sorted([cost[a] for a in A])
D = {}
for a in A:
    c = cost[a]
    D[c] = max(a, D.setdefault(c, -1))

min_cost = can_cost[0]
min_cost_num = D[min_cost]


def f2(v, l, num):
    L = list(str(v))
    min_cost = cost[int(num)]
    num = D.setdefault(min_cost + l, -1)
    if num == -1:
        return -1

    min_cost_num = D[min_cost]
    L[L.index(str(min_cost_num))] = str(num)
    L.sort(reverse=True)
    return int("".join(L))


def f(v, l):
    L = list(str(v))
    set_L = set(L)
    L2 = [f2(v, l, num) for num in set_L]
    return max(L2)

def g(K, r):
    temp = int("".join([str(min_cost_num)] * K))
    dp = [[-1 for _ in range(min(r, K) + 1)] for __ in range(r + 1)]
    dp[0][0] = temp

    for k in range(min(r, K)):
        for n in range(r):
            v = dp[n][k]
            if v == -1:
                continue
            for l in range(1, r - n + 1):
                dp[n + l][k + 1] = max(dp[n + l][k + 1], f(v, l))
    return max(dp[r])

K = N // min_cost
r = N - K * min_cost
res = g(K, r)
if g(K, r) == -1:
    res = g(K - 1, r + min_cost)
print(res)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
R = np.zeros(N + 1, dtype="int32")
P = np.ones(N + 1, dtype="int32")
mod = 10 ** 9 + 7

def rev(a):
    return pow(a, mod - 2, mod)
    
for n in range(N + 1):
    R[n] = (R[n - 1] + rev(n)) % mod
    if n != 0:
        P[n] = P[n - 1] * n
    
C = [(R[j] + R[N - j + 1] - 1) % mod for j in range(1, N + 1)]

print(sum([a * c for a, c in zip(C, A)]) * P[N] % mod)


Fixed submission:
N, M = map(int, input().split())
S = input()
T = input()

def f(a, b):
    if b < a:
        a, b = b, a
    
    while b % a != 0:
        a, b = b % a, a
    return a

if S[0] != T[0]:
    print(-1)

else:
    p = f(N, M)
    k = N // p
    l = M // p

    for n in range(p):
        if S[n * k] != T[n * l]:
            print(-1)
            break
    else:
        print(N * M // p)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
R = np.zeros(N + 1, dtype=int)
P = np.ones(N + 1, dtype=int)
mod = 10 ** 9 + 7

def rev(a):
    return pow(a, mod - 2, mod)
    
for n in range(N + 1):
    R[n] = (R[n - 1] + rev(n)) % mod
    if n != 0:
        P[n] = P[n - 1] * n
    
C = [(R[j] + R[N - j + 1] - 1) % mod for j in range(1, N + 1)]

print(sum([a * c for a, c in zip(C, A)]) * P[N] % mod)


Fixed submission:
N, M = map(int, input().split())
S = input()
T = input()

def f(a, b):
    if b < a:
        a, b = b, a
    
    while b % a != 0:
        a, b = b % a, a
    return a

if S[0] != T[0]:
    print(-1)

else:
    p = f(N, M)
    k = N // p
    l = M // p

    for n in range(p):
        if S[n * k] != T[n * l]:
            print(-1)
            break
    else:
        print(N * M // p)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, M =map(int, input().split())
p = []

for _ in range(M):
    A, B= map(int, input().split())
    n = B - A
    m = {i for i in range(A, B)}
    heapq.heappush(p, (n, m))

n = 0
sets = []
for _ in range(M):
    n, q = heapq.heappop(p)
    for m, s in sets:
        if len(s - q) == 0:
            break
    else:
        heapq.heappush(sets, (max(q), q))
    
count = 0
minnum = -1
for _ in range(len(sets)):
    n, q = heapq.heappop(sets)
    if minnum in q:
        continue
    minnum = n
    count += 1

print(count)

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


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N, M = read_values()
    Q = [read_list() for _ in range(M)]
    Q.sort()

    res = 0
    end = 10 ** 6
    for q in Q:
        if q[0] >= end:
            res += 1
            end = q[1]
        else:
            end = min(end, q[1])
    
    res += 1
    print(res)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
num = [S[:n].count("W") + S[n + 1:].count("E") for n in range(N)]
print(min(num))

Fixed submission:
N = int(input())
S = input()
result = S[1:].count("E")
cost = result
l0 = S[0]
for n in range(1, N):
    l1 = S[n]
    if l0 != l1:
        l0 = l1
        continue
    if l0 == "W":
        cost += 1
        continue
    cost -= 1
    if cost < result:
        result = cost

print(result)
Buggy python submission (verdict: Runtime Error):
S = input().strip()
N = len(S)
K = int(input())

T = set()
for i in range(N):
    for j in range(i + 1, N + 1):
        T.add(S[i:j])
A = sorted(list(T))
print(A[K])

Fixed submission:
S = input().strip()
N = len(S)
K = int(input()) - 1

T = set()
for i in range(N):
    for j in range(i + 1, min(N + 1, i + 6)):
        T.add(S[i:j])
A = sorted(list(T))
print(A[K])