jiahuimbzuai/CoQuIR huggingface dataset:
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func chk(x int) int {
	if x == 2 {
		return 3
	}
	if x == 4 || x == 6 || x == 9 || x == 11 {
		return 2
	}
	return 1
}

func main() {
	sc.Split(bufio.ScanWords)
	x, y := getInt(), getInt()
	if chk(x) == chk(y) {
		out("Yes")
		return
	}
	out("No")
}
//  [go]
package main

import (
	"fmt"
)

func isA(a int) bool {
	switch a {
	case 1, 3, 5, 7, 8, 10, 12:
		fmt.Println(a)
		return true
	}
	return false
}

func isB(a int) bool {
	switch a {
	case 4, 6, 9, 11:
		return true
	}
	return false
}

func isC(a int) bool {
	if a == 2 {
		return true
	}
	return false
}

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	if (isA(x) && isA(y)) ||
		(isB(x) && isB(y)) ||
		(isC(x) && isC(y)) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}
//  [go]
package main

import (
	"fmt"
)

func main() {
	s := []int{0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1}
	var x, y int
	fmt.Scan(&x, &y)
	if s[x-1] == s[y-1] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [go]
func main() {
	group := make([]int, 12+1)
	for _, b := range []int{4, 6, 9, 11} {
		group[b] = 1
	}
	for _, c := range []int{2} {
		group[c] = 2
	}
	
	var x, y int
	fmt.Scanf("%d %d", &x, &y)
	if group[x] == group[y] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [ruby]
def id(x)
  case x
  when 1,3,5,7,8,10,12 then 1
  when 4,6,9,11 then 2
  else 3
  end
end

x,y = gets.split.map(&:to_i)
puts id(x) == id(y) ? "Yes" : "No"
//  [ruby]
puts gets.include?("2") ? "No" : "Yes"
//  [ruby]
x, y = gets.split.map(&:to_i)
arr = [-1, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]
puts arr[x]==arr[y] ? "Yes" : "No"
//  [ruby]
a=gets.split.map do |i|
  i = i.to_i
  i==2 ? 2 : [1,3,5,7,8,10,12].include?(i) ? 1 : 0
end
puts a.uniq.size==2 ? "Yes" : "No"
//  [ruby]
# すぬけ君は、1 から 12 までの整数を下図のようにグループ分けしました。 
# 整数 x, y (1≤x<y≤12) が与えられるので、x, y が同一のグループに属しているか判定してください。

input = gets.chomp.split
x = input[0].to_i
y = input[1].to_i

groups = [
    [1, 3, 5, 7, 8, 10, 12],
    [4, 6, 9, 11],
    [2]
]

3.times do |i|
    if x.include?(groups[i]) && y.include?(groups[i])
        puts "Yes"
        break
    end
    if i == 2
        puts "No"
    end
end
//  [ruby]
x, y = gets.split.map(&:to_i)
array = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]
puts array[x] == array[y] ? "Yes" : "no"
//  [rust]
use std::io;
use std::collections::HashSet;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let x = v[0];
	let y = v[1];
	let mut set1:HashSet<i32> = HashSet::new();
	set1.insert(1);
	set1.insert(3);
	set1.insert(5); 
	set1.insert(7);
	set1.insert(8);
	set1.insert(10);
	set1.insert(12);
	let mut set2:HashSet<i32> = HashSet::new();
	set2.insert(4);
	set2.insert(6);
	set2.insert(9);
	set2.insert(11);
	let mut set3:HashSet<i32> = HashSet::new();
	set3.insert(2);
	let mut flag = false;
	if !set1.insert(x) && !set1.insert(y) {
		flag = true;
	}
	if !set2.insert(x) && !set2.insert(y) {
		flag = true;
	}
	if !set3.insert(x) && !set3.insert(y) {
		flag = true;
	}
	if flag {
		println!("Yes");
	}else{
		println!("No");
	}
}
//  [rust]
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct UnionFind {
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        // initialize
        let mut v: Vec<usize> = vec![];
        for i in 0..n + 1 {
            v.push(i)
        }
        let mut s: Vec<usize> = vec![1; n + 1];

        UnionFind { parent: v, size: s }
    }

    fn root(&self, x: usize) -> usize {
        if self.parent[x] == x {
            return x;
        } else {
            return self.root(self.parent[x]);
        }
    }

    fn size(&self, a: usize) -> usize {
        let ra = self.root(a);
        self.size[ra]
    }

    fn unite(&mut self, a: usize, b: usize) {
        let mut ra = self.root(a);
        let mut rb = self.root(b);
        if ra == rb {
            return;
        }
        if self.size[ra] < self.size[rb] {
            std::mem::swap(&mut ra, &mut rb)
        };
        self.size[ra] += self.size[rb];
        self.parent[rb] = ra;
    }

    fn same(&self, a: usize, b: usize) -> bool {
        let ra = self.root(a);
        let rb = self.root(b);
        self.parent[a] == self.parent[b]
    }
}

