Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
r = int(input())

if n >= 10:
    print(int(r))
else:
    a = 100*(10-n)
    print(int(r+a))

Fixed submission:
inputStr = input()
inputList = inputStr.split(' ')
n = int(inputList[0])
r = int(inputList[1])

if n >= 10:
    print(int(r))
else:
    a = 100*(10-n)
    print(int(r+a))
Buggy python submission (verdict: Runtime Error):
if A == 0:
  print(0)
elif B == 0:
  print(N)
else:
  ans = 0
  div = N //( A + B ) # A > 0
  ans = div * A
  ans += min( N % (A + B) , A)
  # mod = N % ( A + B )


  # if mod > A :
  #   ans += A
  # else :
  #   ans += mod
  
  print(ans)

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

result = 0
result += N // (A + B) * A
result += min(N % (A + B), A)
print(result)
Buggy python submission (verdict: Runtime Error):
s = input()
s.split(' ')

n = int(s[0])
a = int(s[2])
b = int(s[4])

train = n * a
taxi = b

if(taxi < train):
    print(taxi)
else:
    print(train)

Fixed submission:
s = input()
l = s.split(" ")

n = int(l[0])
a = int(l[1])
b = int(l[2])
#print(l)
train = n * a
taxi = b

if(taxi < train):
    print(taxi)
else:
    print(train)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

array = [0, 0, 0]

s = int(input())
sum = 0
for a in range(1, s+1):
    for b in range(1, s+1):
        for c in range(1, s+1):
            array = [a, b, c]
            sum += gcd_list(array)

print(sum)

Fixed submission:
import math
from functools import reduce
import numpy as np
from itertools import combinations
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

s = int(input())
qwe = np.arange(s+1)

sum = (1+s)*s/2

for i in range(1, s+1):
    for j in range(i + 1, s+1):
        sum += gcd(i, j, j) * 3
        sum += gcd(i, i, j )* 3
        # print(i, j)
        for k in range(j + 1, s+1):
            sum += gcd(i, j, k) * 6
            # print(i, j, k)
print(int(sum))
Buggy python submission (verdict: Runtime Error):
N, K = int(input().split())

# N = 1000000000000000000
# K = 1
amari = N%K
bmari = abs(amari-K)
if amari >= bmari:
    print(bmari)
else:
    print(amari)

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

amari = N%K
bmari = abs(amari-K)
if amari >= bmari:
    print(bmari)
else:
    print(amari)
Buggy python submission (verdict: Time Limit Exceeded):
def isOK(array, index, key):
    if array[index] > key:
        return True
    else:
        return False

def binary_serch(array, key):
    ng = -1
    ok = len(array)

    while (abs(ok - ng) > 1):
        mid = (ok + ng)//2

        if isOK(array, mid, key):
            ok = mid
        else:
            ng = mid
    return ok
n = int(input())
array1 = list(map(int,input().split()))
array2 = list(map(int,input().split()))
array3 = list(map(int,input().split()))

# array1 = sorted(array1)
array2 = sorted(array2)
array3 = sorted(array3)

# a = binary_serch(array2, 5)
count=0
for array1_index in range(n):
    start_array2_index = binary_serch(array2, array1[array1_index])
    #print(array1[array1_index])
    for cor_array2_index in range(start_array2_index, n):
        #print(array2[cor_array2_index])
        start_array3_index = binary_serch(array3, array2[cor_array2_index])
        # for k in range(start_array3_index,n):
        #     print(array3)
        count+=abs(start_array3_index - n)
print(count)


Fixed submission:
def isOK_under(array, index, key):
    if array[index] >= key:
        return True
    else:
        return False

def isOK_over(array, index, key):
    if array[index] > key:
        return True
    else:
        return False

