Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

import numpy as np
sumA = np.cumsum(A)

ans = float('inf')
for i in range(0, N-1):
    x = sumA[i]
    y = sumA[-1] - x
    ans = min(abs(x-y), ans)
print(ans)

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

import numpy as np
sumA = np.cumsum(A)

ans = float('inf')
for i in range(0, N-1):
    x = sumA[i]
    y = sumA[-1] - x
    ans = min(abs(x-y), ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

import numpy as np

A = sorted(A)
B = np.cumsum(A)

mem = N
for i in range(N-1):
    if 2*B[i] >= A[i+1]:
        mem = min(i, mem)
    else:
        mem = N
print(N-mem)

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

import numpy as np

A = sorted(A)
B = np.cumsum(A)

mem = N
for i in range(N-1):
    if 2*B[i] >= A[i+1]:
        mem = min(i, mem)
    else:
        mem = N
print(N-mem)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())

count1 = 0
count2 = 0
count3 = 0
for x in range(K+1):
    for y in range(x, K+1):
        for z in range(y, K+1):
            if x + y + z == S:
                count1 += 1
                if x == y or y == z or z == x:
                    count2 += 1
                    if x == y and y == z:
                        count3 += 1
                
print(count1*6 - count2*3 - count3*2)

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

count = 0
for x in range(K+1):
    for y in range(K+1):
        if 0 <= S - x - y <= K:
            count += 1
                
print(count)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a == b+c or b = c+a or c == a+b:
    print('Yes')
else:
    print('No')

Fixed submission:
a, b, c = map(int, input().split())

if a == b+c or b == c+a or c == a+b:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

h1, m1, h2, m2, k = map(int, rl().split())
m = h260 + m2 - h160 - m1
print(m-k)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

h1, m1, h2, m2, k = map(int, rl().split())
m = h2*60 + m2 - h1*60 - m1
print(m-k)

Buggy python submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

h1, m1, h2, m2, k = map(int, rl().split())
m = h260 + m2 - h160 - m1
print(m-k)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

h1, m1, h2, m2, k = map(int, rl().split())
m = h2*60 + m2 - h1*60 - m1
print(m-k)
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
  string s;cin >> s;
  vector<char> t(0);
  rep(i,s.size()) t.push_back(s.at(i));
  vector<char> u(0);
  rep(i,s.size()) u.push_back(s.at(i));
  int nD = 0;
  rep(i,t.size()) if(t.at(i) != 'P') nD++;
  rep(i,t.size()) {
    if(t.at(i) == '?') {
      if(i<(t.size()-1)) {
        if(t.at(i+i) == 'D') t.at(i) = 'P';
        else t.at(i) = 'D';
      }else t.at(i) = 'D';
    }
  }
  int nDPD = 0;
  string Ans = "";
  rep(i,t.size()) if(t.at(i) != 'P') nDPD++;
  rep(i,t.size()-1) if(t.at(i) == 'P') if(t.at(i+1) == 'D') nDPD++;
  if(nD > nDPD) {
    rep(i,u.size()) if(u.at(i) == '?') u.at(i) = 'D';
    rep(i,u.size()) Ans += u.at(i);
    cout << Ans << endl;
  }else{
    rep(i,t.size()) Ans += t.at(i);
    cout << Ans << endl;
  }
}

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

t = rl()
li = []
for i in range(len(t)):
    if t[i] == '?':
        li.append('D')
    else:
        li.append(t[i])
print(''.join(li))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
listA = list(map(int, input().split()))

i = k-1
bef = 0
hyouka = 1
while i < len(listA):
    if i == k-1:
        p = 0
        while p < k:
            hyouka*=listA[p]
            p+=1
    else:
        newHyouka = hyouka*listA[i]//listA[i-k]
        if newHyouka > hyouka:
            print("Yes")
        else:
            print("No")
        hyouka = newHyouka
    i+=1