fn main() {
    let mut uf = UnionFind::new(12);
    uf.unite(1, 3);
    uf.unite(1, 5);
    uf.unite(1, 7);
    uf.unite(1, 8);
    uf.unite(1, 10);
    uf.unite(1, 12);

    uf.unite(4, 6);
    uf.unite(4, 9);
    uf.unite(4, 11);
    let x: usize = read();
    let y: usize = read();
    if uf.same(x, y) {
        println!("Yes");
    } else {
        println!("No");
    }
}
//  [rust]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let ms = [0,1,3,1,2,1,2,1,1,2,1,2,1];
    let (x, y) = get!(usize, usize);
    println!("{}", if ms[x] == ms[y] { "Yes" } else { "No" });
}
//  [rust]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (x, y): (i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let g: std::collections::HashSet<i64> = vec![4, 6, 9, 11].into_iter().collect::<_>();
    let ans = if x == y || g.contains(&x) && g.contains(&y) || x != 2 && !g.contains(&x) && !g.contains(&y) {
        "Yes"
    } else {
        "No"
    };

    println!("{}", ans);
}
//  [rust]
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"a b c"# => r#"ABC"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        x: isize,
        y: isize,
    }

    let f:[isize; 7] = [1, 3, 5, 7, 8, 10, 12];
    let s:[isize; 4] = [4, 6, 9, 11];

    if x == y && x == 2 {
        "Yes"
    } else if f.into_iter().filter(|&i| &x == i).count() == s.into_iter().filter(|&i| &y == i).count() {
        "Yes"
    } else {
        "No"
    }.to_string()
}
//  [swift]
let a=[1,3,1,2,1,2,1,1,2,1,2,1],i=readLine()!.characters.split(" ").map{Int(String($0))!-1};print(a[i[0]]==a[i[1]] ?"Yes":"No")
//  [swift]
let a=[1,3,1,2,1,2,1,1,2,1,2,1],i=readLine()!.characters.split(" ").map{Int(String($0))!--};print(a[i[0]]==a[i[1]] ?"Yes":"No")
//  [swift]
let a=[1,3,1,2,1,2,1,1,2,1,2,1];i=readLine()!.characters.split(" ").map{Int(String($0))!--};print(a[i[0]]==a[i[1]] ?"Yes":"No")
//  [typescript]
import * as fs from 'fs';

const [x, y]: number[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split(' ').map(Number);

const group1 : number[] =[1,3,5,7,8,10,12];
const group2 : number[] =[4,6,9,11];

if (x===2 || y===2) {
    console.log('No');
} else {

    if (group1.find(g=>g===x)&&group1.find(g=>g===y)) {
        console.log('Yes');
    } else if (group2.find(g=>g===x)&&group2.find(g=>g===y)) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b]=nrin(2)
  out(a==b||
    (a==4||a==6||a==9||a==11)&&(b==4||b==6||b==9||b==11)||
    (a==1||a==3||a==5||a==7||a==8||a==10||a==12)&&(b==1||b==3||b==5||b==7||b==8||b==10||b==12)?'Yes':'No')
}
main()
//  [typescript]
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [x, y] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const grp = [4, 6, 9, 11]

const res = _ => {
  if (x === 2 || y === 2) {
    return 'No'
  } else if (grp.indexOf(x) > -1) {
    if (grp.indexOf(y) > -1) {
      return 'Yes'
    } else {
      return 'No'
    }
  } else if (grp.indexOf(y) > -1) {
    return 'No'
  } else {
    return 'Yes'
  }
}

console.log(res())
//  [typescript]
import * as fs from 'fs';

const input = fs.readFileSync("/dev/stdin", "utf8").split(" ");
const x = +input[0];
const y = +input[1];

