There are N people standing in a row from west to east.
Each person is facing east or west.
The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = E, and west if S_i = W.
You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.
Here, we do not care which direction the leader is facing.
The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.
Find the minimum number of people who have to change their directions.

-----Constraints-----
 - 2 \leq N \leq 3 \times 10^5
 - |S| = N
 - S_i is E or W.

-----Input-----
Input is given from Standard Input in the following format:
N
S

-----Output-----
Print the minimum number of people who have to change their directions.

-----Sample Input-----
5
WEEWW

-----Sample Output-----
1

Assume that we appoint the third person from the west as the leader.
Then, the first person from the west needs to face east and has to turn around.
The other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.
It is not possible to have 0 people who have to change their directions, so the answer is 1.
[{"code": "n=int(input())\ns=input()\n\ncnt=s[1:].count(\"E\")\nans=cnt\n\nfor i in range(1,n):\n  if s[i-1]==\"W\":\n    cnt+=1\n  if s[i]==\"E\":\n    cnt-=1\n  ans=min(ans,cnt)\n\nprint(ans)", "passed": true, "time": 0.31, "memory": 14076.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\n\ne_count = 0\nfor s in S:\n  if s == 'E':\n    e_count += 1\n\nmin_inv = float('infinity')\n    \nfor s in S:\n  if s == 'E':\n    e_count -= 1\n  \n  min_inv = min(e_count, min_inv)\n  \n  if s == 'W':\n    e_count += 1\n\nprint(min_inv)\n", "passed": true, "time": 0.31, "memory": 14240.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nW_cnt=[0]\nE_cnt=[0]\n\nfor ss in s:\n  w=W_cnt[-1]\n  if ss==\"W\":\n    w+=1\n  W_cnt.append(w)\n\nfor ss in reversed(s):\n  e=E_cnt[-1]\n  if ss==\"E\":\n    e+=1\n  E_cnt.append(e)\nE_cnt=E_cnt[::-1]\n\nminc=float(\"inf\")\nfor i in range(n):\n  c=(W_cnt[i] + E_cnt[i+1])\n  minc=min(minc,c)\nprint(minc)\n", "passed": true, "time": 0.14, "memory": 14120.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\nans_list = []\n\nans = S[1:].count(\"E\")\nans_list.append(ans)\n\nfor i in range(1,N):\n  if S[i-1] == \"W\":\n    ans += 1\n  if S[i] == \"E\":\n    ans -= 1\n  ans_list.append(ans)\n\nprint(min(ans_list))", "passed": true, "time": 0.21, "memory": 14240.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nnumE = [0] * N\nnumW = [0] * N\nfor i in range(N):\n    if S[i] == 'E':\n        numE[i] += 1\n    else:\n        numW[i] += 1\n    if 0 < i:\n        numE[i] += numE[i - 1]\n        numW[i] += numW[i - 1]\nans = N\nfor i in range(N):\n    if i == 0:\n        val = numE[-1] - numE[i]\n    elif i == N - 1:\n        val = numW[i - 1]\n    else:\n        val = numE[-1] - numE[i] + numW[i - 1]\n    ans = min(ans, val)\nprint(ans)", "passed": true, "time": 0.28, "memory": 14136.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\ncnt = S[1:].count(\"E\")\nans = cnt\n\nfor i in range(1,N):\n  if S[i-1] == \"W\":\n    cnt += 1\n  if S[i] == \"E\":\n    cnt -= 1\n  ans = min(ans, cnt)\n  \nprint(ans)", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "n = int(input())\ns = str(input())\nsE = s.count('E')\nsW = s.count('W')\nl = []\ne, w = 0, 0\nfor ch in s:\n    if ch == 'E':\n        e += 1\n    else:\n        w += 1\n    m = (sE-e)+w\n    l.append(sE-e+w-1 if ch == 'W' else sE-e+w)\nprint((min(l)))\n", "passed": true, "time": 0.15, "memory": 14176.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nfrom itertools import accumulate\nn = int(input())\ns = [0 if i == \"E\" else 1 for i in str(input())]\n\ns_cumsum = list(accumulate(s))\ns_cumsum_rev = list(accumulate(reversed(s)))\n\nans = 10**10\n\nfor i in range(1, n-1):\n\n    a_1 = s_cumsum[i-1]\n    a_0 = i - a_1\n    b_1 = s_cumsum_rev[-2-i]\n    b_0 = (n-1-i) - b_1\n\n    # print(a_1+b_0)\n    ans = min(ans, a_1+b_0)\n\nans = min(ans, s_cumsum[-2])\nans = min(ans, (n-1)-s_cumsum_rev[-2])\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14148.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\n\nminCount = N\nleft =  0\nright = S.count(\"E\")\nfor n in range(0, N):\n    if n != 0 and S[n-1] == \"W\":\n        left += 1\n\n    if S[n] == \"E\":\n        right -= 1\n\n    if minCount > left + right:\n        minCount = left + right\n\nprint(minCount)\n", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\n\nsum_W = [0]\nfor i in range(1, N):\n    if S[i-1] == \"W\":\n        sum_W.append(sum_W[i-1]+1)\n    else:\n        sum_W.append(sum_W[i-1])\n\nsum_E = [S[1:].count(\"E\")]\nfor i in range(0, N-1):\n    if S[i+1] == \"E\":\n        sum_E.append(sum_E[i]-1)\n    else:\n        sum_E.append(sum_E[i])\n\ncounts = []\nfor i in range(N):\n    count = 0\n    counts.append(sum_W[i]+sum_E[i])\n\nprint(min(counts))", "passed": true, "time": 1.64, "memory": 14264.0, "status": "done"}, {"code": "N=int(input())\nS=input()\na=S.count(\"E\")\nc=a\nfor s in S:\n  if s==\"E\":\n    c-=1\n  else:\n    c+=1\n  a=min(a,c)\nprint(a)\n", "passed": true, "time": 0.14, "memory": 14052.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nres = n\ne = s.count(\"E\")\n\nl_w = 0\nl_e = 0\nfor i in range(n):\n    if i == n - 1 and s[i] == \"E\":\n        l_e += 1\n    tmp = l_w + (e - l_e)\n    res = min(tmp, res)\n    if s[i] == \"W\":\n        l_w += 1\n    else:\n        l_e += 1\nprint(res)\n", "passed": true, "time": 1.76, "memory": 14076.0, "status": "done"}, {"code": "n = int(input())\ns = str(input())\nleft = s[0]\nans = 10**6\nleft = {}\nleft.setdefault('W',0)\nleft.setdefault('E',0)\nright = {}\nright.setdefault('E',0)\nright.setdefault('W',0)\nfor i in range(n):\n    right[s[i]] += 1\nans = 10**6\nfor i in range(n):\n    right[s[i]] -= 1\n    ans = min(ans,left['W']+right['E'])\n    #print(left,right)\n    left[s[i]] += 1\nprint(ans)\n    \n", "passed": true, "time": 0.15, "memory": 14288.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nw = [0]*n\ne = [0]*n\nif s[0] == \"W\": w[0] = 1\nelse: e[0] = 1\nfor i in range(1,n):\n  if s[i] == \"W\":\n    w[i] = w[i-1]+1\n    e[i] = e[i-1]\n  else:\n    w[i] = w[i-1]\n    e[i] = e[i-1]+1\n\nans = float(\"inf\")\nfor i in range(n):\n  t = 0\n  if i != 0: t += w[i-1]\n  if i != n-1: t += e[-1] - e[i]\n  if t < ans: ans = t\nprint(ans)  ", "passed": true, "time": 0.14, "memory": 14104.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(10**8)\ndef ii(): return int(sys.stdin.readline())\ndef mi(): return map(int, sys.stdin.readline().split())\ndef li(): return list(map(int, sys.stdin.readline().split()))\ndef li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]\ndef dp2(ini, i, j): return [[ini]*i for _ in range(j)]\n#import bisect #bisect.bisect_left(B, a)\n#from collections import defaultdict #d = defaultdict(int) d[key] += value\n#from collections import Counter # a = Counter(A).most_common()\nfrom itertools import accumulate #list(accumulate(A))\n\nN = ii()\nS = input()\ncnt = [0] * N\n\nfor i in range(N):\n    if S[i] == 'W':\n        cnt[i] = 1\n\ncnt = list(accumulate(cnt))\nans = N\n\nfor i in range(N):\n    if S[i] == 'E':\n        ans = min(ans, cnt[i] + (N-1-i)-(cnt[-1]-cnt[i]))\n    else:\n        ans = min(ans, i+1-cnt[i] + (N-1-i)-(cnt[-1]-cnt[i]))\n\nprint(ans)", "passed": true, "time": 0.2, "memory": 14324.0, "status": "done"}, {"code": "N=int(input())\nS=list(input())\ne,w=[0]*(N+1),[0]*(N+1)\nfor i in range(1,N+1):\n    w[i] += w[i-1] + (1 if S[i-1]=='W' else 0)\n    e[i] += e[i-1] + (1 if S[i-1]=='E' else 0)\nans=N\nfor i in range(N):\n    ans=min(ans,w[i]+e[-1]-e[i+1])\nprint(ans)", "passed": true, "time": 0.18, "memory": 14056.0, "status": "done"}, {"code": "import math\nfrom math import gcd,pi,sqrt\nINF = float(\"inf\")\n\nimport sys\nsys.setrecursionlimit(10**6)\nimport itertools\nfrom collections import Counter,deque\ndef i_input(): return int(input())\ndef i_map(): return list(map(int, input().split()))\ndef i_list(): return list(i_map())\ndef i_row(N): return [i_input() for _ in range(N)]\ndef i_row_list(N): return [i_list() for _ in range(N)]\ndef s_input(): return input()\ndef s_map(): return input().split()\ndef s_list(): return list(s_map())\ndef s_row(N): return [s_input for _ in range(N)]\ndef s_row_str(N): return [s_list() for _ in range(N)]\ndef s_row_list(N): return [list(s_input()) for _ in range(N)]\n\n\ndef main():\n    n = i_input()\n    s = input()\n\n    ans = 0\n    for i in s[1:]:\n        if i == \"E\":\n            ans += 1\n    l = [ans]\n\n    for i in range(n-1):\n        trial = 0\n        if s[i] == \"W\":\n            trial += 1\n        if s[i+1] == \"E\":\n            trial -= 1\n        ans += trial\n        l.append(ans)\n\n    print((min(l)))\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\ns = input()\narr = []\nE = s.count('E')\nw = 0\ne = 0\nfor i in range(n):\n  if s[i] == 'W':\n    arr.append(w + E - e)\n    w += 1\n  else:\n    arr.append(w + E - e - 1)\n    e += 1\nans = min(arr)\nprint(ans)", "passed": true, "time": 0.3, "memory": 14220.0, "status": "done"}, {"code": "N = int(input())\nS = input()\ne = S.count(\"E\")\ncnt = e\nfor i in S:\n    if i == \"E\":\n        cnt -= 1\n    else:\n        cnt += 1\n    e = min(e, cnt)\nprint(e)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "import sys\nread = sys.stdin.read\nreadlines = sys.stdin.readlines\nfrom itertools import accumulate\ndef main():\n    n = int(input())\n    s = list(input())\n    enum = [1 if c == 'E' else 0 for c in s]\n    wnum = [1 if c == 'W' else 0 for c in s]\n    enuma = tuple(accumulate(enum))\n    wnuma = tuple(accumulate(wnum))\n    wnumm = wnuma[-1]\n    wnuma2 = [wnumm - wn for wn in wnuma]\n    num = max(wnuma2[0], enuma[-2])\n    for i1 in range(1, n - 1):\n        num = max(num, enuma[i1 - 1] + wnuma2[i1])\n    r = n - num - 1\n    print(r)\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14100.0, "status": "done"}, {"code": "#\n# abc096 c\n#\n\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n    def assertIO(self, input, output):\n        stdout, stdin = sys.stdout, sys.stdin\n        sys.stdout, sys.stdin = StringIO(), StringIO(input)\n        resolve()\n        sys.stdout.seek(0)\n        out = sys.stdout.read()[:-1]\n        sys.stdout, sys.stdin = stdout, stdin\n        self.assertEqual(out, output)\n\n    def test_\u5165\u529b\u4f8b_1(self):\n        input = \"\"\"5\nWEEWW\"\"\"\n        output = \"\"\"1\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_2(self):\n        input = \"\"\"12\nWEWEWEEEWWWE\"\"\"\n        output = \"\"\"4\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_3(self):\n        input = \"\"\"8\nWWWWWEEE\"\"\"\n        output = \"\"\"3\"\"\"\n        self.assertIO(input, output)\n\n\ndef resolve():\n    N = int(input())\n    S = list(input())\n\n#    ans = float(\"inf\")\n#    for i in range(N):\n#        if i == 0:\n#            ans = min(ans, S[1:].count(\"E\"))\n#        elif i == N-1:\n#            ans = min(ans, S[0:N-1].count(\"W\"))\n#        else:\n#            ans = min(ans, S[0:i].count(\"W\") + S[i+1:].count(\"E\"))\n#    print(ans)\n\n    W = [0] * N\n    E = [0] * N\n    L = 0\n    R = 0\n\n    for i in range(N):\n        if S[i] == \"W\":\n            L += 1\n        if S[N-1-i] == \"E\":\n            R += 1\n        W[i] = L\n        E[N-1-i] = R\n\n    ans = float(\"inf\")\n    for i in range(N):\n        ans = min(ans, E[i]+W[i]-1)\n    print(ans)\n\n\ndef __starting_point():\n    # unittest.main()\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "EW=0\nans=99999999999999999999999999999999\n\nN=int(input())\nS=input()\n\nfor i in range(N):\n    if i==0:\n        pass\n    elif S[i]==\"E\":\n        EW+=1\nif ans>EW:\n    ans=EW\n\nfor j in range(1,N):\n    if S[j]==\"E\":\n        EW-=1\n    if S[j-1]==\"W\":\n        EW+=1\n\n    if ans>EW:\n        ans=EW\nprint(ans)\n", "passed": true, "time": 0.2, "memory": 14272.0, "status": "done"}, {"code": "N=int(input())\nS=list(input())\ne,w=[0]*(N+1),[0]*(N+1)\nfor i in range(1,N+1):\n    w[i] += w[i-1] + (1 if S[i-1]=='W' else 0)\n    e[i] += e[i-1] + (1 if S[i-1]=='E' else 0)\nans=N\nfor i in range(N):\n    ans=min(ans,w[i]+e[-1]-e[i+1])\nprint(ans)", "passed": true, "time": 0.23, "memory": 14256.0, "status": "done"}, {"code": "n=int(input())\ns=input()\n\ndef count(n,s):\n    cntw=0\n    cnte=0\n    mcntw=0\n    mcnte=0\n    maxn=0\n    for i in range(n):\n        if s[i]==\"W\":\n            cntw+=1\n        else:\n            cnte+=1\n        if maxn<cnte-cntw:\n            maxn=cnte-cntw\n            mcnte=cnte\n            mcntw=cntw\n\n    if cntw==0 or cnte==0:\n        print((0))\n        return\n\n    else:\n        print((mcntw+cnte-mcnte))\n        return\ncount(n,s)\n\n", "passed": true, "time": 0.14, "memory": 14196.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\n\nans = N\n\nleft_W = 0\nright_E = S[1:].count(\"E\")\n\nfor n in range(N):\n  if n == 0:\n    ans = min(ans,S[1:].count(\"E\"))\n        \n  elif n == N-1 :\n    ans = min(ans,S[:n].count(\"W\"))\n      \n  else:\n    if S[n] == \"E\":\n      right_E -= 1\n    if S[n-1] == \"W\":\n      left_W += 1\n    ans = min(ans,left_W + right_E)\n\nprint(ans)", "passed": true, "time": 0.21, "memory": 14064.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nans =  S.count(\"E\")\nleft = 0\nright = ans\nfor i in S:\n    if i == \"E\":\n        right -= 1\n        ans = min(ans,right+left)\n    if i == \"W\":\n        ans = min(ans,right+left)\n        left += 1\nprint(ans)", "passed": true, "time": 0.24, "memory": 14084.0, "status": "done"}, {"code": "# import itertools\n# import math\n# import sys\n# sys.setrecursionlimit(500*500)\n# import numpy as np\n# import heapq\n# from collections import deque\n\nN = int(input())\nS = input()\n# n, *a = map(int, open(0))\n# N, M = map(int, input().split())\n# A = list(map(int, input().split()))\n# B = list(map(int, input().split()))\n# tree = [[] for _ in range(N + 1)]\n# B_C = [list(map(int,input().split())) for _ in range(M)]\n# S = input()\n\n# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])\n# all_cases = list(itertools.permutations(P))\n# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))\n# itertools.product((0,1), repeat=n)\n\n# A = np.array(A)\n# cum_A = np.cumsum(A)\n# cum_A = np.insert(cum_A, 0, 0)\n\n# def dfs(tree, s):\n#     for l in tree[s]:\n#         if depth[l[0]] == -1:\n#             depth[l[0]] = depth[s] + l[1]\n#             dfs(tree, l[0])\n# dfs(tree, 1)\n\n# def factorization(n):\n#     arr = []\n#     temp = n\n#     for i in range(2, int(-(-n**0.5//1))+1):\n#         if temp%i==0:\n#             cnt=0\n#             while temp%i==0:\n#                 cnt+=1\n#                 temp //= i\n#             arr.append([i, cnt])\n#     if temp!=1:\n#         arr.append([temp, 1])\n#     if arr==[]:\n#         arr.append([n, 1])\n#     return arr\n\nnum_E = [0] * N\nnum_W = [0] * N\nmax_num = 0\nleader_index = 0\nfor i, c in enumerate(S):\n    if c == \"W\":\n        num_W[i] = num_W[i - 1] + 1\n        num_E[i] = num_E[i - 1]\n    else:\n        num_W[i] = num_W[i - 1]\n        num_E[i] = num_E[i - 1] + 1\n    tmp = num_E[i] - num_W[i]\n    if max_num < tmp:\n        leader_index = i\n        max_num = tmp\n\nprint(S[:leader_index].count(\"W\") + S[leader_index + 1:].count(\"E\"))", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nl = [0]*n\nr = [0]*n\nfor i in range(1, n):\n    l[i] = l[i-1] + (s[i-1] == 'W')\nfor i in range(n-2, -1, -1):\n    r[i] = r[i+1] + (s[i+1] == \"E\")\nans = n-1\nfor i in range(n):\n    ans = min(ans, l[i]+r[i])\nprint(ans)\n\n", "passed": true, "time": 0.14, "memory": 14192.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nl = [0] * n\nr = [0] * n\nans = n\nfor i in range(n):\n    if i == 0:\n        if s[0] == \"W\":\n            l[0] = 1\n    elif s[i] == \"W\":\n        l[i] = l[i - 1] + 1\n    else:\n        l[i] = l[i - 1]\n    if i == 0:\n        if s[-1] == \"E\":\n            r[0] = 1\n    elif s[-i-1] == \"E\":\n        r[i] = r[i - 1] + 1\n    else:\n        r[i] = r[i - 1]\nfor i in range(n):\n    if i == 0:\n        ans = min(ans, r[n - 1 - i])\n    elif i == n - 1:\n        ans = min(ans, l[i - 1])\n    else:\n        ans = min(ans, l[i - 1] + r[n - 1 - i])\nprint(ans)", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\nA = [0]*N\nB = [0]*N\n\nfor i in range(1, N):\n    A[i] = A[i-1] + (1 if S[i-1]=='W' else 0)\n    B[N-i-1] = B[N-i] + (1 if S[N-i]=='E' else 0)\n\nprint(min(map(lambda x: x[0]+x[1], zip(A, B))))", "passed": true, "time": 0.14, "memory": 14060.0, "status": "done"}, {"code": "import math\n\nn = int(input())\ns = input()\n\neS = [0] * n\nwS = [0] * n\n\nec = 0\nfor i in range(n):\n    eS[i] = ec\n    if s[i] == \"W\":\n        ec += 1\n\nwc = 0\nfor i in reversed(list(range(n))):\n    wS[i] = wc\n    if s[i] == \"E\":\n        wc += 1\n\nans = 10000000\n\nfor i in range(n):\n    ans = min(ans, eS[i] + wS[i])\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "n = int(input())\ns = input()\ne = s.count('E')\nw = s.count('W')\nans = 1000000\ne_counter = 0\nw_counter = 0\nfor i in range(len(s)):\n    if s[i] == 'E':\n        e_counter += 1\n    else:\n        w_counter += 1\n    d = w_counter\n    if s[i] == 'W':\n        d -= 1\n    ans1 = d + (e - e_counter)\n    ans = min(ans1, ans)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14292.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\ndirected = [S[1:].count(\"W\")]\n\nfor i in range(1, len(S)):\n  d = directed[i - 1]\n  if S[i - 1] == \"E\":\n    d += 1\n  if S[i] == \"W\":\n    d -= 1\n  directed.append(d)\n\nprint(N - max(directed) - 1)", "passed": true, "time": 0.14, "memory": 14036.0, "status": "done"}, {"code": "n=int(input())\ns=list(input())\nsw=[0]\nse=[0]\nswc=0\nsec=0\nfor i in range(n):\n    if s[i]=='W':\n        swc+=1\n    else:\n        sec+=1\n    sw.append(swc)\n    se.append(sec)\nm=n\nfor i in range(n+1):\n    m=min(m,sw[i]+se[-1]-se[i])\nprint(m)", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "\nn = int(input())\nA =input()\ne = A.count('E')\ncnt = e\n\nfor i in A:\n    if i == 'E':\n        cnt -= 1\n    else:\n        cnt += 1\n    e = min(e,cnt)\n\nprint(e)", "passed": true, "time": 0.14, "memory": 14056.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat Sep 19 20:18:57 2020\n\n@author: liang\n\"\"\"\n\nN = int(input())\nS = input()\n\ntmp = 0\n\nfor i in range(1,N):\n    if S[i] == \"E\":\n        tmp += 1\n\nans = 10**6\nfor i in range(N):\n    if ans > tmp:\n        ans = tmp\n    if i == N-1:\n        break\n    if S[i] == \"W\":\n        tmp += 1\n    if S[i+1] == \"E\":\n        tmp -= 1\n    #print(tmp)\n        \nprint(ans)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\n\nw_cnt = 0\ne_cnt = 0\nw_lst = []\ne_lst = []\n\nfor s in S:\n    if s == 'W':\n        w_cnt += 1\n\n    else:\n        e_cnt += 1\n\n    w_lst.append(w_cnt)\n    e_lst.append(e_cnt)\n\nans = float('inf')\ne_all = e_lst[-1]\nfor i in range(N):\n    if S[i] == 'W':\n        t = w_lst[i] - 1 + e_all - e_lst[i]\n    else:\n        t = w_lst[i] + e_all - e_lst[i]\n\n    ans = min(ans, t)\n\n\nprint(ans)", "passed": true, "time": 0.23, "memory": 14120.0, "status": "done"}, {"code": "n = int(input())\na = list(input())\nwcnt,ecnt,ans,box = 0,0,0,[]\nW = a.count(\"W\")\nE = a.count(\"E\")\nfor i in range(n-1):\n  if a[i] == \"W\":\n    box.append(E+wcnt)\n    wcnt += 1\n    W -= 1\n  else:\n    box.append(E+wcnt)\n    ecnt += 1\n    E -= 1\nif a[n-1] == \"W\":\n  W -= 1\n  box.append(E+wcnt)\n  wcnt += 1\nelse:\n  E -= 1\n  box.append(E+wcnt)\n  ecnt += 1\nprint(min(box))", "passed": true, "time": 0.21, "memory": 14088.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\ne_all = s.count(\"E\")\nw_all = s.count(\"W\")\ne_l = 0\nw_l = 0\n\nunti = [0] * n\n\nfor i in range(n):\n    if s[i] == \"E\":\n        e_l += 1\n        unti[i] = w_l + (e_all - e_l) \n    if s[i] == \"W\":\n        unti[i] = w_l + (e_all - e_l) \n        w_l += 1\n\n\n#print(unti)\nprint(min(unti))", "passed": true, "time": 0.14, "memory": 14160.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nleft = [0] * n\nright = [0] * n\n\ntmp = 0\nfor i in range(1, n):\n    if s[i - 1] == \"W\":\n        tmp += 1\n        left[i] = tmp\n    else:\n        left[i] = tmp\n\ntmp = 0\nfor i in range(n - 2, -1, -1):\n    if s[i + 1] == \"E\":\n        tmp += 1\n        right[i] = tmp\n    else:\n        right[i] = tmp\n\nres = 10**9\nfor i in range(n):\n    res = min(res, left[i] + right[i])\nprint(res)\n", "passed": true, "time": 0.28, "memory": 14100.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\nEP = [0]*(N+1)\nWP = [0]*(N+1)\nCP = [0]*N\nfor T in range(0,N):\n    EP[N-T-1] = EP[N-T]+(S[N-1-T]=='E')\n    WP[T+1] = WP[T]+(S[T]=='W')\nfor T in range(0,N):\n    CP[T] = EP[T+1]+WP[T]\nprint(min(CP))", "passed": true, "time": 0.28, "memory": 14000.0, "status": "done"}, {"code": "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef main():\n    N = int(readline())\n    S = readline().strip()\n\n    east = [0] * (N + 1)\n    west = [0] * (N + 1)\n    for i in range(N):\n        east[i + 1] = east[i] + (1 if S[i] == 'E' else 0)\n        west[i + 1] = west[i] + (1 if S[i] == 'W' else 0)\n\n    ans = INF\n    for i in range(N):\n        if ans > west[i] + east[N] - east[i + 1]:\n            ans = west[i] + east[N] - east[i + 1]\n\n    print(ans)\n    return\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14224.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nv=[0 for i in range(n)]\n\nfor i in range(n):\n    j=0\n    if s[i]==\"E\":\n        j=1\n    else:\n        j=-1\n    if i==0:\n        v[i]+=j\n    else:\n        v[i]+=j+v[i-1]\n\nsum=-2\nw=0\nres=\"\"\nfor i in range(n):\n    if sum<v[i]:\n        sum=v[i]\n        wmax=w\n        emax=i-w\n        res=s[i]\n    if s[i]==\"W\":\n        w+=1\n\nif res==\"W\":\n    print((wmax+s.count(\"E\")-emax))\nelse:\n    print((wmax+s.count(\"E\")-emax-1))\n", "passed": true, "time": 0.23, "memory": 14292.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\nallW = S.count('W')\nallE = S.count('E')\nnumW = S.count('E')\nnumE = 0\nans = 3*10**5\nfor i in range(N):\n    if S[i] == 'E':\n        numW -= 1\n    ans = min(ans,numW + numE)\n    if S[i] == 'W':\n        numE += 1   \nprint(ans)", "passed": true, "time": 0.16, "memory": 14076.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\n\nlst = [0]*N\nRe = S.count(\"E\")\nLw = 0\n\nfor i in range(N):\n    if S[i] == \"E\":\n        Re -= 1\n        lst[i] = Re + Lw\n    else:\n        Lw += 1\n        lst[i] = Re + Lw - 1\n\nans = min(lst)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "n=int(input())\ns=input()\n\ndp_w=[0]\ndp_e=[0]\n\nfor i in range(n):\n    if i!=0:\n        dp_w.append(dp_w[-1])\n        dp_e.append(dp_e[-1])\n    if s[i]==\"W\":\n        dp_w[-1]+=1\n    else:\n        dp_e[-1]+=1\n\ndef migi(i):\n    if i==n-1:\n        return 0\n    return dp_e[n-1]-dp_e[i]\ndef hidari(i):\n    if i==0:\n        return 0\n    return dp_w[i-1]\nans=1000000000000000\nfor i in range(n):\n    right=migi(i)\n    left=hidari(i)\n    ans=min(right+left,ans)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14196.0, "status": "done"}, {"code": "n = int(input())\ns = list(input())\ncnt = 0\nans_list = [0]\ne_cnt = 0\n\nfor i in range(1,n):\n    if s[i-1] == \"E\" and s[i] == \"E\":\n        cnt -= 1\n        e_cnt += 1\n    if s[i-1] == \"E\" and s[i] == \"W\":\n        cnt -= 0\n    if s[i-1] == \"W\" and s[i] == \"E\":\n        cnt += 0\n        e_cnt += 1\n    if s[i-1] == \"W\" and s[i] == \"W\":\n        cnt += 1\n    ans_list.append(cnt)\n\nprint(min(ans_list) + e_cnt)", "passed": true, "time": 0.16, "memory": 14312.0, "status": "done"}, {"code": "from collections import Counter\nn = int(input())\ns = input()\nsn = Counter(s)\n\nl = 0\nr = sn['E']\n\nans = r\nfor i in range(n):\n    if s[i] == 'W':\n        l += 1\n    else:\n        r -= 1\n    ans = min(ans, l+r)\nprint(ans)\n", "passed": true, "time": 0.19, "memory": 14268.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nw = [0]*n\ne = [0]*n\n\nif s[0] == \"W\": w[0] += 1\nelse: e[0] += 1\nfor i in range(1,n):\n  if s[i] == \"W\":\n    w[i] = w[i-1]+1\n    e[i] = e[i-1]\n  else:\n    w[i] = w[i-1]\n    e[i] = e[i-1]+1\n\nans = float(\"inf\")\nif e[n-1]-e[0] < ans: ans = e[n-1]-e[0]\nif w[n-1] < ans: ans = w[n-1]\n\nfor i in range(1,n-1):\n  t = w[i-1] + e[n-1]-e[i]\n  if t < ans: ans = t\nprint(ans)", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nans = [0]*(n+1)\nfor i in range(n):\n  if s[i] == 'E':\n    ans[i+1] = ans[i] + 1\n  else:\n    ans[i+1] = ans[i]\n    \nprint(min(i-ans[i]+ans[n]-ans[i+1] for i in range(n)))", "passed": true, "time": 0.14, "memory": 14140.0, "status": "done"}, {"code": "def count(left_w, right_e):\n    return left_w + right_e\n\n\ndef main():\n    n = int(input())\n    s = str(input())\n\n    w_count = s.count('W')\n    e_count = n - w_count\n\n    lst = []\n    left = 0\n    left_w = 0\n    right = n\n    right_e = e_count\n    for i in range(n):\n        s_alp = s[i]\n        right -= 1\n        if s_alp == 'E':\n            right_e -= 1\n\n        lst.append(count(left_w, right_e))\n\n        left += 1\n        if s_alp == 'W':\n            left_w += 1\n\n    minimum = min(lst)\n    print(minimum)\n\n\ndef __starting_point():\n    main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14304.0, "status": "done"}, {"code": "n = int(input())\ns = input()\ne = s.count(\"E\")\nw = n - e\nans = 10**9\nif s[0] == \"W\":\n    cnt = e\nelse:\n    cnt = e-1\nnum = cnt\nfor i in range(n-1):\n    if s[i] == s[i+1] and s[i] == \"E\":\n        cnt -= 1\n    elif s[i] == s[i+1]:\n        cnt += 1\n    ans = min(ans,cnt,num)\n    ans = max(ans,0)\nprint(max(ans,0))", "passed": true, "time": 0.15, "memory": 14260.0, "status": "done"}, {"code": "n=int(input())\ns=list(input())\nans=[0]*n\nans[0]+=list(s[1:]).count(\"E\")\nfor i in range(1,n):\n    if s[i]==\"E\" and s[i-1]==\"E\":\n        ans[i]=ans[i-1]-1\n    elif (s[i]==\"E\" and s[i-1]==\"W\") or (s[i-1]==\"E\" and s[i]==\"W\"):\n        ans[i]=ans[i-1]    \n    else:\n        ans[i]=ans[i-1]+1\nprint(min(ans))", "passed": true, "time": 0.14, "memory": 14196.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\nN = int(input())\nS = list(input())\n\nW = [0] * N\nE = [0] * N\n\nW_pre = E_pre = 0\nfor i in range(N):\n    if S[i] == \"W\":\n        W[i] = W_pre + 1\n        E[i] = E_pre\n    else:\n        W[i] = W_pre\n        E[i] = E_pre + 1\n    W_pre = W[i]\n    E_pre = E[i] \n\nans = N\nfor i in range(N):\n    if i>0:\n        res1 = W[i-1]\n    else:\n        res1 = 0\n    res2 = E[N-1]-E[i]\n    #print(i,res1,res2)\n    ans = min(ans,res1+res2)\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14100.0, "status": "done"}, {"code": "N = int(input())\nS = input()\na = S.count(\"E\")\nc = a \n\nfor s in S:\n  if s==\"E\":\n    c-=1\n  else:\n    c+=1\n  a=min(a,c)\n\nprint(a)", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nl = 0\nr = S[1:N].count('E')\nans = l+r\n\nfor n in range(1,N):\n  if S[n-1]==\"W\":\n    l+=1\n  if S[n]==\"E\":\n    r-=1\n  ans=min(ans,l+r)\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\ncount = s.count('E')\nans = s.count('E')\nfor i in range(len(s)):\n    if s[i] == 'E':\n        count -=1\n    else:\n        count+=1\n    ans = min(count,ans)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "import sys, re, os\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd\nfrom itertools import permutations, combinations, product, accumulate\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom functools import reduce\nfrom bisect import bisect_left, insort_left\nfrom heapq import heapify, heappush, heappop\n\nINPUT = lambda: sys.stdin.readline().rstrip()\nINT = lambda: int(INPUT())\nMAP = lambda: list(map(int, INPUT().split()))\nS_MAP = lambda: list(map(str, INPUT().split()))\nLIST = lambda: list(map(int, INPUT().split()))\nS_LIST = lambda: list(map(str, INPUT().split()))\n\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef main():\n    N = INT()\n    S = INPUT()\n\n    left, right = 0, S[1:].count('E')\n    ans = left + right\n    for i in range(N-1):\n        if S[i] == 'W':\n            left += 1\n        if S[i+1] == 'E':\n            right -= 1\n\n        ans = min(ans, left + right)\n\n    print(ans)\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14184.0, "status": "done"}, {"code": "# import sys\n# sys.setrecursionlimit(10 ** 6)\n# import bisect\n# # from collections import deque\n# from decorator import stop_watch\n#\n#\n# @stop_watch\ndef solve(N, S):\n    W_sum = [0]\n    E_sum = [0]\n    for s in list(S):\n        if s == 'W':\n            W_sum.append(W_sum[-1] + 1)\n            E_sum.append(E_sum[-1])\n        else:\n            W_sum.append(W_sum[-1])\n            E_sum.append(E_sum[-1] + 1)\n\n    ans = N + 1\n    for i in range(1, N + 1):\n        ans = min(W_sum[i - 1] + (E_sum[-1] - E_sum[i]), ans)\n\n    print(ans)\n\n\n\ndef __starting_point():\n    N = int(input())\n    S = input()\n    solve(N, S)\n\n    # # test\n    # from random import randint\n    # from func import random_str\n    # solve()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "n=int(input())\ns=list(input())\n\nE=s.count('E')\nW=s.count('W')\n\nif s[0]=='E':\n  ans=E-1\nelse:\n  ans=E\n  \nans1=[]\nans1.append(ans)\n  \nfor x in range(1,n):\n  if s[x]=='E':\n    if s[x-1]=='E':\n      ans-=1\n      \n  else:\n    if s[x-1]=='W':\n      ans+=1\n  ans1.append(ans)\n  \nprint(min(ans1))", "passed": true, "time": 0.18, "memory": 14104.0, "status": "done"}, {"code": "def main():\n    N = int(input())\n    S = input()\n    lst = [0] * N\n    ans = N\n\n    if S[0] == \"E\":\n        lst[0] = 1\n    for i in range(1, N):\n        if S[i] == \"E\":\n            lst[i] = lst[i - 1] + 1\n        else:\n            lst[i] = lst[i - 1]\n\n    for i in range(N):\n        if i == 0:\n            left = 0\n        else:\n            left = i - lst[i - 1]\n        right = lst[N - 1] - lst[i]\n\n        if left + right < ans:\n            ans = left + right\n\n    print(ans)\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.44, "memory": 14188.0, "status": "done"}, {"code": "N = int(input())\nS = list(input())\nE = S[1:].count('E')\nW = 0\nmi = E+W\nfor i in range(1,N):\n    if S[i] == 'E':E -= 1\n    if S[i-1] == 'W':W+=1\n    if E+W <= mi:mi = E+W\nprint(mi)\n", "passed": true, "time": 0.6, "memory": 14148.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\nwest = [0]*N\neast = [0]*N\n\ntmp = 0\nfor i in range(1,N):\n    if S[i-1] == 'W':\n        tmp += 1\n        west[i] = tmp\n    else:\n        west[i] = tmp\n\ntmp = 0\nfor i in range(N-2,-1,-1):\n    if S[i+1] == 'E':\n        tmp += 1\n        east[i] = tmp\n    else:\n        east[i] = tmp\n\nans = float('inf')\nfor i in range(N):\n    ans = min(ans,west[i]+east[i])\nprint (ans)\n", "passed": true, "time": 0.2, "memory": 14260.0, "status": "done"}, {"code": "import sys\n\nN = int(input())\nS = input()\n\nW = [0]*N\nE = [0]*N\nans = N\nfor i in range(1, N):\n    W[i] = W[i-1]+1 if S[i-1]=='W' else W[i-1]\n    E[-i-1] = E[-i]+1 if S[-i]=='E' else E[-i]\n\nfor i in range(N):\n    ans = min(W[i]+E[i], ans)\n\nprint(ans)\n\n\n\n", "passed": true, "time": 0.26, "memory": 14192.0, "status": "done"}, {"code": "n=int(input())\nS=list(input())\nW=[0]*(n+1)\nE=[0]*(n+1)\nfor i in range(n):\n  W[i]=W[i-1]+S[i].count(\"W\")\n  E[n-i-1]=E[n-i]+S[n-i-1].count(\"E\")\nW = W[:n]\nE = E[:n]\nans = 1000000\nfor i in range(n):\n  ans = min(ans,W[i]+E[i]-1)\nprint(ans)\n", "passed": true, "time": 0.2, "memory": 14204.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nW=0 ; E=s[1:].count(\"E\")\nans=float(\"inf\")\nfor i in range(n):\n    ans=min(ans, W+E)\n    if i==n-1:print(ans);return\n    if s[i]==\"W\":\n        W+=1\n    if s[i+1]==\"E\":\n        E-=1", "passed": true, "time": 0.2, "memory": 14308.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\ne_all = S.count('E')\n\nw_cnt = 0\ne_cnt = 0\nans = float('inf')\nfor i in range(N):\n    if S[i] == 'W':\n        w_cnt += 1\n        ans = min(ans, w_cnt - 1 + e_all - e_cnt)\n    else:\n        e_cnt += 1\n        ans = min(ans, w_cnt + e_all - e_cnt)\n\nprint(ans)\n", "passed": true, "time": 0.2, "memory": 14136.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nfrom collections import Counter\ncount = Counter(s[1:])\nx = count[\"E\"]\n\ntemp =x\nfor i in range(1,n):\n    if s[i-1] ==\"W\":\n        x +=1\n    if s[i] ==\"E\":\n        x -=1\n    temp = min(temp,x)\n\nprint(temp)        ", "passed": true, "time": 0.23, "memory": 14284.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nres = n\nw = 0\ne = 0\nfor i in range(n):\n    if s[i] == \"W\":\n        w += 1\n    else:\n        e += 1\n\nl_w = 0\nl_e = 0\nfor i in range(n):\n    if i == n - 1 and s[i] == \"E\":\n        l_e += 1\n    tmp = l_w + (e - l_e)\n    res = min(tmp, res)\n    if s[i] == \"W\":\n        l_w += 1\n    else:\n        l_e += 1\nprint(res)\n", "passed": true, "time": 0.14, "memory": 14192.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nwest = S.count('W')\neast = N - west \nQ = [0,0,west,east] #[\u81ea\u5206\u3088\u308a\u897f\u3067\u897f\u5411\u304d\u3001\u6771\u5411\u304d\u3001\u81ea\u5206\u3088\u308a\u6771\u3067\u897f\u5411\u304d\u3001\u6771\u5411\u304d]\nans = N-1\nfor i in range(N):\n    if S[i]=='W':\n        Q[2]-=1\n        cnt = Q[0]+Q[3]\n        Q[0]+=1\n    else:\n        Q[3]-=1\n        cnt = Q[0]+Q[3]\n        Q[1]+=1\n    ans = min(ans,cnt)\nprint(ans)", "passed": true, "time": 0.39, "memory": 14172.0, "status": "done"}, {"code": "N = int(input())\nr = input()\n\nE_sum = sum(x == \"E\" for x in r)\nW_sum = N-E_sum\nleft_sum = 0\nright_sum = E_sum\nmin_sum = E_sum\nfor i in range(N):\n  if i == 0:\n    if r[i] == \"E\":\n      min_sum -= 1\n    prev_sum = min_sum\n  else:\n    if (r[i-1], r[i]) == (\"W\", \"W\"):\n      prev_sum += 1\n    elif (r[i-1], r[i]) == (\"E\", \"W\"):\n      pass\n    elif (r[i-1], r[i]) == (\"E\", \"E\"):\n      prev_sum -= 1\n    elif (r[i-1], r[i]) == (\"W\", \"E\"):\n      pass\n  if min_sum > prev_sum:\n    min_sum = prev_sum\n\nprint(min_sum)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "#!/usr/bin/env python\n\nn = int(input())\ns = input()\n\ntotal_E = s.count('E')\ntotal_W = n-total_E\n\nright_E = []\ntmp_E = total_E\ntmp_W = 0 \nfor i in range(n):\n    if s[i] == 'E':\n       tmp_E -= 1 \n    right_E.append(tmp_E)\n\nleft_W = [0] \nfor i in range(1,n):\n    if s[i-1] == 'W':\n       tmp_W += 1 \n    left_W.append(tmp_W)\n\ncandidates = []\nfor i in range(n):\n    candidates.append(right_E[i]+left_W[i])\n\n#print('candidates =', candidates)\n#print('right_E =', right_E)\n#print('left_W =', left_W)\nans = min(candidates)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14072.0, "status": "done"}, {"code": "n = int(input())\ns = [(i == \"W\")*1 for i in list(input())]\nc = [0]*(n+1)\nfor i in range(n):\n    c[i+1] = c[i] + s[i]\nans = float(\"inf\")\nfor i in range(n):\n    t = c[i] + (n-i-1-c[-1]+c[i+1])\n    ans = min(ans,t)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14256.0, "status": "done"}, {"code": "inf = float('inf')\nn = int(input())\ns = input()\n\nright_e = s.count(\"E\")\nleft_w = 0\ncnt = inf\n\nfor e in s:\n  if e == \"W\":\n    cnt = min(cnt, right_e + left_w)\n    left_w += 1\n  else:\n    right_e -= 1\n    cnt = min(cnt, right_e + left_w)\nprint(cnt)", "passed": true, "time": 0.14, "memory": 14192.0, "status": "done"}, {"code": "N=int(input())\nS=input()\na=[0]\nfor i in range(N):\n    a.append(a[-1])\n    if S[i]=='W':\n        a[-1]+=1\n\nans=N\nfor i in range(N):\n    ans=min(ans,a[i]+N-(i+1)-(a[N]-a[i+1]))\nprint(ans)\n", "passed": true, "time": 0.2, "memory": 14272.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nwcnt = [0] * n\necnt = [0] * (n)\nenum = 0\nwnum = 0\nfor i in range(n):\n    if s[i] == \"W\":\n        wnum += 1\n    wcnt[i] += wnum\n    if s[-i - 1] == \"E\":\n        enum += 1\n    ecnt[-i - 1] += enum\nans = 10 ** 10\nfor i in range(n):\n    temp = 0\n    if i - 1 >= 0:\n        temp += wcnt[i - 1]\n    if i + 1 < n:\n        temp += ecnt[i + 1]\n    ans = min(ans, temp)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14092.0, "status": "done"}, {"code": "N=int(input())\nS=input()\nans=S.count(\"W\")\nans1=-10\nfor i in range(N):\n  if S[i]==\"W\":\n    ans-=1\n  if i!=0:\n    if S[i-1]==\"E\":\n      ans+=1\n  ans1=max(ans,ans1)\nprint(N-1-ans1)", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nl,r=[],[]\nans=min(s.count(\"W\"),s.count(\"E\"))\nk=s.count(\"E\")\nfor i in range(n):\n    if s[i]==\"W\":\n        k+=1\n    else:\n        k-=1\n    ans=min(ans,k)\nprint(ans)", "passed": true, "time": 0.22, "memory": 14144.0, "status": "done"}, {"code": "def main():\n    n = int(input())\n    ss = list(input())\n    num_sum = [0]*n\n    west_sum = 0\n    east_sum = 0\n    for i in range(1, n):\n        if ss[i-1] == 'W':\n            west_sum += 1\n        num_sum[i] += west_sum\n\n    for i in range(n-2, -1, -1):\n        if ss[i+1] == 'E':\n            east_sum += 1\n        num_sum[i] += east_sum\n\n    ans = min(num_sum)\n    print(ans)\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14268.0, "status": "done"}, {"code": "from itertools import accumulate\nn = int(input())\ns = list(input())\nl = [1 if s[i] == \"E\" else 0 for i in range(n)]\nl = list(accumulate(l))\nans = l[-1]-l[0]\nfor i in range(1, n):\n    ans = min(ans, i-l[i-1] + l[-1]-l[i])\nprint(ans)", "passed": true, "time": 0.22, "memory": 14216.0, "status": "done"}, {"code": "def schange(s):\n    if s==\"E\":\n        return 1\n    else:\n        return 0\n\nn = int(input())\ns = list(map(schange,input()))\nssum = [0]*(n+1)\n\nfor i in range(n):\n    ssum[i+1] = ssum[i] + s[i]\n\nans = float('inf')\nfor i in range(1,n+1):\n    turnE = (i-1)-ssum[i-1]\n    turnW = ssum[-1] - ssum[i]\n    ans=min(ans,turnE+turnW)\n    \nprint(ans)", "passed": true, "time": 0.14, "memory": 14120.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n \noE = S.count(\"E\")\nWo = 0\n\nL = []\nfor i in range(N):\n    if i == 0:\n        if S[i] == \"E\":\n            oE -= 1\n    else:\n        if S[i-1] == \"W\":\n            Wo += 1\n        if S[i] == \"E\":\n            oE -= 1\n    L.append(Wo + oE)\n    if Wo + oE == 0:\n        break\nprint(min(L))", "passed": true, "time": 0.15, "memory": 14152.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nli = []\nfor i in range(n):\n    if s[i]==\"W\":\n        li.append(-1)\n    else:\n        li.append(1)\n\ncumsum = [li[0]]\nfor i in range(n-1):\n    cumsum.append(cumsum[i] + li[i+1])\n\nl = cumsum.index(max(cumsum))\nw_to_e = 0\ne_to_w = 0\n\nfor i in range(n):\n    if i < l:\n        if li[i]==-1:\n            w_to_e += 1\n    elif i > l:\n        if li[i]==1:\n            e_to_w += 1\nprint(e_to_w + w_to_e)", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "from collections import deque\n\nN=int(input())\nS=input()\n\nleft=deque([0])\nright=[0]\nfor i in range(N):\n  if S[i]=='W':plus=1\n  else:plus=0\n  left.append(left[-1]+plus)\n  if S[-i-1]=='E':plus=1\n  else:plus=0\n  right.append(right[-1]+plus)\n  \nleft.popleft()\nright = right[::-1]\nright.pop()\n\nprint(min([left[i]+right[i] for i in range(N)])-1)", "passed": true, "time": 0.14, "memory": 14128.0, "status": "done"}, {"code": "N=int(input())\nS=list(str(input()))\neast=S[1:].count('E')\nans_min = east\nans = east\nfor l in range(1,N):\n  if S[l-1]=='W':\n    ans+=1\n  if S[l]=='E':\n    ans-=1\n  if ans<=0:\n    ans_min = 0\n    break\n  if ans < ans_min:\n    ans_min = ans\nprint(ans_min)\n", "passed": true, "time": 0.17, "memory": 14272.0, "status": "done"}, {"code": "N=int(input())\nS=list(input())\n\ndp_f=[0 for _ in range(N)]\ndp_b=[0 for _ in range(N)]\nfor n in range(1,N):\n    if S[n-1]==\"W\":\n        tmp=1\n    else:\n        tmp=0\n    dp_f[n]=dp_f[n-1]+tmp\n\nfor n in reversed(range(N-1)):\n    if S[n+1]==\"E\":\n        tmp=1\n    else:\n        tmp=0\n    dp_b[n]=dp_b[n+1]+tmp\n\nMIN=N\nfor n in range(N):\n    if n==N-1:\n        MIN=min(MIN,dp_f[N-1])\n    elif n==0:\n        MIN=min(MIN,dp_b[0])\n    else:\n        MIN=min(MIN,dp_f[n]+dp_b[n])\nprint(MIN)", "passed": true, "time": 0.2, "memory": 14364.0, "status": "done"}, {"code": "n = int(input())\ns = input()\ncnt_e = [0] * n\ncnt_w = [0] * n\nfor i in range(n):\n    if i == 0 :\n        if s[i] == 'E':\n            cnt_e[i] = 1\n        else :\n            cnt_w[i] = 1\n    else :\n        if s[i] == 'E':\n            cnt_e[i] = cnt_e[i-1] + 1\n            cnt_w[i] = cnt_w[i-1]\n        else :\n            cnt_e[i] = cnt_e[i-1]\n            cnt_w[i] = cnt_w[i-1] + 1\nans = 3 * 10**5 + 1\nfor i in range(n):\n    if s[i] == 'E':\n        e = cnt_e[-1] - cnt_e[i]\n        w = cnt_w[i]\n    else :\n        e = cnt_e[-1] - cnt_e[i]\n        w = cnt_w[i] - 1\n    ans = min(ans, e + w)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "N=int(input())\nS=input()\nS=\"N\"+S+\"N\"\nans=0\nE=0\nW=S.count(\"W\")\nfor i in range(1,N+1):\n    if S[i-1]==\"E\":\n        E+=1\n    if S[i]==\"W\":\n        W-=1\n    tmp=E+W\n    if tmp>ans:\n        ans=tmp\nans=N-1-ans\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14168.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nwest_back = s.count(\"W\")\neast_back = n-west_back\nwest_front = 0\neast_front = 0\n\nans = 10**6\nfor i in range(n):\n    if s[i] == \"W\":\n        west_front += 1\n        west_back -= 1\n        key = west_front+east_back-1\n    else:\n        east_front += 1\n        east_back -= 1\n        key = west_front+east_back\n    ans = min(ans, key)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14100.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nc = [0,0]\nfor i in range(n):\n    if (s[i]==\"E\"):\n        c[0] += 1\n    else:\n        c[1] += 1\nb = [0,0]\nans = c[0]\nfor i in range(n):\n    if (s[i]==\"E\"):\n        c[0] -= 1\n        b[0] += 1\n    else:\n        c[1] -= 1\n        b[1] += 1\n    ans = min(ans,c[0]+b[1])\nprint(ans)", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "N = int(input())\nN_List = str(input())\nC_Ans = N_List[1:].count(\"E\")\nAns = C_Ans\nfor i in range(1,N):\n    C_Ans = C_Ans + (0,1)[N_List[i-1] == \"W\"] - (0,1)[N_List[i] == \"E\"]\n    if C_Ans < Ans:\n        Ans = C_Ans\n\nprint(Ans)", "passed": true, "time": 0.14, "memory": 14256.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\n# full search\ncnt = s.count('E')\n\nans = cnt\nfor i in range(n):\n    if s[i] == 'E':\n        cnt -= 1\n        if ans > cnt:\n            ans = cnt\n    \n    else:\n        cnt += 1\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "n=int(input())\ns=input()\ndata=[0]*(n+1)\nfor i in range(n):\n  if s[i]=='E':\n    data[i+1]=data[i]+1\n  else:\n    data[i+1]=data[i]\nprint(min(i-data[i]+data[n]-data[i+1] for i in range(n)))", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "N = int(input())\nS = input()\na = S.count(\"E\")\nc = a \n \nfor s in S:\n  if s==\"E\":\n    c-=1\n  else:\n    c+=1\n  a=min(a,c)\n \nprint(a)", "passed": true, "time": 0.15, "memory": 14052.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nL = [0]*(N+1)\nfor i in range(N):\n  if S[i]==\"E\":\n    L[i+1] = L[i]+1\n  else:\n    L[i+1] = L[i]\nprint(min(i-L[i]+L[N]-L[i+1] for i in range(N)))", "passed": true, "time": 0.14, "memory": 14100.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\ndp = [0] * n\n\nfor i in range(1,n):\n  if s[i] == \"E\":\n    dp[0] += 1\n\nfor i in range(1,n):\n  dp[i] = dp[i-1]\n  if s[i-1] == \"W\":\n    dp[i] += 1\n  if s[i] == \"E\":\n    dp[i] -= 1\n\nprint(min(dp))", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "import sys\nimport re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd\nfrom itertools import accumulate, permutations, combinations, product\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left\nfrom heapq import heappush, heappop\nfrom functools import reduce\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return list(map(str, input().split()))\ndef LIST(): return list(map(int, input().split()))\nsys.setrecursionlimit(10 ** 9)\nINF = float('inf')\nmod = 10 ** 9 + 7\n\nN = INT()\nS = [_ for _ in input()]\n\nleft, right = 0, S[1:].count('E')\nans = left + right\nfor i in range(N-1):\n    if S[i] == 'W':\n        left += 1\n    if S[i+1] == 'E':\n        right -= 1\n\n    ans = min(ans, left + right)\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14112.0, "status": "done"}]