Fixed submission:
n, k = map(int, input().split())
listA = list(map(int, input().split()))

i = k
while i < len(listA):
    if listA[i] > listA[i-k]:
        print("Yes")
    else:
        print("No")
    i+=1
Buggy python submission (verdict: Runtime Error):
answerL = []
for i in range(D):
    listS = list(map(int, input().split()))
    maxi = min(listS)
    target = listS.index(maxi)
    answerL.append(target+1)
for ans in answerL:
    print(ans)

Fixed submission:
D = int(input())
listC = list(map(int, input().split()))
answerL = []
for i in range(D):
    listS = list(map(int, input().split()))
    maxi = max(listS)
    target = listS.index(maxi)
    answerL.append(target+1)
for ans in answerL:
    print(ans)
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
listP = list(map(int, input().split()))

listP.sort()

minD = 200
val = 0
bef = None
for p in listP:
    if bef == None:
        bef = p
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                minD = 0
                val = x
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if abs(bef+1-x) < minD:
    val = bef+1
elif not x in listP:
    val = x
elif val == 0:
    if abs(0-x) > abs(101-x):
        val = 101
    else:
        val = 0

print(val)

Fixed submission:
x, n = map(int, input().split())
listP = list(map(int, input().split()))

listP.sort()

minD = 200
val = 0
bef = None
for p in listP:
    if bef == None:
        bef = p
        minD = abs(p-1-x)
        val = p-1
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                minD = 0
                val = x
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if not x in listP:
    val = x
    minD = 0
elif val == 0:
    if abs(0-x) > abs(101-x):
        val = 101
        minD = abs(101-x)
    else:
        val = 0
        minD = abs(0-x)
elif bef!=None and abs(bef+1-x) < minD:
    val = bef+1

print(val)
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
sL = [0]*m
bL = []
for i in range(n):
    book = list(map(int, input().split()))
    bL.append(book)


def fullS(currentL, index, allP):
    if index > len(currentL):
        if min(currentL) >= x:
            return allP
        else:
            return -1
    else:
        if min(currentL) >= x:
            return allP
        else:
            op1 = fullS(currentL, index+1, allP)
            newP = 0
            newL = []
            for i in range(len(bL[index])):
                if i == 0:
                    newP = allP+bL[index][i]
                else:
                    newL.append(currentL[i-1]+bL[index][i])
            op2 = fullS(newL, index+1, newP)
            if op1 == -1 and op2 == -1:
                return -1
            elif op1 == -1:
                return op2
            elif op2 == -1:
                return op1
            else:
                return min(op1, op2)
                


print(fullS(sL, 0, 0))

Fixed submission:
n, m, x = map(int, input().split())
sL = [0]*m
bL = []
for i in range(n):
    book = list(map(int, input().split()))
    bL.append(book)


def fullS(currentL, index, allP):
    if index >= len(bL):
        if min(currentL) >= x:
            return allP
        else:
            return -1
    else:
        if min(currentL) >= x:
            return allP
        else:
            op1 = fullS(currentL, index+1, allP)
            newP = 0
            newL = []
            for i in range(len(bL[index])):
                if i == 0:
                    newP = allP+bL[index][i]
                else:
                    newL.append(currentL[i-1]+bL[index][i])
            op2 = fullS(newL, index+1, newP)
            if op1 == -1 and op2 == -1:
                return -1
            elif op1 == -1:
                return op2
            elif op2 == -1:
                return op1
            else:
                return min(op1, op2)
                


print(fullS(sL, 0, 0))
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
cCan = b//c-(a-1)//c
dCan = b//d-(a-1)//d
cdSK = c*d//math.gcd(c, d)
cdCan = b//cdSK-(a-1)//cdSK
print(int(b-(a-1)-cCan-dCan+cdCan))

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())
cCan = b//c-(a-1)//c
dCan = b//d-(a-1)//d
cdSK = c*d//fractions.gcd(c, d)
cdCan = b//cdSK-(a-1)//cdSK
print(int(b-(a-1)-cCan-dCan+cdCan))
Buggy python submission (verdict: Runtime Error):
n = int(input())
listA = list(map(int, input().split()))