const B = [4,6,9,11];

const check = (param: number) : 'A'| 'B' | 'C' => {
 if (param == 2) {
     return 'C';
 } else if (param in B) {
     return 'B';
 } else
   return 'A'
}

console.log(check(x) == check(y) ? 'Yes' : 'No');
//  [python]
def main():
    N, S = open(0).read().split()
    pre = S.count("E")
    cur = pre
    for Si in S:
        if pre < cur:
            cur = pre
        if Si == "E":
            pre -= 1
        else:
            pre += 1
    print(pre if pre < cur else cur)
    return


main()
//  [python]
def main():
    N, S = open(0).read().split()
    pre = S.count("E")
    ans = pre
    for Si in S:
        if pre < ans:
            ans = pre
        if Si == "E":
            pre -= 1
        else:
            pre += 1
    print(pre if pre < ans else ans)
    return


main()
//  [python]
def main():
    N, S = open(0).read().split()
    pre = S.count("E")
    cur = pre
    for Si in S:
        if cur < pre:
            pre = cur
        if Si == "E":
            cur -= 1
        else:
            cur += 1
    print(pre if pre < cur else cur)
    return


main()
//  [python]
n=int(input())
S=list(input())
W=[0]*(n+1)
E=[0]*(n+1)
for i in range(n):
  W[i]=W[i-1]+S[i].count("W")
  E[n-i-1]=E[n-i]+S[n-i-1].count("E")
W = W[:n]
E = E[:n]
ans = 10000
for i in range(n):
  ans = min(ans,W[i]+E[i]-1)
print(ans)
//  [python]
n=int(input())
s=input()
l = [0]*n
for i in range(n):
  if s[i] == "E":
    for j in range(i+1,n):
      l[j] += 1
  else:
    for j in range(0,i):
      l[j] += 1
c = max(l)
index = l[c]
ans = s[0:index].count("W") + s[index+1:n].count("E")
print(ans)
//  [python]
def turn(curr, A, B):
  count = 0
  count += A.count('W')
  count += B.count('E')
  
  return count

N = int(input())
S = list(input())
res = []
for i in range(0, N):
  A = S[:i]
  B = S[i + 1:]
  curr = S[i]
  res.append(turn(curr, A, B))

print(min(res))
//  [java]
import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		char[] str = sc.next().toCharArray();
		int cnt = 0;
	    for(int i = 1; i < n; i++) {
	    	if (str[i] == 'E') cnt++;
	    }
	    int min = cnt;
	    for(int i = 1; i < n; i++) {
	    	if(str[i - 1] == 'W')
	    		cnt++;
	    	if(str[i] == 'E')
	    		cnt--;
	    	if(cnt < 0)
	    		cnt = 0;
	    	if (min > cnt) min = cnt;
	    }
	    out.println(min);
		
		out.close();
	}
	  private static long gcd(long m, long n) {
		    if(m < n) return gcd(n, m);
		    if(n == 0) return m;
		    return gcd(n, m % n);
		}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}
//  [java]
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        char[] c = s.toCharArray();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                } else if (i < j) {
                    if (c[j] == 'E') {
                        sum++;
                    }
                } else {
                    if (c[j] == 'W') {
                        sum++;
                    }
                }
            }
            min = Math.min(min, sum);
        }
        System.out.println(min);
    }
}
//  [java]
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Attention solver = new Attention();
        solver.solve(1, in, out);
        out.close();
    }

    static class Attention {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();

            int cost = Integer.MAX_VALUE;
            int wc = 0;
            int ec = 0;

            for (int i = 0; i < n; i++) {
                int wcount = n - i;
                int ecount = i;

                ecount -= ec;

                if (s[i] == 'W') {
                    wc++;
                } else if (s[i] == 'E') {
                    ec++;
                }

                for (int j = i + 1; j < n; j++) {
                    if (s[j] == 'W') {
                        wcount--;
                    } else if (s[j] == 'E') {
                    }
                }
                cost = Math.min(cost, wcount + ecount - 1);
            }
            out.println(cost);
        }

    }
}
//  [java]
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Attention solver = new Attention();
        solver.solve(1, in, out);
        out.close();
    }

    static class Attention {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();

            int cost = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                int wcount = n - i;
                int ecount = i;
                for (int j = 0; j < n; j++) {
                    if (i == j) {
                        continue;
                    }
                    if (j < i) {
                        if (s[j] == 'W') {

                        } else if (s[j] == 'E') {
                            ecount--;
                        }
                    } else {
                        if (s[j] == 'W') {
                            wcount--;
                        } else if (s[j] == 'E') {

                        }
                    }
                }
                cost = Math.min(cost, wcount + ecount - 1);
            }
            out.println(cost);
        }

    }
}
//  [cpp]
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#define max(a,b) ((a > b) ? a : b)
#define min(a,b) ((a < b) ? a : b)
#define abs(a) ((a < 0) ? -a : a)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