def binary_serch_under(array, key):
    ng = -1
    ok = len(array)

    while (abs(ok - ng) > 1):
        mid = (ok + ng)//2

        if isOK_under(array, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

def binary_serch_over(array, key):
    ng = -1
    ok = len(array)
    while (abs(ok - ng) > 1):
        mid = (ok + ng)//2
        if isOK_over(array, mid, key):
            ok = mid
        else:
            ng = mid
    return ok

n = int(input())
array1 = list(map(int,input().split()))
array2 = list(map(int,input().split()))
array3 = list(map(int,input().split()))

array1 = sorted(array1)
array2 = sorted(array2)
array3 = sorted(array3)

# a = binary_serch(array2, 5)
count=0
# for array1_index in range(n):
#     start_array2_index = binary_serch(array2, array1[array1_index])
#     # print(array1[array1_index])
#     for cor_array2_index in range(start_array2_index, n):
#         # print(array2[cor_array2_index])
#         start_array3_index = binary_serch(array3, array2[cor_array2_index])
#         # for k in range(start_array3_index,n):
#         #     print(array3)
#         count+=abs(start_array3_index - n)
for index_array2 in range(n):
    a = binary_serch_under(array1, array2[index_array2])
    c = binary_serch_over(array3, array2[index_array2])
    count += a*abs(c-n)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()
    ans = 0
    r, g, b = [], [], []
    for i in range(n):
        if s[i] == 'R':
            r.append(i)
        elif s[i] == 'G':
            g.append(i)
        else:
            b.append(i)
    for ri in r:
        for gi in g:
            for bi in b:
                rgb = sorted([ri, gi, bi])
                if rgb[2] - rgb[1] == rgb[1] - rgb[0]:
                    continue
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    s = input()
    r, g, b = [], [], []
    for i in range(n):
        t = s[i]
        if t == 'R':
            r.append(i)
        elif t == 'G':
            g.append(i)
        else:
            b.append(i)
    ans = len(r) * len(g) * len(b)

    for i in range(1, n // 2 + 1):
        for k in range(n):
            try:
                if {s[k], s[k + i], s[k + 2 * i]} == {'R', 'G', 'B'}:
                    ans -= 1
            except IndexError:
                break
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
s = input()
if s[3] == s[4] and s[5] == s[6]:
    print('Yes')
else:
    print('No')


Fixed submission:
s = input()
if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import sys

x = int(input())
nums = [i for i in range(1, 100004, 2)]
del nums[0]
if x == 2:
    print(2)
    sys.exit()
while nums:
    primal = nums.pop(0)
    if primal >= x:
        print(primal)
        break
    nums = [num for num in nums if num % primal != 0]


Fixed submission:
import sys

x = int(input())
nums = [i for i in range(1, 100004, 2)]
del nums[0]
if x == 2:
    print(2)
    sys.exit()
while nums:
    primal = nums.pop(0)
    if primal >= x:
        print(primal)
        break
    nums = [num for num in nums if num % primal != 0]

Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
nums = [i for i in range(2, 100004)]
while nums:
    primal = nums.pop(0)
    if primal >= x:
        print(primal)
        break
    nums = [num for num in nums if num % primal != 0]


Fixed submission:
import sys

x = int(input())
nums = [i for i in range(1, 100004, 2)]
del nums[0]
if x == 2:
    print(2)
    sys.exit()
while nums:
    primal = nums.pop(0)
    if primal >= x:
        print(primal)
        break
    nums = [num for num in nums if num % primal != 0]
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def main():
    n = int(input())
    color = [None]*(n-1)
    color[0] = -1

    con = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        con[a-1].append((b-1, i))
        con[b-1].append((a-1, i))

    def dfs(now=0, prev=-1, mycolor=-1):
        in_use = {mycolor}
        i = 0

        for tup in con[now]:
            if tup[0] != prev:
                while i < 1000:
                    if i not in in_use:
                        color[tup[1]] = i
                        in_use.add(i)
                        break
                    i += 1
                dfs(tup[0], now, i)

    dfs()

    print(max(color)+1)
    for i in color:
        print(i+1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def main():
    n = int(input())
    color = [None]*(n-1)
    color[0] = -1

    con = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        con[a-1].append((b-1, i))
        con[b-1].append((a-1, i))

    def dfs(now=0, prev=-1, mycolor=-1):
        in_use = {mycolor}
        i = 0

        for tup in con[now]:
            if tup[0] != prev:
                while True:
                    if i not in in_use:
                        color[tup[1]] = i
                        in_use.add(i)
                        break
                    i += 1
                dfs(tup[0], now, i)

    dfs()

    print(max(color)+1)
    for i in color:
        print(i+1)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())
c = [0]*205
c[1], c[2], c[3] = 3, 2, 1
reword = c[x]+c[y]
if x+y == 2:
    reword += 4

print(reword*100000)


Fixed submission:
x, y = map(int, input().split())
c = [0]*210
c[1], c[2], c[3] = 3, 2, 1
reword = c[x]+c[y]
if x+y == 2:
    reword += 4

print(reword*100000)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [int(s) for s in input().split()]
# m回だけ最も大きい数字を2で割る
for i in range(m):
    a[a.index(max(a))] //= 2
print(sum(a[i] for i in range(n)))


Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1

heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))