sum1=0
index=0
while index < len(listA):
    sum1+=listA[index]
    index+=1

if len(listA)%2==0:
    leng = len(listA)-1
else:
    leng = len(listA)-2
while leng > 1:
    index=0
    max1 = 0
    startI=0
    endI=0
    while index < len(listA)-leng+1:
        if sum(listA[index:index+leng+1]) <= 0 and max1 < sum(listA[index:index+leng+1])*-2:
            max1 = -2*(sum(listA[index:index+leng+1]))
            startI = index
            endI = index+leng
        index+=1
    if max1!=0:
        sum1+=max1
        index2=startI
        while index2 < endI+1:
            listA[index2]*=-1
            index2+=1
    leng-=1

print(sum1)

Fixed submission:
n = int(input())
listA = list(map(int, input().split()))

index=0
count=0
plSum=0
miSum=0
miniO=10000000
while index < len(listA):
    if listA[index] < 0:
        count+=1
        miSum-=listA[index]
    else:
        plSum+=listA[index]
    if abs(listA[index]) < miniO:
        miniO = abs(listA[index])
    index+=1
if count%2==0:
    print(plSum+miSum)
else:
    print(plSum+miSum-2*miniO)
Buggy python submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))
listC = list(map(int, input().split()))

sumAB =[]
index=0
while index < len(listA):
    index2=0
    while index2 < len(listB):
        sumAB.append(listA[index]+listB[index2])
        index2+=1
    index+=1
sumAB.sort()
sumAB.reverse()
abSL=[]
index3=0
while index3 < min(k, len(sumAB)):
    abSL.append(sumAB[index3])
    index3+=1

answerL=[]
index4=0
while index4 < len(abSL):
    index5=0
    while index5 < min(k,len(listC)):
        answerL.append(abSL[index4]+listC[index5])
        index5+=1
    index4+=1

answerL.sort()
answerL.reverse()
index6=0
while index6 < k:
    print(answerL[index6])
    index6+=1

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e-a > k or d-a >k or c-a>k or b-a>k or e-b > k or d-b > k or c-b>k or e-c >k or d-c >k or e-d>k:
    print(":(")
else:
    print("Yay!")
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
listI=[]
index2=0
while index2 < len(listS)-1:
    if listS[index2]=="A" and listS[index2+1]=="C":
        listI.append(index2)
    index2+=1

while index < q:
    l, r = map(int, input().split())
    count=0
    index3=0
    while index3 < len(listI):
        if listI[index3] >= l-1 and listI[index3]+1 <= r-1:
            count+=1
        index3+=1
    listA.append(count)
    index+=1
for ans in listA:
    print(ans)

Fixed submission:
n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
listM=[0]*n
index2=1
countM=0
while index2 < len(listS):
    if listS[index2-1]=="A" and listS[index2]=="C":
        countM+=1
    listM[index2] = countM               
    index2+=1

while index < q:
    l, r = map(int, input().split())
    listA.append(listM[r-1]-listM[l-1])
    index+=1
for ans in listA:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
while index < q:
    l, r = map(int, input().split())
    listQ = listS[l-1: r]
    index2=0
    count=0
    while index2 < len(listQ)-1:
        if listQ[index2]=="A" and listQ[index2+1]=="C":
            count+=1
        index2+=1
    listA.append(count)
    index+=1
for ans in listA:
    print(ans)

Fixed submission:
n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
listM=[0]*n
index2=1
countM=0
while index2 < len(listS):
    if listS[index2-1]=="A" and listS[index2]=="C":
        countM+=1
    listM[index2] = countM               
    index2+=1

while index < q:
    l, r = map(int, input().split())
    listA.append(listM[r-1]-listM[l-1])
    index+=1