int main() {
	int n = ri();
	char s[n+1];
	for (int i = 0; i <= n; i++) s[i] = '\0';
	scanf("%s", s);
	
	int first = 0;
	for (int i = 1; i < n; i++) {
		if (s[i] == 'E') first++;
	}
	
	int res = first;
	int cur = first;
	for (int i = 1; i < n; i++) {
		if (s[i-1] == 'W') cur++; // <-
		if (s[i] == 'E') cur--;   // ->
		res = min(res, cur);
	}
	
	printf("%d", res);
	
	return 0;
}
//  [cpp]
#include <cstdio>
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MIN(x, y) x < y ? x : y
using namespace std;

int n, t, ans=1<<30;
char s[300005];

int main() {
  scanf("%d", &n), scanf("%s", s);
	FOR(i,1,n) t += (s[i]=='E');
	REP(i,n) {
		ans = MIN(ans, t);
		t += (s[i]=='W') - (s[i+1]=='E');
	}
	printf("%d\n", ans);
	return 0;
}
//  [cpp]
#include <cstdio>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define MIN(x, y) x < y ? x : y
using namespace std;
const int MAXN = 300005;

int n, e[MAXN], ans=1<<30;
char s[MAXN];

int main() {
    scanf("%d", &n), scanf("%s", s);
    REP(i,n) e[i+1] = e[i] + (s[i] == 'E');
    REP(i,n) ans = MIN(ans, i - e[i] + e[n] - e[i+1]);
    printf("%d", ans);
    return 0;
}
//  [cpp]
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<int> cntl(N + 1);
    for(int i = 0; i < N; i++){
        if(S[i] == 'E') cntl[i + 1] = cntl[i] + 1;
        else cntl[i + 1] = cntl[i];
    }
    int ans = 1e9;
    for(int i = 0; i < N; i++){
        int t = max(0, i - 1) - cntl[i] + (N - i - 1 - (cntl[N] - cntl[i + 1]));
        ans = min(ans, t);
    }
    cout << ans << endl;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;

int main( void )
{
  int N;
  string S;
  int countW, countE;
  int min = INT_MAX;
  cin >> N >> S;

  for( int i = 0; i < N; i++ ) {
    countE = 0;
    countW = 0;
    
    for( int j = 0; j < i; j++ ) {
      if( S.at( j ) != 'E' )
	countE++;
    }
    for( int j = i + 1; j < N; j++ ) {
      if( S.at( j ) != 'W' )
	countW++;
    }
    if( min > countE + countW )
      min = countE + countW;
  }
  cout << min << endl;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;

int main(){
  int N;
  string str;
  cin>>N>>str;
  vector<int> dataW(N);
  vector<int> dataE(N);
  if(str.at(0)=='W'){dataW.at(0)=1;}else{dataW.at(0)=0;}
  if(str.at(N-1)=='E'){dataE.at(0)=1;}else{dataE.at(0)=0;}
  for(int i=1;i<N;i++){
    if(dataW.at(i)=='W'){
      dataW.at(i)=dataW.at(i-1)+1;
    }else{
      dataW.at(i)=dataW.at(i-1);
    }
    if(dataE.at(N-1-i)=='E'){
      dataE.at(i)=dataE.at(i-1)+1;
    }else{
      dataE.at(i)=dataE.at(i-1);
    }
  }
  
  int cnt=dataE.at(N-2);
  for(int i=1;i<N-1;i++){
    int tmp=dataW.at(i-1)+dataE.at(N-2-i);
    cnt=min(cnt,tmp);
  }
  cnt=min(cnt,dataE(N-2));
  cout<<cnt<<endl;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,tmp=0,tmp2=0;
  int a[LIMIT2]={0};
  char s[LIMIT2];
  
  scanf("%lld",&n);
  scanf("%s",s);
  rep(i,n){
    if(s[i]=='E') tmp2++;
  }
  rep(i,n){
    if(s[i]=='E') tmp2--;
    if(i==0) result = tmp+tmp2;
    else result = min(result,tmp+tmp2);
    if(s[i]=='W') tmp++;
  }
  printf("%lld",result);
  return 0;
}
//  [c]
#include <stdio.h>
char s[300000];
int main(){
  int n,i,count=0,count_min;
  
  scanf("%d",&n);
  scanf("%s",s);
  
  for(i=1;i<n;i++){
    if(s[i]=='E'){
      count++;
    }
  }
  count_min=count;
  
  for(i=1;i<n;i++){
    if(s[i-1]=='W'){
      count+=1;
    }
    if(s[i]=='E'){
      count-=1;
    }
    
    if(count<count_min){
      count_min=count;
    }
  }
  
  printf("%d",count_min);
}
//  [c]
#include <stdio.h>
char s[300000];
int main() {
    int n, cou = 0, min;
    scanf("%d %s", &n, s);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'E') {
            cou++;
        }
    }
    min = cou;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'E') cou--;
        if (i != 0 && s[i - 1] == 'W') cou++;
        if (cou < min) min = cou;
    }
    printf("%d\n", min);
    return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)

