Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    y = (x * 10 + 7) % K
    if x == y:
        print(-1)
        exit()
    x = y
    i += 1


Fixed submission:
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    x = (x * 10 + 7) % K
    i += 1
    if i > 10**6:
        print(-1)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    y = (x * 10 + 7) % K
    if x == y:
        print(-1)
        exit()
    x = y
    i += 1


Fixed submission:
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    x = (x * 10 + 7) % K
    i += 1
    if i > 10**6:
        print(-1)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = int('7'*len(str(K)))

while True:
    if x % K == 0:
        print(len(str(x)))
        exit()
    x = x * 10 + 7


Fixed submission:
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    x = (x * 10 + 7) % K
    i += 1
    if i > 10**6:
        print(-1)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

B = [1] * (N+1)
B[1] = A[0]

for i in range(2, N+1):
    B[i] = B[i-1]*A[i-1]

for i in range(K+1, N+1):
    if B[i-1]/B[i-1-K] < B[i]/B[i-K]:
        print('Yes')
    else:
        print('No')


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

for i in range(K, N):
    if A[i - K] < A[i]:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

B = [1, A[0]]

for i in range(2, N+1):
    B.append(B[i-1]*A[i-1])

for i in range(K+1, N+1):
    if B[i-1]/B[i-1-K] < B[i]/B[i-K]:
        print('Yes')
    else:
        print('No')


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

for i in range(K, N):
    if A[i - K] < A[i]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations_with_replacement


n = int(input())