for ans in listA:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
listB = list(map(int, input().split()))
i = 1
if i == 1:
    listA = []
    index2 = len(listB)-1
    befI = len(listB)
    while index2 > -1:
        if listB[index2]!=1:
            pass
        else:
            if index2 != befI:
                newL = listB[index2:befI]
                newL.sort()
                listA.extend(newL)
                befI = index2
            else:
                listA.append(1)
        index2-=1
    listC = []
    index3=0
    while index3 < len(listA):
        if index3 == 0:
            if listA[index3] == 1:
                listC.append(listA[index3])
            else:
                listC.append(0)
        elif listA[index3] > index3+1:
            listC.append(0)
        else:
            if listA[index3]-1 <=  len(listC):
                listC.insert(listA[index3]-1, listA[index3])
            else:
                listC.append(0)
        index3+=1
    if index3 == len(listA):
        if listC == listB:
            for ans in listA:
                print(ans)
        else:
            print(a)

Fixed submission:
n = int(input())
listB = list(map(int, input().split()))
listA = []

flag=1
while flag:
    index=len(listB)-1
    while index > -1:
        if listB[index] == index+1:
            listA.append(listB[index])
            del listB[index]
            break
        index-=1
    if index == -1:
        print(-1)
        flag=0
        break
    if listB == []:
        break
listA.reverse()
if flag:
    for ans in listA:
        print(ans)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n = int(input())
listA=list(map(int, input().split()))
print(gcd_list(listA))
            

Fixed submission:
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = int(input())
listA=list(map(int, input().split()))
print(gcd_list(listA))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
listTakahashi = []
listPoint = []
i=0
while i < n:
    a, b = map(int, input().split())
    listTakahashi.append([a+b, i])
    listPoint.append([a, b])
    i+=1
listTakahashi.sort()
listTakahashi.reverse()
index2=0
takaP=0
aokiP=0
while index2 < n:
    if index2%2==0:#takahashi's turn
        index = listTakahashi[0][1]
        takaP+=listPoint[index][0]
        del listTakahashi[0]
    else:
        index = listTakahashi[0][1]
        aokiP+=listPoint[index][1]
        del listTakahashi[0]
    index2+=1

print(takaP-aokiP)
    

Fixed submission:
n = int(input())
listP = []
i=0
while i < n:
    a, b = map(int, input().split())
    listP.append([a+b, a, b])
    i+=1
listP.sort()
listP.reverse()

takaP=0
aokiP=0
index=0
while index < len(listP):
    if index%2==0:
        takaP+=listP[index][1]
    else:
        aokiP+=listP[index][2]
    index+=1
print(takaP-aokiP)
Buggy python submission (verdict: Runtime Error):
n = int(input())
numberL = list(map(int, input().split()))
 
kisuuSyuL=[]
kisuuKosuL=[]
kisuuKosuL2=[]
gusuSyuL=[]
gusuKosuL=[]
gusuKosuL2=[]
 
index=0
while index<n:
    if index==0:
        gusuSyuL.append(numberL[index])
        gusuKosuL.append(1)
        gusuKosuL2.append(1)
    elif index==1:
        kisuuSyuL.append(numberL[index])
        kisuuKosuL.append(1)
        kisuuKosuL2.append(1)
    else:
        if index%2==0:
            if numberL[index] in gusuSyuL:
                tarI = gusuSyuL.index(numberL[index])
                gusuKosuL[tarI]+=1
                gusuKosuL2[tarI]+=1
            else:
                gusuSyuL.append(numberL[index])
                gusuKosuL.append(1)
                gusuKosuL2.append(1)
        else:
            if numberL[index] in kisuuSyuL:
                tarI = kisuuSyuL.index(numberL[index])
                kisuuKosuL[tarI]+=1
                kisuuKosuL2[tarI]+=1
            else:
                kisuuSyuL.append(numberL[index])
                kisuuKosuL.append(1)
                kisuuKosuL2.append(1)
    index+=1

 