int main()
{
    int i,j;
    long N;
    char s[300010];
    long ans = 150000;
    int sum;

    scanf("%ld", &N);
    scanf("%s", s);

    for (i = 0; i < N; i++) {
        sum = 0;
        for (j = 0; j < i; j++) {
            if (s[j] != 'E')
                sum++;
        }

        if (sum >= ans) break;

        for (j = i + 1; j < N; j++) {
            if (s[j] != 'W')
                sum++;
        }

        if (sum < ans)
            ans = sum;

    }
    
    printf("%ld", ans);

    return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)

int main()
{
    int N,i,j;
    char s[300010];
    long ans = 300000;
    int sum;

    scanf("%d", &N);
    scanf("%s", s);

    for (i = 0; i < N; i++) {
        sum = 0;
        for (j = 0; j < i; j++) {
            if (s[j] != 'E')
                sum++;
            if (sum >= ans) break;
        }

        for (j = i + 1; j < N; j++) {
            if (s[j] != 'W')
                sum++;
            if (sum >= ans) break;
        }

        if (sum < ans)
            ans = sum;

    }
    
    printf("%ld", ans);

    return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)

int main()
{
    int N,i,j;
    char s[300010];
    long ans = 300000;
    int sum;

    scanf("%d", &N);
    scanf("%s", s);

    for (i = 0; i < N; i++) {
        sum = 0;
        for (j = 0; j < i; j++) {
            if (s[j] != 'E')
                sum++;
        }
        for (j = i + 1; j < N; j++) {
            if (s[j] != 'W')
                sum++;
        }
        if (sum < ans)
            ans = sum;

    }
    
    printf("%ld", ans);

    return 0;
}
//  [javascript]
function main(input) {
  input = input.split('\n');
  var n = Number(input[0]);
  var seq = input[1];
  var change = 0;
  for (var i = 1; i < n; i++) {
    if (seq[i] === 'E') change += 1;
  }
  var minChange = change;
  var prev = seq[0];
  for (i = 1; i < n; i++) {
    if (prev === 'W') {
      change += 1;
    }
    if (seq[i] === 'E') {
      change -= 1;
    }
    minChange = Math.min(change, minChange);
    prev = seq[i];
  }
  console.log(minChange);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
"use strict";

var main = function main(input) {
  var N = parseInt(input.split('\n')[0], 10);
  var S = input.split('\n')[1].split('');
  var init = 0;

  for (var i = 0; i < N; i++) {
    if (S[i] == 'E' && i != 0) {
      init++;
    }
  }

  var tmp = init;
  var min = init;

  for (var _i = 1; _i < N; _i++) {
    if (S[_i] == 'E' && S[_i - 1] == 'E') {
      tmp--;
    } else if (S[_i] == 'W' && S[_i - 1] == 'W') {
      tmp++;
    }

    if (tmp < min) {
      min = tmp;
    }
  }

  console.log(min);
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));
//  [javascript]
function main(input){
  const lines = input.split('\n');

  const N = parseInt(lines[0]);
  const S = lines[1].split('');

  
  var result = Math.pow(10, 8);
  var current_count = 0;
  for(var i=1;i<N;i++){
    if(S[i]=='E'){current_count++;}
  }
  result = current_count;

//    console.log(current_count);
  for(var i=1;i<N;i++){
    if(S[i]=='E'){current_count--;}
    if(S[i-1]=='W'){current_count++;}
    result = Math.min(result, current_count);
//    console.log(current_count);
  }
//    console.log('---');

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict';
function Main(stdin){
  const input = stdin.trim().split(/\r?\n/g);
  const N = Number(input[0]);
  const S = input[1].split('');
  let min_count = N;
  for(let i = 0; i < N; i++){
      let count = 0;
      for(let j = 0; j < N; j++){
          if(j < i){
              if(S[j] === 'W') count++;
          } else if (i < j){
              if(S[j] === 'E') count++;
          }
          if(min_count < count) break;
      }
      if(count < min_count) min_count = count;
  }
  console.log(min_count);
}

// 固定
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function* stdinIter() {
    var stdin = require('fs').readFileSync('/dev/stdin', 'utf-8').trim().split(/\n|\s/)
    yield* stdin
}

let _iter
function readMany(n, iter) {
    _iter = iter || _iter || stdinIter()
    var res = []
    for (let i = 0; i < n; i += 1) res.push(_iter.next().value)
    return res
}

(() => {
  	'use strict'
    const [ n, s ] = readMany(2)

    const west = []
    for (let i = 0; i < n; i += 1) {
        const before = west[i - 1] || 0
        if (s[i] == 'W') {
            west.push(before + 1)
        } else {
            west.push(before)
        }
    }

    const leader = []
    for (let i = 0; i < n; i += 1) {
        const people = (west[i - 1] || 0) + ((n - i - 1) - (west[n - 1] - west[i]))
        leader.push(people)
    }

    let ans = Infinity
    for (let i = 0; i < n; i += 1) {
        if (leader[i] < ans) ans = leader[i]
    }

    console.log(ans)
})()
//  [javascript]
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const S = arg[1].split("");
    
    // リーダーより右は全員Wになる
    // 左は全員Eになるべき
    
    let W = 0;
    let E = S.filter(n=>n === "E").length;
    
    if(E === N || E === 0) {
        console.log(0);
        return;
    }
    
    let answer = Infinity;
    
    for(let i=0; i<N; i++) {
        let toE = 0;
        let toW = 0;
    
        if(E > 0) {
            toW = E;
        }
        
        if(W > 0) {
            toE = W;
        }
        
        const temp = toE + toW;
        answer = Math.min(answer, temp);
        
        if(S[i] === "W") {
            W++;
        } else {
            E--;
        }
        
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	maxSize := 300000 * 2
	buf := make([]byte, maxSize)
	sc.Buffer(buf, maxSize)
	n := scanLineInt(sc)
	s := scanLineStr(sc)

	var count int
	for i := 0; i < n; i++ {
		if s[i] == 'E' {
			count++
		}
	}

	min := count
	for i := 0; i < n; i++ {
		if s[i] == 'E' {
			count--
		}
		if i > 0 && s[i-1] == 'W' {
			count++
		}
		if count < min {
			min = count
		}
	}
	fmt.Println(min)
}

func scanLineStr(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanLineInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	maxSize := 300000 * 2
	buf := make([]byte, maxSize)
	sc.Buffer(buf, maxSize)
	n := scanLineInt(sc)
	s := scanLineStr(sc)

	var count int
	for i := 0; i < n; i++ {
		if s[i] == 'E' {
			count++
		}
	}

	result := count
	for i := 0; i < n; i++ {
		if s[i] == 'E' {
			count--
		}
		if i > 0 && s[i-1] == 'W' {
			count++
		}
		result = min(result, count)
	}
	fmt.Println(result)
}

func scanLineStr(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanLineInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	maxSize := 300000 * 2
	buf := make([]byte, maxSize)
	sc.Buffer(buf, maxSize)
	sc.Scan()
	s := scanLineStr(sc)

	count := 0
	for i := range s {
		if s[i] == 'E' {
			count++
		}
	}

	result := count
	for i := range s {
		if s[i] == 'E' {
			count--
		}
		if i > 0 && s[i-1] == 'W' {
			count++
		}
		result = min(result, count)
	}
	fmt.Println(result)
}

func scanLineStr(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanLineInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
)

var rdr = bufio.NewReaderSize(os.Stdin, 10000000)

func readLine() string {
	buf := make([]byte, 0, 10000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	_, S := readLine(), readLine()

	fmt.Printf("%d\n", ABC098C(S))
}

// ABC098C ...
func ABC098C(S string) int {
  	w, e := []int{0}, []int{0}
  
	for i := 1; i < len(S); i++ {
		if S[i-1] == 'W' {
			w = append(w, w[i-1]+1)
		} else {
			w = append(w, w[i-1])
		}
	}

	for i := len(S) - 2; i >= 0; i-- {
		if S[i+1] == 'E' {
			e = append([]int{e[0] + 1}, e...)
		} else {
			e = append([]int{e[0]}, e...)
		}
	}

	res := len(S)
	for leader := 0; leader < len(S); leader++ {
		tmp := w[leader] + e[leader]
		if tmp < res {
			res = tmp
		}
	}

	return res
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	_, S := readLine(), readLine()

	fmt.Printf("%d\n", ABC098C(S))
}

// ABC098C ...
func ABC098C(S string) int {
	l, r := 0, 0
	for i := 0; i < len(S); i++ {
		if S[i] == 'E' {
			r++
		}
	}
	res := l + r

	for leader := 1; leader < len(S); leader++ {
		if S[leader-1] == 'W' {
			l++
		}
		if S[leader] == 'E' {
			r--
		}
		if l+r < res {
			res = l + r
		}
	}

	return res
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, S := nextInt(), nextLine()

	fmt.Printf("%d\n", ABC098C(N, S))
}

// ABC098C ...
func ABC098C(N int, S string) int {
	res := N

	for leader := 0; leader < N; leader++ {
		tmp := 0
		for j := 0; j < N; j++ {
			if leader < j && S[j] == 'E' {
				tmp++
			} else if j < leader && S[j] == 'W' {
				tmp++
			}
		}
		if tmp < res {
			res = tmp
		}
	}

	return res
}
//  [ruby]
n = gets.to_i
s = gets.chomp
count = 3000000

left_count = 0 # 先頭から
right_count = s.count('E') # 最初は向く方向が代わるEをカウント

n.times do |i|
  if s[i] == 'W'
    ans = left_count + right_count
    left_count += 1
  else
    right_count -= 1
    ans = left_count + right_count
  end
  count = ans if ans < count
end

puts count
//  [ruby]
n = gets.chomp.to_i
x = gets.chomp

left = 0
right = x.count("E")
ans = n

n.times do |i|
  s = 0
  curr = x[i]
  if curr == "W"
    s = left + right
    left += 1
  else
    right -= 1
    s = left + right
  end
  ans = s if s < ans
end
puts ans
//  [ruby]
n = gets.to_i
s = gets.chomp
tmp = 0
cum = [0]
min = 3 * 10**5 - 1

s.each_char do |c|
  tmp += 1 if c == 'W'
  cum << tmp
end

1.upto(n) do |i|
  tmp = cum[i - 1] + n - i - (cum[-1] - cum[i])
  min = tmp if min > tmp
end

puts min
//  [ruby]
n = gets.to_i
s = gets.chomp.split('').map &:to_s

$w_rui = [0]
$e_rui = [0]
(1..n).each do |i|
  $w_rui.push s[i] === 'W' ? $w_rui[-1] + 1 : $w_rui[-1]
  $e_rui.unshift s[n-i] === 'E' ? $e_rui[0] + 1 : $e_rui[0]
end

puts [$w_rui , $e_rui].transpose.map{|x| x.sum}.min
//  [ruby]
n = gets.to_i
pontas = gets.chomp.chars

count_e = pontas.count('E')

costs = (1...n).each_with_object([[count_e, 0]]) { |i, result|
  result <<
      [
        pontas[i] == 'E' ? result.last.first - 1 : result.last.first,
        pontas[i - 1] == 'W' ? result.last.last + 1 : result.last.last
      ]
}

puts costs.map { |left_cost, right_cost| left_cost + right_cost }.min
//  [ruby]
n = gets.to_i
pontas = gets.chomp.chars

count_e = pontas.count('E')

costs = (1...n).each_with_object([[count_e, 0]]) { |i, result|
  result <<
      [
        pontas[i] == 'E' ? result.last.first - 1 : result.last.first,
        pontas[i - 1] == 'W' ? result.last.last + 1 : result.last.last
      ]
}

puts costs.map(&:sum).min
//  [rust]
#![allow(non_snake_case)]

use std::io;
use std::cmp::min;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line.clear();
    io::stdin().read_line(&mut line).unwrap();
    let S: Vec<char> = line.chars().collect();

    let mut cnt = 0;
    for i in 1..S.len() {
        if S[i] == 'E' {
            cnt += 1;
        }
    }
    let mut ret = cnt;
    for i in 1..S.len() - 1 {
        if S[i - 1] == 'W' {
            cnt += 1;
        }
        if S[i] == 'E' {
            cnt -= 1;
        }
        ret = min(ret, cnt);
    }

    println!("{}", ret);
}
//  [rust]
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let n: usize;
    input!(n);
    let s = str2vec(&input_line_str());
    let mut ecount_right = 0;
    let mut wcount_left = 0;
    for z in &s {
        if *z == 'E' {
            ecount_right += 1;
        }
    }

    let mut ans = 999999;

    for z in 0..n+1 {
        ans = std::cmp::min(wcount_left + ecount_right, ans);

        if z == n{
            break;
        }
        if s[z] == 'W' {
            wcount_left += 1;
        } else {
            ecount_right -= 1;
        }
    }
    p(ans);
}
//  [rust]
use std::iter::once;

