Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    #使う本数の種類
    b = set()
    matti = [2,5,5,4,5,6,3,7,6]
    for i in a:
        b.add(matti[i-1])

    dp = [-1]*(n+1)
    dp[0] = 0
    for i in range(n+1):
        for j in b:
            if i >= j:
                dp[i] = max(dp[i-j]+1, dp[i])

    keta = dp[-1]
    res = []
    a.sort(reverse=True)
    cnt = n
    while cnt>0:
        for i in a:
            if dp[cnt]-dp[cnt-matti[i-1]]==1:
                res.append(str(i))
                cnt -= matti[i-1]
                break
    print(''.join(res))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    #使う本数の種類
    b = set()
    matti = [2,5,5,4,5,6,3,7,6]
    for i in a:
        b.add(matti[i-1])

    dp = [-1]*(n+1)
    dp[0] = 0
    for i in range(n+1):
        for j in b:
            if i >= j:
                dp[i] = max(dp[i-j]+1, dp[i])

    keta = dp[-1]
    res = []
    a.sort(reverse=True)
    cnt = n
    while cnt>0:
        for i in a:
            if cnt >= matti[i-1]:
                if dp[cnt]-dp[cnt-matti[i-1]]==1:
                    res.append(str(i))
                    cnt -= matti[i-1]
                    break
    print(''.join(res))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import numpy as np

    N, K = map(int, input().split())
    H = np.array(list(map(int, input().split())) + [0] * (K + 2), dtype = np.int32) 

    INF = 10 ** 9
    cost = np.array([INF] * (N + K + 2), dtype = np.int32)
    cost[0] = 0

    n_minimum = np.minimum
    n_abs = np.abs

    for i in range(N):
        cost[i + 1: i + K + 1] = n_minimum(cost[i + 1: i + K + 1], cost[i] + n_abs(H[i + 1: i + K + 1] - H[i]))


    # print (cost)
    print (cost[N - 1])
    return

if __name__ == '__main__':
    main()


Fixed submission:
#カエル
#各足場の1つ前と2つ前を考える

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = float('inf')
    dp = [inf]*(N)
    dp[0] = 0
    for i in range(1, N):
        for j in range(1,K+1):
            if i>=j:
                dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
            else:
                continue
    print(dp[N-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#カエル
#各足場の1つ前と2つ前を考える

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = float('inf')
    dp = [inf]*(N)
    dp[0] = 0
    for i in range(1, N):
        for j in range(1,K+1):
            if i>=j:
                dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
            else:
                continue
    print(dp[N-1])

if __name__ == '__main__':
    main()

Fixed submission:
#カエル
#各足場の1つ前と2つ前を考える

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    inf = float('inf')
    dp = [inf]*(N)
    dp[0] = 0
    for i in range(1, N):
        for j in range(1,K+1):
            if i>=j:
                dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
            else:
                continue
    print(dp[N-1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007
    
    N, W = map(int,input().split())
    wv = [tuple(map(int,input().split())) for i in range(n)]
    dp = [0]*(W+1)
    for i in range(N):
        for j in range(W, wv[i][0]-1, -1):
            dp[j] = max(dp[j], dp[j-wv[i][0]]+wv[i][1])
    print(max(dp))

if __name__ == '__main__':
    main()

Fixed submission:


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

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

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    S = input().rstrip()
    T = input().rstrip()
    s = len(S)
    t = len(T)

    dp = [[0]*(t+1) for _ in range(s+1)]
    for i in range(s):
        for j in range(t):
            if S[i]==T[j]:
                dp[i+1][j+1]=dp[i][j]+1
            else:
                dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j])

    #復元
    res = ''
    while s != 0 and t != 0:
        if dp[s][t] == dp[s-1][t]:
            s -= 1
        elif dp[s][t] == dp[s][t-1]:
            t -= 1
        else:
            s -= 1
            t -= 1
            res = S[s] + res
    print(res)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    S = input().rstrip()
    T = input().rstrip()
    s = len(S)
    t = len(T)

    dp = [[0]*(t+1) for _ in range(s+1)]
    for i in range(s):
        for j in range(t):
            if S[i]==T[j]:
                dp[i+1][j+1]=dp[i][j]+1
            else:
                dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j])

    #復元
    res = ''
    while s != 0 and t != 0:
        if dp[s][t] == dp[s-1][t]:
            s -= 1
        elif dp[s][t] == dp[s][t-1]:
            t -= 1
        else:
            s -= 1
            t -= 1
            res = S[s] + res
    print(res)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N, M = map(int, input().split())
    g = [[] for _ in range(N)] #場合によって変える
    
    for _ in range(M):
        x, y = map(int, input().split())
        g[x-1].append(y-1)
    dp = [0]*N
    
    def func(i):
        for j in g[i]:
            dp[j] = max(dp[j], dp[i]+1)
            func(j)

    for i in range(N):
        if dp[i]==0:
            func(i)
    print(max(dp))