for i in range(1, n+1):
    count = 0
    n_list = list(combinations_with_replacement([j for j in range(1, i//6+2)], 3))
    for x in n_list:

        if x[0]**2 + x[1]**2 + x[2]**2 + x[0]*x[1] + x[1]*x[2] + x[2]*x[0] == i:
            if x.count(x[0]) == 2 or (x.count(x[0]) == 1 and x.count(x[1]) == 2):
                count += 3
            elif x.count(x[0]) == 1 and x.count(x[1]) == 1 and x.count(x[2]) == 1:
                count += 6
            else:
                count += 1
    print(count)


Fixed submission:
n = int(input())

ans = [0 for _ in range(n+1)]
m = int(n**0.5) + 1
for x in range(1, m):
    for y in range(1, m):
        for z in range(1, m):
            t = x*x + y*y + z*z + x*y + y*z + z*x
            if t < n + 1:
                ans[t] += 1

for i in range(1, n+1):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000000)


def search(ai, bi, ti, ansi):
    global ans
    if ai < n and ti + a[ai] <= k:
        search(ai+1, bi, ti+a[ai], ansi+1)

    if bi < m and ti + b[bi] <= k:
        search(ai, bi+1, ti+b[bi], ansi+1)

    ans = max(ans, ansi)


n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
search(0, 0, 0, 0)
print(ans)


Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumsum_a = [0] * (N + 1)
cumsum_b = [0] * (M + 1)

for i in range(1, N + 1):
    cumsum_a[i] = cumsum_a[i - 1] + A[i - 1]

for i in range(1, M + 1):
    cumsum_b[i] = cumsum_b[i - 1] + B[i - 1]

ans = 0
bi = M
for i in range(N+1):
    for j in range(bi, -1, -1):
        t = cumsum_a[i] + cumsum_b[j]
        if t <= K:
            ans = max(ans, i + j)
            bi = j
            break

print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if n > m:
    b += [10**9+1]*(n-m)
elif m > n:
    a += [10**9+1]*(m-n)

t = 0
i, j = 0, 0
ans = 0
while i < n or j < m:
    if a[i] <= b[j]:
        if t + a[i] <= k:
            t += a[i]
            i += 1
        else:
            break
    else:
        if t + b[j] <= k:
            t += b[j]
            j += 1
        else:
            break
    ans += 1

print(ans)


Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumsum_a = [0] * (N + 1)
cumsum_b = [0] * (M + 1)

for i in range(1, N + 1):
    cumsum_a[i] = cumsum_a[i - 1] + A[i - 1]

for i in range(1, M + 1):
    cumsum_b[i] = cumsum_b[i - 1] + B[i - 1]

ans = 0
bi = M
for i in range(N+1):
    for j in range(bi, -1, -1):
        t = cumsum_a[i] + cumsum_b[j]
        if t <= K:
            ans = max(ans, i + j)
            bi = j
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter


n = int(input())
a = list(map(int, input().split()))
counter = Counter(a)
ini_sum = sum(a)
q = int(input())
s = [0] * q

for i in range(q):
    b, c = map(int, input().split())
    counter[c] += counter[b]
    counter[b] = 0
    print(sum(key * value for key, value in counter.items()))


Fixed submission:
from collections import Counter


n = int(input())
a = list(map(int, input().split()))
counter = Counter(a)
ini_sum = sum(a)
q = int(input())
s = [ini_sum] + [0] * q

for i in range(1, q+1):
    b, c = map(int, input().split())
    x = c - b
    s[i] = s[i-1] + x*counter[b]
    counter[c] += counter[b]
    counter[b] = 0

for i in range(1, q+1):
    print(s[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
b = [False] * (max_a + 1)
a.sort()
a = a + [0]
b[a[0]] = True
count = 0
for i in range(1, n):
    flg = True
    if b[a[i]]:
        continue
    for j in range(i - 1, -1, -1):
        if a[i] % a[j] == 0 or a[i] == a[i+1]:
            flg = False
            b[a[i]] = True
            k = 2
            while k*a[i] < max_a:
                b[k*a[i]] = True
                k += 1
            break
    if flg:
        count += 1

if a[0] != a[1]:
    count += 1
print(count)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
b = [0] * (max_a + 1)
a.sort()

for i in a:
    b[i] += 1
    if b[i] == 1:
        for j in range(2*i, max_a + 1, i):
            b[j] += 2
print(b.count(1))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
b = [False] * (max_a + 1)
a.sort()
a = a + [0]
b[a[0]] = True
count = 0
for i in range(1, n):
    flg = True
    if b[a[i]]:
        continue
    for j in range(i - 1, -1, -1):
        if a[i] % a[j] == 0 or a[i] == a[i+1]:
            flg = False
            b[a[i]] = True
            k = 2
            while k*a[i] < max_a:
                b[k*a[i]] = True
                k += 1
            break
    if flg:
        count += 1

if a[0] != a[1]:
    count += 1
print(count)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
b = [0] * (max_a + 1)
a.sort()

for i in a:
    b[i] += 1
    if b[i] == 1:
        for j in range(2*i, max_a + 1, i):
            b[j] += 2
print(b.count(1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
print(m)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
            break
print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
m = 1
for i in a:
    m *= i
if m > 10**18:
    m = -1
print(m)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = 1
if 0 in a:
    m = 0
else:
    for i in a:
        m *= i
        if m > 10**18:
            m = -1
            break
print(m)
Buggy python submission (verdict: Runtime Error):
import math


def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

        # nの平方根まで計算する
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True


N = int(input())
if N == 1:
    print(0)
elif isPrime(N):
    print(1)
else:
    count = 0
    for i in range(2, N//2):
        if not isPrime(i):
            continue
        if isPrime(N) and i > N:
            break
        for j in range(1, 10):
            if N % i**j == 0:
                N = N / i**j
                count += 1
                if N == 1 or N % i != 0:
                    break
print(count)


Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if not arr:
        arr.append([n, 1])

    return arr


N = int(input())
p = factorization(N)
count = 0
for x in p:
    if N == 1:
        break
    for j in range(1, x[1] + 1):
        if N % (x[0] ** j) == 0:
            N /= x[0] ** j
            count += 1
        else:
            break
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, M = map(int, input().split())
A = []
B = []
route = [[False for _ in range(N)] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    route[a-1][b-1] = True
    route[b-1][a-1] = True

print('Yes')

q = deque()
d = [-1] * N
d[0] = 0
q.append(0)

while len(q) != 0:
    x = q.popleft()
    for i in range(1, N):
        if route[x][i] and d[i] == -1:
            d[i] = x + 1
            q.append(i)

for i in range(1, N):
    print(d[i])


Fixed submission:
from collections import deque

N, M = map(int, input().split())

route = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    route[a - 1].append(b - 1)
    route[b - 1].append(a - 1)

print('Yes')

q = deque()
d = [-1] * N
d[0] = 0
q.append(0)

while q:
    x = q.popleft()
    for i in route[x]:
        if d[i] == -1:
            d[i] = x + 1
            q.append(i)

for i in range(1, N):
    print(d[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, M = map(int, input().split())
A = []
B = []
route = [[False for _ in range(N)] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    route[a-1][b-1] = True
    route[b-1][a-1] = True

print('Yes')

q = deque()
d = [-1] * N
d[0] = 0
for i in range(1, N):
    if route[0][i]:
        q.append(i)
        d[i] = 1

while len(q) != 0:
    x = q.popleft()
    for i in range(1, N):
        if route[x][i] and d[i] == -1:
            d[i] = x + 1
            q.append(i)

for i in range(1, N):
    print(d[i])


Fixed submission:
from collections import deque

N, M = map(int, input().split())

route = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    route[a - 1].append(b - 1)
    route[b - 1].append(a - 1)

print('Yes')

q = deque()
d = [-1] * N
d[0] = 0
q.append(0)

while q:
    x = q.popleft()
    for i in route[x]:
        if d[i] == -1:
            d[i] = x + 1
            q.append(i)

for i in range(1, N):
    print(d[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))
num_sub = [0] * n

for i in range(n):
    print(a.count(i + 1))

Fixed submission:
n = int(input())
a = list(map(int, input().split(' ')))
num_sub = [0] * n

for i in a:
    num_sub[i - 1] += 1

for num in num_sub:
    print(num)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

sum = 0

def gcd(a, b):
    if b == 0:
        return a
    
    return gcd(b, a % b)


for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab_gcd = gcd(a, b)
        for c in range(1, k + 1):
            abc_gcd = gcd(c, ab_gcd)
            sum += abc_gcd
        
print(sum)

Fixed submission:
k = int(input())

sum = 0

def gcd(a, b):
    if b == 0:
        return a
    
    return gcd(b, a % b)


for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab_gcd = gcd(a, b)
        for c in range(1, k + 1):
            abc_gcd = gcd(c, ab_gcd)
            sum += abc_gcd
        
print(sum)
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
x = 0

for c in C.values():
    x += comb(c, 2, exact=True)

for i in range(N):
    y = x - comb(C[A[i]], 2, exact=True) + comb(C[A[i]] - 1, 2, exact=True)
    print(y)


Fixed submission:
from scipy.special import comb
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
x = 0

for c in C.values():
    x += comb(c, 2, exact=True)

for i in range(N):
    y = x - comb(C[A[i]], 2, exact=True) + comb(C[A[i]] - 1, 2, exact=True)
    print(y)
Buggy python submission (verdict: Time Limit Exceeded):
from _collections import deque

s = deque(input())
q = int(input())

for i in range(q):
    query = list(input().split())
    if query[0] == '1':
        s.reverse()
    else:
        if query[1] == '1':
            s.appendleft(query[2])
        else:
            s.append(query[2])
print("".join(s))


Fixed submission:
from _collections import deque

s = deque(input())
q = int(input())
reverse_flg = False

for i in range(q):
    query = list(input().split())
    if query[0] == '1':
        reverse_flg = not reverse_flg
    else:
        if query[1] == '1':
            if reverse_flg:
                s.append(query[2])
            else:
                s.appendleft(query[2])
        else:
            if reverse_flg:
                s.appendleft(query[2])
            else:
                s.append(query[2])
if reverse_flg:
    s.reverse()
print("".join(s))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))
max_sum_k = 0

for i in range(n - k + 1):
    max_sum_k = max(max_sum_k, sum(p[i:i+k]))

max_ex = (k + max_sum_k) / 2
print(max_ex)


Fixed submission:
n, k = map(int, input().split())
p = list(map(int, input().split()))
max_sum_k = 0
cum_sum = [0] * (n+1)
cum_sum[0] = 0
cum_sum[1] = p[0]
for i in range(2, n+1):
    cum_sum[i] = p[i-1] + cum_sum[i-1]

for i in range(k, n + 1):
    sum_p = cum_sum[i] - cum_sum[i-k]
    if sum_p > max_sum_k:
        max_sum_k = sum_p

max_ex = (k + max_sum_k) / 2
print(max_ex)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

n_list = [i for i in range(1, n)]
ans = sum(n_list)
print(ans)


Fixed submission:
from decimal import Decimal


n = int(input())

ans = (Decimal((n - 1) * n) / 2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
x = []
for i in range(m):
    b, c = map(int, input().split())
    x += [c]*b
x.sort(reverse=True)

ans = 0
for i in range(n):
    if i >= len(x):
        ans += a[i]
    else:
        ans += max(a[i], x[i])

print(ans)


Fixed submission:
from collections import Counter


n, m = map(int, input().split())
a = list(map(int, input().split()))
x = Counter(a)

for i in range(m):
    b, c = map(int, input().split())
    x[c] += b

y = list(zip(x.keys(), x.values()))
y.sort(reverse=True)

ans = 0
k = 0
for z in y:
    if k + z[1] <= n:
        ans += z[0] * z[1]
        k += z[1]
    else:
        ans += z[0] * (n - k)
        k = n
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
X = []
for i in range(Q):
    l, r = map(int, input().split())
    X.append(S[l-1:r])

for x in X:
    print(x.count('AC'))


Fixed submission:
N, Q = map(int, input().split())
S = input()
cumsum = [0] * N

for i in range(1, N):
    if S[i - 1] == 'A' and S[i] == 'C':
        cumsum[i] = cumsum[i - 1] + 1
    else:
        cumsum[i] = cumsum[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    print(cumsum[r-1] - cumsum[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
import math


N, K = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [10**9] * N

dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

        if dp[i] > dp[i - j] + abs(h[i] - h[i - j]):
            dp[i] = dp[i - j] + abs(h[i] - h[i - j])

print(dp[-1])


Fixed submission:
import numpy as np


N, K = map(int, input().split())
h = np.array([int(i) for i in input().split()])
dp = np.full(N, 10 ** 10)

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    ik = max(0, i - K)
    dp[i] = np.min(dp[ik:i] + np.abs(h[i] - h[ik:i]))

print(int(dp[-1]))

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


N, K = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [10**9] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

        dp[i] = min(
            dp[i],
            dp[i - j] + abs(h[i] - h[i - j])
        )

print(dp[-1])


Fixed submission:
import numpy as np


N, K = map(int, input().split())
h = np.array([int(i) for i in input().split()])
dp = np.full(N, 10 ** 10)

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    ik = max(0, i - K)
    dp[i] = np.min(dp[ik:i] + np.abs(h[i] - h[ik:i]))

print(int(dp[-1]))

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


N, K = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [1000000000] * N

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

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

        dp[i] = min(
            dp[i],
            dp[i - j] + abs(h[i] - h[i - j])
        )

print(dp[N - 1])



Fixed submission:
import numpy as np


N, K = map(int, input().split())
h = np.array([int(i) for i in input().split()])
dp = np.full(N, 10 ** 10)

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    ik = max(0, i - K)
    dp[i] = np.min(dp[ik:i] + np.abs(h[i] - h[ik:i]))

print(int(dp[-1]))

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


N, K = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [math.inf] * N

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    for j in range(1, K + 1):
        if i - j < 0:
            break
            
        dp[i] = min(
            dp[i],
            dp[i - j] + abs(h[i] - h[i - j])
        )

print(dp[N - 1])


Fixed submission:
import numpy as np


N, K = map(int, input().split())
h = np.array([int(i) for i in input().split()])
dp = np.full(N, 10 ** 10)

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    ik = max(0, i - K)
    dp[i] = np.min(dp[ik:i] + np.abs(h[i] - h[ik:i]))

print(int(dp[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[0 for _ in range(W+1)] for i in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i])

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])


Fixed submission:
N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[0 for _ in range(W+1)] for i in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i])

        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
sum_i = [n - 1] * n
for i in range(n):
    sum_i[i] = S[:i].count('W') + S[i + 1:].count('E')

print(min(sum_i))


Fixed submission:
n = int(input())
S = input()
e_sum = [0] * n
w_sum = [0] * n
ew_sum = [0] * n
for i in range(2, n + 1):
    e_sum[-i] = e_sum[-i + 1] + 1 if S[-i + 1] == 'E' else e_sum[-i + 1]
    ew_sum[-i] = e_sum[-i]
for i in range(1, n):
    w_sum[i] = w_sum[i - 1] + 1 if S[i - 1] == 'W' else w_sum[i - 1]
    ew_sum[i] += w_sum[i]

print(min(ew_sum))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
count = 0
answer = n - 1
for i in range(n):
    count = S[:i].count('W') + S[i + 1:].count('E')
    answer = min(answer, count)
    count = 0

print(answer)


Fixed submission:
n = int(input())
S = input()
e_sum = [0] * n
w_sum = [0] * n
ew_sum = [0] * n
for i in range(2, n + 1):
    e_sum[-i] = e_sum[-i + 1] + 1 if S[-i + 1] == 'E' else e_sum[-i + 1]
    ew_sum[-i] = e_sum[-i]
for i in range(1, n):
    w_sum[i] = w_sum[i - 1] + 1 if S[i - 1] == 'W' else w_sum[i - 1]
    ew_sum[i] += w_sum[i]

print(min(ew_sum))

Buggy python submission (verdict: Runtime Error):
n = int(input())
S = input()
count = 0
answer = n - 1
for i in range(n):
    print(S[:i], S[i + 1:])
    count = S[:i].count('W') + S[i + 1:].count('E')
    answer = min(answer, count)
    count = 0

print(answer)


Fixed submission:
n = int(input())
S = input()
e_sum = [0] * n
w_sum = [0] * n
ew_sum = [0] * n
for i in range(2, n + 1):
    e_sum[-i] = e_sum[-i + 1] + 1 if S[-i + 1] == 'E' else e_sum[-i + 1]
    ew_sum[-i] = e_sum[-i]
for i in range(1, n):
    w_sum[i] = w_sum[i - 1] + 1 if S[i - 1] == 'W' else w_sum[i - 1]
    ew_sum[i] += w_sum[i]

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

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

for i in range(N):
    y = X[:i] + X[i + 1:]
    print(int(np.median(y)))


Fixed submission:
import numpy as np

N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
x = np.median(X)
index = N // 2
m1 = Y[index]
m2 = Y[index - 1]

for i in range(N):
    if X[i] < x:
        print(m1)
    else:
        print(m2)