print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [int(s) for s in input().split()]
# m回だけ最も大きい数字を2で割る
for i in range(m):
    a.sort()
    a[n-1] //= 2
print(sum(a[i] for i in range(n)))


Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1

heapq.heapify(a)
for _ in range(m):
    x = heapq.heappop(a)
    heapq.heappush(a, (-x//2)*(-1))

print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
# 目の前の人が同じ方を向いてたら幸福
# 操作はK回以下
# l~rの範囲内を列の塊ごと反転

n, k = map(int, input().split())
s = list(input())
# R = True, L = False
b = []
for i in range(n):
    if s[i] == 'R':
        b.append(True)
    else:
        b.append(False)

# s[i] != s[i+1] となる最小のiをまず見つけて
# s[i] == s[j] となるiより大きい最小のjを見つけて
# s[i+1]~s[j-1] の区間をひっくり返す
# 通常2点増えるのに対し端を含むと1点しか増えないので後回しにする

for i in range(n-2):
    if b[i] == b[i+1]:
        continue

    for j in range(i+2, n):
        if b[i] == b[j]:
            mir = list(map(lambda x: not x, b[j-1:i:-1]))
            b = b[:i+1]+mir+b[j:]
            k -= 1
            break

    if k == 0:
        break

happy = 0
for i in range(0, n-1):
    if b[i] == b[i+1]:
        happy += 1

# 端を含む操作は1回行えば十分なので両端が異なる&kが余ってたら+1点
if k > 0 and b[0] != b[n-1]:
    happy += 1

print(happy)


Fixed submission:
# 今回の方針
# LRの境界の数だけで計算を済ませる

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

happy = 0
for i in range(0, n-1):
    if s[i] == s[i+1]:
        happy += 1

happy += 2*k
if happy >= n:
    happy = n-1

print(happy)
Buggy python submission (verdict: Time Limit Exceeded):
# 組み合わせの数を出力
import sys
input = sys.stdin.readline

n = int(input())
s = [sorted(input()) for _ in range(n)]
t = 0
dup = []
# sが空っぽになるまで重複するものを消して差分を控える
while s:
    t = len(s)
    pop = s.pop()
    try:
        while True:
            s.remove(pop)
    except ValueError:
        pass
    dup.append(t-len(s))

ans = sum(c*(c-1)//2 for c in dup)
print(ans)


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

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
dup = collections.Counter(s).values()

ans = sum(c*(c-1)//2 for c in dup)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 組み合わせの数を出力
n = int(input())
s = [sorted(input()) for _ in range(n)]
t = 0
dup = []
# sが空っぽになるまで重複するものを消して差分を控える
while s:
    t = len(s)
    pop = s.pop()
    try:
        while True:
            s.remove(pop)
    except ValueError:
        pass
    dup.append(t-len(s))

ans = sum(c*(c-1)//2 for c in dup)
print(ans)


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

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
dup = collections.Counter(s).values()

ans = sum(c*(c-1)//2 for c in dup)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 組み合わせの数を出力
n = int(input())
s = [sorted(input()) for _ in range(n)]
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            count += 1

print(count)


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

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
dup = collections.Counter(s).values()

ans = sum(c*(c-1)//2 for c in dup)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
input = sys.stdin.readline

n, m = map(int, input().split())
sum = 0
# Aiが最小のものから順に選ぶ
# 重複するときは最大金額を選び残りはAiを+1する

# Ai>Mのものは最初から除外
# 受け取りにA日かかるということはM-A+1日目までに受けなければならない
# index = M-A(day)
# element = B(reword)

schedule = [[] for _ in range(m+1)]
for _ in range(n):
    day, reword = map(int, input().split())
    if day > m:
        continue
    schedule[m-day+1].append(reword)

for i in range(m, 0, -1):
    if not schedule[i]:
        del schedule[i]
        continue
    max_reword = heapq.nlargest(1, schedule[i])
    sum += max_reword[0]
    schedule[i].remove(max_reword[0])
    if schedule[i]:
        schedule[i-1].extend(schedule[i])
    del schedule[i]

print(sum)


Fixed submission:
import sys
from heapq import heappop, heappush
input = sys.stdin.readline

n, m = map(int, input().split())
# Ai>Mのものは最初から除外
# Aiが最小のものから順に選ぶ

# index = A(day-1), element = B(reword)
schedule = [[] for _ in range(m)]
for _ in range(n):
    day, reword = map(int, input().split())
    if day > m:
        continue
    schedule[day-1].append(reword)

hq = []
sum = 0

for i in range(m):
    while schedule[i]:
        heappush(hq, -schedule[i][-1])
        del schedule[i][-1]

    if hq:
        sum -= heappop(hq)

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
dam = list(map(int, input().split()))
mt = [0]*n
# a[i]]は山iと山i+1に降った平均
total = sum(dam)
for i in range(n):
    if i-2 < 0:
        mt[i] = total - 2*sum(dam[i+1::2])
    else:
        mt[i] = total - 2*(sum(dam[i-2::-2])+sum(dam[i+1::2]))

print(' '.join(map(str, mt)))


Fixed submission:
n = int(input())
dam = list(map(int, input().split()))
mt = [0]*n
# a[i]]は山iと山i+1に降った平均
mt[0] = sum(dam) - 2*sum(dam[1::2])
mt[n-1] = dam[n-1]*2-mt[0]
for i in range(1, n-1):
    mt[i] = dam[i-1]*2-mt[i-1]
print(' '.join(map(str, mt)))
Buggy python submission (verdict: Runtime Error):
mod = 10**9+7
n, k = map(int, input().split())
ans = n-k+1
print(ans)
for i in range(1, k):
    ans = int(ans*(k-i)*(n-k-i+1)/(i*(i+1)))
    print(ans % mod)


Fixed submission:
# k-1Ci-1 * n-k+1Ci
mod = 10**9+7
n, k = map(int, input().split())
ans = n-k+1
print(ans)
for i in range(1, k):
    ans = ans*(k-i)*(n-k-i+1)//(i*(i+1))
    print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction

n, k = map(int, input().split())


def cmb(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    ans = 1
    if r > n-r:
        r = n-r
    for i in range(r):
        ans = (ans * Fraction(n-i, r-i)) % (10**9+7)
    return ans.numerator


for i in range(1, k+1):
    a = cmb(k-1, i-1)
    b = cmb(n-k+1, i)
    ab = a*b % (10**9+7)
    print(ab)


Fixed submission:
# k-1Ci-1 * n-k+1Ci
mod = 10**9+7
n, k = map(int, input().split())
ans = n-k+1
print(ans)
for i in range(1, k):
    ans = ans*(k-i)*(n-k-i+1)//(i*(i+1))
    print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction

n, k = map(int, input().split())


def cmb(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    ans = 1
    if r > n-r:
        r = n-r
    for i in range(r):
        ans *= Fraction(n-i, r-i)
    return ans.numerator


for i in range(1, k+1):
    a = cmb(k-1, i-1) % (10**9+7)
    b = cmb(n-k+1, i) % (10**9+7)
    ab = a*b % (10**9+7)
    print(ab)


Fixed submission:
# k-1Ci-1 * n-k+1Ci
mod = 10**9+7
n, k = map(int, input().split())
ans = n-k+1
print(ans)
for i in range(1, k):
    ans = ans*(k-i)*(n-k-i+1)//(i*(i+1))
    print(ans % mod)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def fib(n):
    '''f(n)=f(n-1)+f(n-2)'''
    a, b = 0, 1
    for _ in range(n-1):
        a, b = b, a+b
    return b


n, m = map(int, input().split())
mod = 10**9+7
a = [int(input()) for _ in range(m)]
ans = fib(a[0])*fib(n-a[m-1]) % mod
for i in range(m-1):
    if a[i+1]-a[i] == 1:
        ans = 0
        break
    ans = ans * fib(a[i+1]-a[i]-1) % mod

print(ans)


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


def fib(n):
    '''f(n)=f(n-1)+f(n-2)'''
    a, b = 0, 1
    for _ in range(n-1):
        a, b = b, a+b
    return b


n, m = map(int, input().split())
mod = 10**9+7
a = [int(input()) for _ in range(m)]
if not a:
    ans = fib(n+1) % mod
else:
    ans = fib(a[0])*fib(n-a[m-1]) % mod
    for i in range(m-1):
        if a[i+1]-a[i] == 1:
            ans = 0
            break
        ans = ans * fib(a[i+1]-a[i]-1) % mod

print(ans)

Buggy python submission (verdict: Runtime Error):
def fib(n):
    '''f(n)=f(n-1)+f(n-2)'''
    a, b = 0, 1
    for _ in range(n-1):
        a, b = b, a+b
    return b


n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
ans = fib(a[0])*fib(n-a[m-1])
for i in range(m-1):
    if a[i+1]-a[i] == 1:
        ans = 0
        break
    ans = ans * fib(a[i+1]-a[i]-1) % (10**9+7)

print(ans)


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


def fib(n):
    '''f(n)=f(n-1)+f(n-2)'''
    a, b = 0, 1
    for _ in range(n-1):
        a, b = b, a+b
    return b


n, m = map(int, input().split())
mod = 10**9+7
a = [int(input()) for _ in range(m)]
if not a:
    ans = fib(n+1) % mod
else:
    ans = fib(a[0])*fib(n-a[m-1]) % mod
    for i in range(m-1):
        if a[i+1]-a[i] == 1:
            ans = 0
            break
        ans = ans * fib(a[i+1]-a[i]-1) % mod

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

n, k = map(int, input().split())
s = [int(s) for s in list(input())]
count = 0
tmp = 1
c = []
ans = 0

for i in s:
    if i == tmp:
        count += 1
    else:
        c.append(count)
        tmp = i
        count = 1

c.append(count)
if s[-1] == 0:
    c.append(0)

# kが十分大きいなら
if len(c) <= 2*k+1:
    print(sum(c))
    sys.exit()
# TLEしたから尺取りにしたい
for i in range(0, len(c)-2*k, 2):
    ans = max(ans, sum(c[i:i+2*k+1]))

print(ans)


Fixed submission:
import sys

n, k = map(int, input().split())
s = [int(s) for s in list(input())]
count = 0
tmp = 1
c = []
ans = 0

for i in s:
    if i == tmp:
        count += 1
    else:
        c.append(count)
        tmp = i
        count = 1

c.append(count)
if s[-1] == 0:
    c.append(0)

# kが十分大きいなら
if len(c) <= 2*k+1:
    print(sum(c))
    sys.exit()
# TLEしたから尺取りにしたい
# for i in range(0, len(c)-2*k, 2):
#     ans = max(ans, sum(c[i:i+2*k+1]))
ans = total = sum(c[:2*k+1])
for i in range(0, len(c)-2*k-2, 2):
    total = total + c[i+2*k+1] + c[i+2*k+2] - c[i] - c[i+1]
    ans = max(ans, total)

print(ans)

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

n, k = map(int, input().split())
s = [int(s) for s in list(input())]
count = 0
tmp = 1
c = []
ans = 0

for i in s:
    if i == tmp:
        count += 1
    else:
        c.append(count)
        tmp = i
        count = 1

c.append(count)
if s[-1] == 0:
    c.append(0)

# kが十分大きいなら
if len(c) <= 2*k+1:
    print(sum(c))
    sys.exit()

for i in range(0, len(c)-2*k, 2):
    ans = max(ans, sum(c[i:i+2*k+1]))

print(ans)


Fixed submission:
import sys

n, k = map(int, input().split())
s = [int(s) for s in list(input())]
count = 0
tmp = 1
c = []
ans = 0

for i in s:
    if i == tmp:
        count += 1
    else:
        c.append(count)
        tmp = i
        count = 1

c.append(count)
if s[-1] == 0:
    c.append(0)

# kが十分大きいなら
if len(c) <= 2*k+1:
    print(sum(c))
    sys.exit()
# TLEしたから尺取りにしたい
# for i in range(0, len(c)-2*k, 2):
#     ans = max(ans, sum(c[i:i+2*k+1]))
ans = total = sum(c[:2*k+1])
for i in range(0, len(c)-2*k-2, 2):
    total = total + c[i+2*k+1] + c[i+2*k+2] - c[i] - c[i+1]
    ans = max(ans, total)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
"""
    リーダーに向いてない人の最小
    (W in 0~i) + (E in i+2~n-1)
"""
from collections import Counter as count
n = int(input())
s = input()
least = n

for i in range(n):
    turn = count(s[:i])['W'] + count(s[i+2:])['E']
    if turn < least:
        least = turn

print(least)


Fixed submission:
"""
    リーダーに向いてない人の最小
    (W in 0~i) + (E in i+2~n-1)
"""
from collections import Counter as count
n = int(input())
s = input()
turn = count(s[1:])['E']
least = turn

for i in range(n-1):
    if s[i] == 'W':
        turn += 1
    if s[i+1] == 'E':
        turn -= 1
    if turn < least:
        least = turn

print(least)
Buggy python submission (verdict: Runtime Error):
n = input()

m = len(n)
f = 0
ans = 0

for i in range(m):
    ans += n[i]
    
    
if m>1 and n[0] == 1:
    if n[1] == 0:
        ans += 9
print(ans)

Fixed submission:
n = input()

m = len(n)
f = 0
ans = 0

for i in range(m):
    ans += int(n[i])
    
    
if m>1 and n[0] == '1':
    if n[1] == '0':
        ans += 9
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

a = list(map(int, input().split()))

a = sorted(a)

m = a[-1]
f = 1
if m % 2 == 1:
    s = m // 2 + 1
    count = 0
    if a[0] != s or a[2] == s:
        f = 0
    else:
        for i in range(n):
            if a[i] < s:
                continue
            elif a[i] == s:
                if count == 0:
                    count = 1
                else:
                    count = 0
                    s += 1
            else:
                f = 0
                break
        if count == 1:
            f = 0
else:
    s = m // 2 + 1
    count = 0
    if a[0] != s-1 or a[1] == s-1:
        f = 0
    else:
        for i in range(1, n):
            if a[i] < s:
                continue
            elif a[i] == s:
                if count == 0:
                    count = 1
                else:
                    count = 0
                    s += 1
            else:
                f = 0
                break
        if count == 1:
            f = 0
        
if f == 1:
    print('Possible')
else:
    print('Impossible')

Fixed submission:
n = int(input())

a = list(map(int, input().split()))

a = sorted(a)

m = a[-1]
f = 1
if m % 2 == 1:
    s = m // 2 + 1
    count = 0
    if n == 2:
        if a[0] != 1 or a[1] != 1:
            f = 0
    elif a[0] != s or a[2] == s:
        f = 0
    else:
        for i in range(n):
            if a[i] < s:
                continue
            elif a[i] == s:
                if count == 0:
                    count = 1
                else:
                    count = 0
                    s += 1
            else:
                f = 0
                break
        if count == 1:
            f = 0
else:
    s = m // 2 + 1
    count = 0
    if a[0] != s-1 or a[1] == s-1:
        f = 0
    else:
        for i in range(1, n):
            if a[i] < s:
                continue
            elif a[i] == s:
                if count == 0:
                    count = 1
                else:
                    count = 0
                    s += 1
            else:
                f = 0
                break
        if count == 1:
            f = 0
        
if f == 1:
    print('Possible')
else:
    print('Impossible')