#import <stdio.h>
#import <limits.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
int main() {
    long N;
    scanf("%ld",&N);
    char S[300002] = {'\0'};
    scanf("%s",S);
    long L[300002] = {0L};
    long R[300002] = {0L};
    for(long i=1;i<N;i++){
       L[i] = L[i-1] + ((S[i-1] == 'W') ? 1 : 0);
       R[N-1-i] = R[N-i] + ((S[N-i] == 'E') ? 1 : 0);
    }
    long min = LONG_MAX;
    for(long i=0;i<N;i++){
       min = MIN(min,L[i]+R[i]);
    }
    printf("%ld",min);
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_534/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_534/source.m"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@.str = private unnamed_addr constant [4 x i8] c"%ld\00", align 1
@.str.1 = private unnamed_addr constant [3 x i8] c"%s\00", align 1

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
entry:
  %N = alloca i64, align 8
  %S = alloca [300002 x i8], align 16
  %L = alloca [300002 x i64], align 16
  %R = alloca [300002 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %N) #5
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %N)
  call void @llvm.lifetime.start.p0(i64 300002, ptr nonnull %S) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(300002) %S, i8 0, i64 300002, i1 false)
  %call1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %S)
  call void @llvm.lifetime.start.p0(i64 2400016, ptr nonnull %L) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2400016) %L, i8 0, i64 2400016, i1 false)
  call void @llvm.lifetime.start.p0(i64 2400016, ptr nonnull %R) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2400016) %R, i8 0, i64 2400016, i1 false)
  %0 = load i64, ptr %N, align 8, !tbaa !5
  %cmp54 = icmp sgt i64 %0, 1
  br i1 %cmp54, label %for.body.preheader, label %for.cond22.preheader

for.body.preheader:                               ; preds = %entry
  %1 = shl i64 %0, 3
  %2 = getelementptr i8, ptr %R, i64 %1
  %scevgep = getelementptr i8, ptr %2, i64 -8
  %load_initial = load i64, ptr %scevgep, align 8
  br label %for.body

for.cond22.preheader:                             ; preds = %for.body, %entry
  %cmp2356 = icmp sgt i64 %0, 0
  br i1 %cmp2356, label %for.body26.preheader, label %for.cond.cleanup25

for.body26.preheader:                             ; preds = %for.cond22.preheader
  %min.iters.check = icmp ult i64 %0, 4
  br i1 %min.iters.check, label %for.body26.preheader65, label %vector.ph

vector.ph:                                        ; preds = %for.body26.preheader
  %n.vec = and i64 %0, -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ <i64 9223372036854775807, i64 9223372036854775807>, %vector.ph ], [ %9, %vector.body ]
  %vec.phi61 = phi <2 x i64> [ <i64 9223372036854775807, i64 9223372036854775807>, %vector.ph ], [ %10, %vector.body ]
  %3 = getelementptr inbounds [300002 x i64], ptr %L, i64 0, i64 %index
  %wide.load = load <2 x i64>, ptr %3, align 16, !tbaa !5
  %4 = getelementptr inbounds i64, ptr %3, i64 2
  %wide.load62 = load <2 x i64>, ptr %4, align 16, !tbaa !5
  %5 = getelementptr inbounds [300002 x i64], ptr %R, i64 0, i64 %index
  %wide.load63 = load <2 x i64>, ptr %5, align 16, !tbaa !5
  %6 = getelementptr inbounds i64, ptr %5, i64 2
  %wide.load64 = load <2 x i64>, ptr %6, align 16, !tbaa !5
  %7 = add nsw <2 x i64> %wide.load63, %wide.load
  %8 = add nsw <2 x i64> %wide.load64, %wide.load62
  %9 = call <2 x i64> @llvm.smin.v2i64(<2 x i64> %vec.phi, <2 x i64> %7)
  %10 = call <2 x i64> @llvm.smin.v2i64(<2 x i64> %vec.phi61, <2 x i64> %8)
  %index.next = add nuw i64 %index, 4
  %11 = icmp eq i64 %index.next, %n.vec
  br i1 %11, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %rdx.minmax = call <2 x i64> @llvm.smin.v2i64(<2 x i64> %9, <2 x i64> %10)
  %12 = call i64 @llvm.vector.reduce.smin.v2i64(<2 x i64> %rdx.minmax)
  %cmp.n = icmp eq i64 %0, %n.vec
  br i1 %cmp.n, label %for.cond.cleanup25, label %for.body26.preheader65