if __name__ == '__main__':
    main()

Fixed submission:
#トポロジカルソートなるもの
#再帰で書いてるところをwhileで書いてる
#要は無駄な探索(再帰呼び出し)を無くしてる
#まぁ思いつかない

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n,m = map(int,input().split())
    edge = [[] for i in range(n)]
    #st:入る辺が無い頂点
    st = []
    #to[i]:頂点iに入る辺数
    to = [0]*n
    for i in range(m):
        x,y = map(int, input().split())
        edge[x-1].append(y-1)
        to[y-1] += 1
    for i in range(n):
        if to[i] == 0:
            st.append(i)

    #dp[i]:頂点iを終点とする最長のパスの長さ
    dp = [0]*n
    while st:
        go = st.pop()
        for e in edge[go]:
            to[e] -= 1
            if to[e] == 0:
                st.append(e)
            dp[e] = max(dp[e],dp[go]+1)
    print(max(dp))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    N,K = map(int, input().split())
    a = tuple(map(int, input().split()))
    dp = [[0]*(K+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        temp = dp[i][0]
        k = a[i]
        for j in range(K+1):
            if j == 0:
                dp[i+1][j] = temp
                continue
            if j <= k:
                temp += dp[i][j]
                dp[i+1][j] = temp
            else:
                temp += dp[i][j] - dp[i][j-k-1]
                dp[i+1][j] = temp
    print(dp[N][K]%mod)


if __name__ == '__main__':
    main()

Fixed submission:
#

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    N,K = map(int, input().split())
    a = tuple(map(int, input().split()))
    dp = [[0]*(K+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        temp = dp[i][0]
        k = a[i]
        for j in range(K+1):
            if j == 0:
                dp[i+1][j] = temp
                continue
            if j <= k:
                temp += dp[i][j]
                dp[i+1][j] = temp%mod
            else:
                temp += dp[i][j] - dp[i][j-k-1]
                dp[i+1][j] = temp%mod
    print(dp[N][K]%mod)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = list(map(int, input().split()))
    b = [0] + list(accumulate(a))
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for j in range(1, N):
        for l in range(0, N-j):
            r = l + j
            temp = b[r+1] - b[l]
            #区間の境界
            for k in range(l, r):
                dp[l][r] = min(dp[l][r], dp[l][k]+dp[k+1][r]+temp)
            
    print(dp[0][-1])

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    a = list(map(int, input().split()))
    b = [0] + list(accumulate(a))
    dp = [[inf]*N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0
    for j in range(1, N):
        for l in range(0, N-j):
            r = l + j
            temp = b[r+1] - b[l]
            #区間の境界
            for k in range(l, r):
                dp[l][r] = min(dp[l][r], dp[l][k]+dp[k+1][r]+temp)
            
    print(dp[0][-1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#bitDP(再帰使用)
#forの組合せでやろうとすると男性の集合/女性の集合を分けるのが難しい

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    N = int(input())
    a = [list(map(int, input().split())) for _ in range(N)]

    #dp[s]：sは既に使った女性をbitで表していて、
    #          dp[s]は残りの男女の組合せの場合の数
    dp = [-1]*(1<<N)
    #全員相手が見つかった状態
    dp[-1] = 1

    #numは今見ている男性
    def dfs(s, num):
        #既にその状態を調べ終わっているなら返す
        if dp[s] != -1:
            return dp[s]

        #resは状態(s, num)において考えられる場合の数で
        #for文で全ての女性について考えて足している
        res = 0

        #状態sにおいて, 男性numと全ての女性とのマッチングを考える
        for i in range(N):
            #i番目の女性がまだ使っていなくて, 今見ている男性と相性が良い時
            if(s >> i) & 1 == 0 and a[num][i] == 1:
                #sを更新して, 次の男性について調べる
                #次の状態が既に調べ終わっていたらその場合の数が足される
                res += dfs(s+(1<<i), num+1)
        dp[s] = res % mod
        return dp[s]

    print(dfs(0, 0))

if __name__ == '__main__':
    main()

Fixed submission:
#bitDP(再帰使用)
#forの組合せでやろうとすると男性の集合/女性の集合を分けるのが難しい

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    N = int(input())
    a = [list(map(int, input().split())) for _ in range(N)]

    #dp[s]：sは既に使った女性をbitで表していて、
    #          dp[s]は残りの男女の組合せの場合の数
    dp = [-1]*(1<<N)
    #全員相手が見つかった状態
    dp[-1] = 1

    #numは今見ている男性
    def dfs(s, num):
        #既にその状態を調べ終わっているなら返す
        if dp[s] != -1:
            return dp[s]

        #resは状態(s, num)において考えられる場合の数で
        #for文で全ての女性について考えて足している
        res = 0

        #状態sにおいて, 男性numと全ての女性とのマッチングを考える
        for i in range(N):
            #i番目の女性がまだ使っていなくて, 今見ている男性と相性が良い時
            if(s >> i) & 1 == 0 and a[num][i] == 1:
                #sを更新して, 次の男性について調べる
                #次の状態が既に調べ終わっていたらその場合の数が足される
                res += dfs(s+(1<<i), num+1)
        dp[s] = res % mod
        return dp[s]

    print(dfs(0, 0))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    s = input()
    k = int(input())
    n = 0
    while n<=k:
        if not s[n]=='1':
            print(s[n])
            exit()
        else:
            n += 1
    print('1')


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    s = input()
    k = int(input())
    n = 0
    while n<=k-1:
        if not s[n]=='1':
            print(s[n])
            exit()
        else:
            n += 1
    print('1')


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    s = input()
    k = int(input())
    if s[0]=='1':
        print(s[1])
    else:
        print(s[0])

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    s = input()
    k = int(input())
    n = 0
    while n<=k-1:
        if not s[n]=='1':
            print(s[n])
            exit()
        else:
            n += 1
    print('1')


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    from collections import Counter
    from itertools import accumulate

    n,m = map(int, input().split())
    a = [0] + list(map(lambda x: x % M, accumulate(map(int, input().split()))))
    c = Counter(a)
    res = 0
    for k, v in c.items():
            res += v*(v-1)//2
    print(res)
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(accumulate(a))
    for i in range(n):
        b[i] %= m
    b = [0] + b
    c = Counter(b)
    res = 0
    for k, v in c.items():
            res += v*(v-1)//2
    print(res)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a, b = list(map(int, input()))
print('Yay!') if a<=8 and b<=8 else print(':(')

Fixed submission:
a, b = list(map(int, input().split()))
print('Yay!') if a<=8 and b<=8 else print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 1000000007

    N = int(input())
    dp = [inf]*(N+1)
    dp[0] = 0
    money = [1, 6, 9, 36, 81, 216, 729, 6**4, 6561, 6**5, 6**6, 59049]
    while dp[N]==inf:
        for i in range(N, 0, -1):
            for j in money:
                if i<j:
                    continue
                dp[i] = min(dp[i-j]+1, dp[i])
    print(dp[N])

if __name__ == '__main__':
    main()

Fixed submission:
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 1000000007

    N = int(input())
    dp = [inf]*(N+1)
    dp[0] = 0
    money = [1, 6, 9, 36, 81, 216, 729, 6**4, 6561, 6**5, 6**6, 59049]
    while dp[N]==inf:
        for i in range(N, 0, -1):
            for j in money:
                if i<j:
                    continue
                dp[i] = min(dp[i-j]+1, dp[i])
    print(dp[N])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

ans = 0

for i in range(n):
    ans = max(ans, len(set[:i] & set[i:]))
print(ans)

Fixed submission:
n = int(input())
s = input()
l = []
for i in range(1, n):
    cnt = 0
    for j in set(s[:i]):
        if j in list(s[i:]):
            cnt += 1
    l.append(cnt)
print(max(l))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = n
for i in range(n):
    ans = min(ans, s[i+1:].count('E') + s[:i].count('W'))
print(ans)

Fixed submission:
n = int(input())
s = list(input())
total = s[1:].count('E')
ans = s[1:].count('E')
for i in range(n-1):
    if s[i]=='W':
        total += 1
    if s[i+1]=='E':
        total -= 1
    ans = min(ans, total)
print(ans)