fn solve(n: usize, s: String) -> i32 {
    let v = once(0)
        .chain(
            s.chars()
                .scan(0, |s, c| {
                    *s = *s + if c == 'E' { 1 }  else { 0 };
                    Some(*s)
                }
            )
        )
        .collect::<Vec<usize>>();
    (0..(n+1))
        .map(|i| i - v[i] + v[n] - v[i])
        .min()
        .map(|i| i as i32)
        .unwrap()
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n = s.trim().parse().ok().unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s = s.trim().to_string();
    let res = solve(n, s);
    println!("{}", res);
}
//  [rust]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::min;

#[fastout]
fn main() {
    input! {
    n: usize,
    s: Chars
    }
    let mut l = vec![vec![0; 2]; n + 2];
    for i in 0..n {
        l[i + 1][0] = l[i][0];
        l[i + 1][1] = l[i][1];
        l[i + 1][if s[i] == 'W' { 0 } else { 1 }] += 1;
    }
    l[n + 1] = l[n].clone();
    let mut ans = std::usize::MAX;
    for i in 0..n {
        ans = min(ans, l[i][0] + l[n + 1][1] - l[i][1]);
    }
    println!("{}", ans);
}
//  [rust]
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        n: usize,
        s: Chars,
    }

    let mut cnt_vec: Vec<(usize, usize)> = vec![(0, 0)];

    for i in 0..n {
        let (e, w) = cnt_vec.last().unwrap();
        if s[i] == 'W' {
            cnt_vec.push((*e, *w+1))
        } else {
            cnt_vec.push((*e+1, *w));    
        }
    }

    let mut ans = INF;

    for i in 0..n {
        let t = cnt_vec[i].1 + cnt_vec[cnt_vec.len()-1].0 - cnt_vec[i].0;
        ans = std::cmp::min(ans, t);
    }

    println!("{}", ans);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
        s: Chars,
    }

    let mut face = 0;
    for i in 0..n {
        if s[i]=='W' {
            face += 1;
        }
    }

    let mut ans = 0;
    if s[0]=='W' {
        face -= 1;
    }
    ans = face;
    for i in 1..n {
        if s[i-1]=='W' && face!=0{
            face -= 1;
        } else {
            face += 1;
        }  
        ans = max(ans, face);
        debug!(face);
    }

    println!("{}", n-ans-1);

}
//  [swift]
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let n = readInt()
    let aryS = readLine()!.map { String($0) }
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var countLeft = 0
    var countRight = 0
    for i in 1..<n {
        if aryS[i] == "E" {
            countRight += 1
        }
    }
    var ans = countLeft + countRight
    // i = リーダのindex
    for i in 1..<n {
        if aryS[i - 1] == "W" {
            countLeft += 1
        }
        if aryS[i] == "E" {
            countRight -= 1
        }
        ans = min(ans, countLeft + countRight)
    }
    print(ans)
}
main()