for.body26.preheader65:                           ; preds = %for.body26.preheader, %middle.block
  %i21.058.ph = phi i64 [ 0, %for.body26.preheader ], [ %n.vec, %middle.block ]
  %min.057.ph = phi i64 [ 9223372036854775807, %for.body26.preheader ], [ %12, %middle.block ]
  br label %for.body26

for.body:                                         ; preds = %for.body.preheader, %for.body
  %store_forwarded = phi i64 [ %load_initial, %for.body.preheader ], [ %add17, %for.body ]
  %13 = phi i64 [ 0, %for.body.preheader ], [ %add, %for.body ]
  %i.055 = phi i64 [ 1, %for.body.preheader ], [ %inc, %for.body ]
  %sub = add nsw i64 %i.055, -1
  %arrayidx3 = getelementptr inbounds [300002 x i8], ptr %S, i64 0, i64 %sub
  %14 = load i8, ptr %arrayidx3, align 1, !tbaa !12
  %cmp4 = icmp eq i8 %14, 87
  %conv6 = zext i1 %cmp4 to i64
  %add = add nuw nsw i64 %13, %conv6
  %arrayidx7 = getelementptr inbounds [300002 x i64], ptr %L, i64 0, i64 %i.055
  store i64 %add, ptr %arrayidx7, align 8, !tbaa !5
  %sub8 = sub nsw i64 %0, %i.055
  %arrayidx11 = getelementptr inbounds [300002 x i8], ptr %S, i64 0, i64 %sub8
  %15 = load i8, ptr %arrayidx11, align 1, !tbaa !12
  %cmp13 = icmp eq i8 %15, 69
  %conv16 = zext i1 %cmp13 to i64
  %add17 = add nsw i64 %store_forwarded, %conv16
  %16 = xor i64 %i.055, -1
  %sub19 = add i64 %0, %16
  %arrayidx20 = getelementptr inbounds [300002 x i64], ptr %R, i64 0, i64 %sub19
  store i64 %add17, ptr %arrayidx20, align 8, !tbaa !5
  %inc = add nuw nsw i64 %i.055, 1
  %exitcond.not = icmp eq i64 %inc, %0
  br i1 %exitcond.not, label %for.cond22.preheader, label %for.body

for.cond.cleanup25:                               ; preds = %for.body26, %middle.block, %for.cond22.preheader
  %min.0.lcssa = phi i64 [ 9223372036854775807, %for.cond22.preheader ], [ %12, %middle.block ], [ %min.0.add29, %for.body26 ]
  %call39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %min.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 2400016, ptr nonnull %R) #5
  call void @llvm.lifetime.end.p0(i64 2400016, ptr nonnull %L) #5
  call void @llvm.lifetime.end.p0(i64 300002, ptr nonnull %S) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %N) #5
  ret i32 0

for.body26:                                       ; preds = %for.body26.preheader65, %for.body26
  %i21.058 = phi i64 [ %inc37, %for.body26 ], [ %i21.058.ph, %for.body26.preheader65 ]
  %min.057 = phi i64 [ %min.0.add29, %for.body26 ], [ %min.057.ph, %for.body26.preheader65 ]
  %arrayidx27 = getelementptr inbounds [300002 x i64], ptr %L, i64 0, i64 %i21.058
  %17 = load i64, ptr %arrayidx27, align 8, !tbaa !5
  %arrayidx28 = getelementptr inbounds [300002 x i64], ptr %R, i64 0, i64 %i21.058
  %18 = load i64, ptr %arrayidx28, align 8, !tbaa !5
  %add29 = add nsw i64 %18, %17
  %min.0.add29 = call i64 @llvm.smin.i64(i64 %min.057, i64 %add29)
  %inc37 = add nuw nsw i64 %i21.058, 1
  %exitcond60.not = icmp eq i64 %inc37, %0
  br i1 %exitcond60.not, label %for.cond.cleanup25, label %for.body26, !llvm.loop !13
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i64> @llvm.smin.v2i64(<2 x i64>, <2 x i64>) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.smin.v2i64(<2 x i64>) #4

attributes #0 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !11, !10}