if len(kisuuSyuL)==1 and len(gusuSyuL)==1:
    if kisuuSyuL[0]==gusuSyuL[0]:
        print(int(n/2))
    else:
        print(0)
else:
    kiIndex = kisuuKosuL.index(max(kisuuKosuL))
    guIndex = gusuKosuL.index(max(gusuKosuL))
    if kisuuSyuL[kiIndex]!=gusuSyuL[guIndex]:
        noC=max(kisuuKosuL)+max(gusuKosuL)
        print(n-noC)
    else:
        if max(kisuuKosuL) < max(gusuKosuL):
            kisuuKosuL.sort()
            noC=kisuuKosuL[len(kisuuKosuL)-1]+max(gusuKosuL)
            print(n-noC)
        else:
            gusuKosuL.sort()
            noC=gusuKosuL[len(gusuKosuL)-1]+max(kisuuKosuL)
            print(n-noC)

Fixed submission:
listN = list(str(input()))

index=0
while index < 3:
    if listN[index] == "1":
        listN[index]="9"
    elif listN[index]=="9":
        listN[index]="1"
    index+=1

print(listN[0]+listN[1]+listN[2])
Buggy python submission (verdict: Runtime Error):
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=1
            for number in list3:
                if number%index2 ==0:
                    flag =1
            if flag ==1:
                ans = index2
                break
            index2-=1
            
        print(ans)

Fixed submission:
list = list(map(int, input().split()))
a = list[0]
b = list[1]

if a%2!=0 and b%2!=0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =1
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2<mimN+1:
            flag=0
            for number in list3:
                if number%index2 !=0:
                    flag =1
            if flag ==0:
                ans = index2
            index2+=1
            
        print(ans)

Fixed submission:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
list4 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=0
            for number in list3:
                if number%index2 ==0:
                    flag =1
                else:
                    flag =0
                    break
            if flag ==1:
                ans = index2
                break
            else:
                index2-=1       
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =1
if len(list3) ==1:
    print(mimN)
else:
    while index2<mimN+1:
        flag=0
        for number in list3:
            if number%index2 !=0:
                flag =1
        if flag ==0:
            ans = index2
        index2+=1
        
    print(ans)

Fixed submission:
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
list4 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=0
            for number in list3:
                if number%index2 ==0:
                    flag =1
                else:
                    flag =0
                    break
            if flag ==1:
                ans = index2
                break
            else:
                index2-=1       
        print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
listS = list(input())

listSeeWSum=[]
index=0
wSum=0
while index < n:
    if index==0:
        listSeeWSum.append(0)
    else:
        if listS[index-1] == "W":
            wSum+=1
        listSeeWSum.append(wSum)
    index+=1

listSeeESum=[]
listS.reverse()
index = 0
eSum = 0
while index < n:
    if index == 0:
        listSeeESum.append(0)
    else:
        if listS[index-1] == "E":
            eSum += 1
        listSeeESum.append(eSum)
    index += 1
listSeeESum.reverse()

listSum=[]
index=0
while index < n:
    listSum.append(listSeeESum[index]+listSeeWSum[index])
    index+=1

print(min(listSum))v

Fixed submission:
n = int(input())
listS = list(input())

listSeeWSum=[]
index=0
wSum=0
while index < n:
    if index==0:
        listSeeWSum.append(0)
    else:
        if listS[index-1] == "W":
            wSum+=1
        listSeeWSum.append(wSum)
    index+=1

listSeeESum=[]
listS.reverse()
index = 0
eSum = 0
while index < n:
    if index == 0:
        listSeeESum.append(0)
    else:
        if listS[index-1] == "E":
            eSum += 1
        listSeeESum.append(eSum)
    index += 1
listSeeESum.reverse()

listSum=[]
index=0
while index < n:
    listSum.append(listSeeESum[index]+listSeeWSum[index])
    index+=1

print(min(listSum))