Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n,m = list(map(int,input().split()))
a = [[] for i in range(n+1)]
b = []
for i in range(m):
    p,s = list(map(int,input().split()))
    a[p].append(s)
    b.append([p,s])

for i in range(n+1):
    a[i].sort()

for i in range(m):
    ken = b[i][0]
    si = a[ken].index(b[i][1]) +1
    ken = str(ken).zfill(6)
    si = str(si).zfill(6)
    print("".join([ken,si]))

### FIXED CODE ###

from bisect import bisect_left


n,m = list(map(int,input().split()))
a = [[0] for i in range(n)]
b = [None]*m
for i in range(m):
    p,s = list(map(int,input().split()))
    p-=1
    a[p].append(s)
    b[i] = [p,s]
for i in range(len(a)):
    a[i].sort()
for i in range(len(b)):
    ken = b[i][0]
    si = bisect_left(a[ken], b[i][1])
    ken = str(ken+1).zfill(6)
    si = str(si).zfill(6)
    print("".join([ken,si]))
### BUGGY CODE ###

n = int(input())
numbers = list(map(int, input().split()))

sum = 0
for i in range(n):
    for j in range(i + 1, n):
        sum += numbers[i] * numbers[j]
        sum %= 1000000007
print(sum)


### FIXED CODE ###

n = int(input())
numbers = list(map(int, input().split()))
result = 0
sum_of_numbers = sum(numbers)
for i in range(n - 1):
    sum_of_numbers -= numbers[i]
    result += numbers[i] * sum_of_numbers
    result %= 1000000007
print(result)
### BUGGY CODE ###

n = int(input())

a = list(map(int, input().split(" ")))

i = 0
list = []

for a_s in a:
    list.insert(0, (a.index(n - i) + 1))
    i += 1

print(*list)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split(" ")))
dic = {}
i = 0
for a_s in a:
    dic.setdefault(i, a_s)
    i += 1
for k, v in sorted(dic.items(), key=lambda x: x[1]):
    print(k + 1)
### BUGGY CODE ###

# coding: utf-8
bodies_count = list(map(int,input().split()))
enemy_life = list(map(int,input().split()))
count = 0

if bodies_count[1] == 0:
    print(sum(enemy_life))
else:
    for i in range(bodies_count[1]):
        if enemy_life == []:
            print(count)
            break
        else:
            enemy_life.pop(enemy_life.index(max(enemy_life)))

    if enemy_life != []:
        print(sum(enemy_life))


### FIXED CODE ###

# coding: utf-8
bodies_count = list(map(int,input().split()))
enemy_life = list(map(int,input().split()))

if bodies_count[1] == 0:
    print(sum(enemy_life))
else:
    enemy_life.sort(reverse=True)
    if bodies_count[1] == 1:
        del enemy_life[0] 
    else:
        a = bodies_count[1]
        del enemy_life[0:a]

    if enemy_life != []:
        print(sum(enemy_life))
    else:
        print(0)
    # for i in range(bodies_count[1]):
    #     if enemy_life == []:
    #         print(count)
    #         break
    #     else:
    #         enemy_life.sort()
    #         print(enemy_life)
    #         enemy_life.pop(enemy_life.index(max(enemy_life)))
### BUGGY CODE ###

n = int(input())
s = input()

ans = []
for i in range(n):
  res = 0
  if 1<=i<=n-2:
    for j in range(i):
      if s[j] == 'W':
        res += 1
    for k in range(i+1, n):
      if s[k] == 'E':
        res += 1
    ans.append(res)
    
  
  elif i == 0:
    if s[0] == 'E':
      res = s.count('E')-1
    else:
      res = s.count('E')
    ans.append(res)
      
  elif i == n-1:
    if s[n-1] == 'W':
      res = s.count('W')-1
    else:
      res = s.count('W')
    ans.append(res)
print(min(ans))

### FIXED CODE ###

n = int(input())
s = input()

ans = [0]*(n+1)
for i in range(n):
  if s[i] == 'E':
    ans[i+1] = ans[i] + 1
  else:
    ans[i+1] = ans[i]
    
print(min(i-ans[i]+ans[n]-ans[i+1] for i in range(n)))
### BUGGY CODE ###

N, *A = map(int, open(0).read().split())

MOD = 10 ** 9 + 7

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += A[i] * A[j] % MOD
print(ans % MOD)

### FIXED CODE ###

from itertools import accumulate

MOD = 10 ** 9 + 7
N, *A = map(int, open(0).read().split())

B = list(accumulate(A)) # cumsum

ans = 0
for i in range(N-1):
    ans += A[i] * (B[-1] - B[i]) % MOD
    ans %= MOD
print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read

N, K, *h = map(int, read().split())
# print(N, K, h)

# コスト無限大で初期化
INF = float("inf")
dp = [ INF ] * N
dp[0] = 0

for i in range(1, N):
  # i番目の梯子までの最小移動コストは、
  # 「i-1番目までの移動コスト」+「i-1番目からi番目への移動コスト」
  # もしくは、
  # 「i-2番目までの移動コスト」+「i-2番目からi番目への移動コスト」
  # ...
  # もしくは、
  # 「i-K番目までの移動コスト」+「i-K番目からi番目への移動コスト」
  # のうち、最も小さいものが、最小移動コストになる
  
  # jをi-Kからi-1まで変化させながら、最小の組み合わせを探す
  # ただし、jが負の値にならないよう注意
  j_min = max(0, i-K)
  dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(j_min, i))
  # print(dp)

print(dp[N-1])

### FIXED CODE ###

import numpy as np
import sys
N, K = map(int,input().split())
h = np.fromstring(input(), dtype=np.int64, sep=' ')

# コスト無限大で初期化
INF = 10**10
dp = np.array([INF]*N)
dp[0] = 0
for i in range(1, N):
  # i番目の梯子までの最小移動コストは、
  # 「i-1番目までの移動コスト」+「i-1番目からi番目への移動コスト」
  # もしくは、
  # 「i-2番目までの移動コスト」+「i-2番目からi番目への移動コスト」
  # ...
  # もしくは、
  # 「i-K番目までの移動コスト」+「i-K番目からi番目への移動コスト」
  # のうち、最も小さいものが、最小移動コストになる
  
  # jをi-Kからi-1まで変化させながら、最小の組み合わせを探す
  # ただし、jが負の値にならないよう注意
  j_min = max(0, i-K)
  dp[i] = np.min(dp[j_min: i] + np.abs(h[i] - h[j_min: i]))

print(dp[N-1])
### BUGGY CODE ###

a = int(input())
li = list(map(int,input().split()))


count = 0
li = sorted(li)
for i,v in enumerate(li):
    for j in li[i+1:]:
        if v != j:
            pass
        elif v==j:
            count += 1

if count >0:
    print('NO')
else:
    print("YES")

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split(' ')))

is_break = False
seen = set()
for a in A:
    if a not in seen:
        seen.add(a)
    else:
        is_break=True
        break

if is_break:
    print('NO')
else:
    print('YES')
### BUGGY CODE ###

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))

n = input_one_number()
a = input_multiple_number_as_list()

ssum =0
mod = 10**9+7
import itertools as itr
for i in itr.combinations(range(len(a)),2):
	ssum += a[i[0]]*a[i[1]]
	ssum %= mod
print(ssum)

### FIXED CODE ###

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))

n = input_one_number()
a = input_multiple_number_as_list()

mod = 10**9+7
ssum = 0

sumA = sum(a)

for _a in a:
	ssum += _a * (sumA-_a)

print(ssum//2%mod)
### BUGGY CODE ###

from functools import lru_cache
import math
def main():
    n=int(input())
    a=list(map(int,input().split()))
    ap=[set(prime_factorize(i)) for i in a]
    x=set()
    for i in ap:
        if len(x & i) > 0:
            break
        x |= i
    else:
        print("pairwise coprime")
        return
    x=a[0]
    for i in a:
        x = math.gcd(x, i)
    if x == 1:
        print("setwise coprime")
        return
    print("not coprime")

def prime_factorize(n: int) -> list:
    '''引数nの素因数分解結果のlistを返す。'''
    arr = []
    # 2で割り続け奇数まで還元する
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    # sqrt(n)までの素数で試し割
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

@lru_cache(maxsize=None)
def primes(n:int) -> list:
    '''n以下の全素数をlistで返す'''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

# 素数判定（単純な素数判定なら十分早い。大量にやる場合はX in primesがよさそう）
@lru_cache(maxsize=None)
def is_prime(n: int) -> bool:
    '''引数nが素数であればTrue、そうでなければFalseを返す'''
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True

if __name__ == "__main__":
    main()

### FIXED CODE ###

from functools import lru_cache
import math
def main():
    n=int(input())
    a=list(map(int,input().split()))
    pair,setwise=True,True
    x,y=set(),a[0]
    for i in a:
        if pair:
            ap=set(prime_factorize(i))
            if len(x & ap) > 0:
                pair=False
            x |= ap
        y=math.gcd(y, i)
    if pair:
        print("pairwise coprime")
    elif y == 1:
        print("setwise coprime")
    else:
        print("not coprime")

def prime_factorize(n: int) -> list:
    '''引数nの素因数分解結果のlistを返す。'''
    arr = []
    # 2で割り続け奇数まで還元する
    while n % 2 == 0:
        arr.append(2)
        n //= 2
    # sqrt(n)までの素数で試し割
    for f in primes(int(n**0.5)):
        while n % f == 0:
            arr.append(f)
            n //= f
    if n != 1:
        arr.append(n)
    return arr

@lru_cache(maxsize=None)
def primes(n:int) -> list:
    '''n以下の全素数をlistで返す'''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

@lru_cache(maxsize=None)
def is_prime(n: int) -> bool:
    '''引数nが素数であればTrue、そうでなければFalseを返す'''
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    for i in range(3, int(n**0.5)+1, 2):
        if n % i == 0:
            return False
    return True

if __name__ == "__main__":
    main()
### BUGGY CODE ###

n,m = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(m)]
y,z,ans = [[] for i in range(n+1)],[None for i in range(n+1)],"Yes"
for i,j,k in x:
	y[i].append([j,k])
	y[j].append([i,-k])
for i in range(1,n+1):
	if z[i] == None:
		z[i],q = 0,[i]
		while q:
			p = q.pop()
			for j,k in y[p]:
				if z[j] == None: q,z[j] = q+[j],z[p]+k
for i in range(1,n+1):
	for j,k in y[i]:
		if z[i]+k != z[j]:
			ans = "No"
			break
print(ans)

### FIXED CODE ###

n,m = (int(i) for i in input().split())
y,z,ans = [[] for i in range(n+1)],[None for i in range(n+1)],"Yes"
for num in range(m):
	i,j,k = (int(i) for i in input().split())
	y[i].append([j,k])
	y[j].append([i,-k])
for i in range(1,n+1):
	if z[i] == None:
		z[i],q = 0,[i]
		while q:
			p = q.pop()
			for j,k in y[p]:
				if z[j] == None:
					q.append(j)
					z[j] = z[p]+k
for i in range(1,n+1):
	for j,k in y[i]:
		if z[i]+k != z[j]: ans = "No"
print(ans)
### BUGGY CODE ###

N, K = list(map(int, input().split()))
P = list(map(int, input().split()))

max_s = 0
len_P = len(P)
for i in range(len_P):
  if i+K < len_P and P[i] < P[i+K]:
    continue
  sum_K = sum(P[0+i:K+i])
  if max_s < sum_K:
    max_s = sum_K
print((max_s+K) / 2)

### FIXED CODE ###

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = [0] * 1000000
for i in range(N):
    s[i+1] = s[i] + A[i]

max_s = 0
for i in range(N):
    if max_s < s[i+K] - s[i]:
        max_s = s[i+K] - s[i]


print((max_s+K) / 2)
### BUGGY CODE ###

R,G,B,N=map(int,input().split())

#R*r+G*g+B*b==n
ir= int(N/R)+1
ig=int(N/G)+1
ib=int(N/B)+1
s=0
for r in range(ir):
    for g in range(ig):
        if(R*r+G*g>N):
            break;
        if((N-R*r-G*g)%B==0):
            s+=1
print(s)


### FIXED CODE ###

R,G,B,N=map(int,input().split())

#R*r+G*g+B*b==n
ir=int(N/R)+1
ig=int(N/G)+1
ib=int(N/B)+1
s=0
for r in range(ir):
    for g in range(ig):
        if(R*r+G*g>N):
            break;
        if((N-R*r-G*g)%B==0):
            s+=1
print(s)
### BUGGY CODE ###

n = int(input())
botan = [int(input()) for i in range(n)]
light = 1 # 1番目のボタンが初め光ってる
count = 1
exi = [1]

if 2 in botan:

    while True:
        light = botan[light - 1]
        if light in exi:
            print(-1)
            exit()
        exi.append(light)
    
        if 2 in exi:
            print(count)
            exit()
        count += 1

else:
    print(-1)

### FIXED CODE ###

n = int(input())
botan = [int(input()) for i in range(n)]
light = 0 # 1番目のボタンが初め光ってる
count = 0

for i in range(n):
    light = botan[light] - 1
    if light == 1:
        break
    
if i == n - 1:
    print(-1)
else:
    print(i + 1)
### BUGGY CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def query(i):
    print(i)
    s = in_s()
    if s == 'Vacant':
        exit(0)
    elif s == 'Male':
        return 0
    elif s == 'Female':
        return 1


def main():

    N = in_n()

    min_i = 0
    max_i = N

    fm = query(0)

    while True:
        now_i = (min_i + max_i) // 2
        now_fm = query(now_i)

        if (now_i - min_i) % 2 == 0:
            if now_fm == fm:
                min_i = now_i
            else:
                max_i = now_i
        elif (now_i - min_i) % 2 == 1:
            if now_fm == fm:
                max_i = now_i
            else:
                min_i = now_i

        now_fm = fm


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import random

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def query(i):
    print(i)
    sys.stdout.flush()
    s = in_s()

    if s == 'Vacant':
        exit(0)
    elif s == 'Male':
        return 0
    elif s == 'Female':
        return 1


def main():

    N = in_n()

    min_i = 0
    max_i = N

    min_fm = query(0)
    max_fm = min_fm

    while max_i - min_i != 1:
        now_i = (min_i + max_i) // 2
        now_fm = query(now_i)

        if abs(now_i - min_i) % 2 == 0 and now_fm != min_fm:
            max_i = now_i
            max_fm = now_fm
        elif abs(now_i - min_i) % 2 == 1 and now_fm == min_fm:
            max_i = now_i
            max_fm = now_fm
        elif abs(now_i - max_i) % 2 == 0 and now_fm != max_fm:
            min_i = now_i
            min_fm = now_fm
        elif abs(now_i - max_i) % 2 == 1 and now_fm == max_fm:
            min_i = now_i
            min_fm = now_fm


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n,m = map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

uf = UnionFind(n)

for i in range(m):
    a,b = map(int, input().split())
    a -=1
    b -=1
    uf.union(a,b)
    
res = 0
for j in  uf.roots():
    res = max(res,len(uf.members(j)))
print(res)

### FIXED CODE ###

n,m = map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

uf = UnionFind(n)

for i in range(m):
    a,b = map(int, input().split())
    a -=1
    b -=1
    uf.union(a,b)
    
res = [0]
for j in  uf.roots():
    res.append(uf.size(j))
print(max(res))
### BUGGY CODE ###

#10:30〜10:46 再提出
N=int(input())
A=sorted(map(int,input().split()))
B=[]
for n in range(N):
  B.append(sum(A[:n+1]))
c=0
for n in range(N-1):
  if B[n]*2 >= A[n+1]:
    c+=1
  else:
    c=0
print(c+1)

### FIXED CODE ###

#累積和で毎回sumしない
N=int(input())
A=sorted(map(int,input().split()))
b=0
c=0
for n in range(N-1):
  b += A[n]
  if b*2 >= A[n+1]:
    c+=1
  else:
    c=0
print(c+1)
### BUGGY CODE ###

from collections import deque

N, K = map(int, input().split())
towns = [0] + list(map(int, input().split()))
checked = [0 for _ in range(N+1)]
next = towns[1]
count = 1
while(True):
  if checked[next] != 0:
    loop = count - checked[next]
    pos = 0
    if K > count:
      pos = checked[next] + (K-checked[next])%loop
    else:
      pos = K
    for i in range(1, N+1):
      if checked[i] == pos:
        print(i)
        exit()
  else:
    checked[next] = count
    count += 1
    next = towns[next]

### FIXED CODE ###

from collections import deque

N, K = map(int, input().split())
towns = [0] + list(map(int, input().split()))
checked = [-1 for _ in range(N+1)]
checked[1] = 0
next = towns[1]
count = 1
    
while(checked[next] < 0):
  checked[next] = count
  count += 1
  next = towns[next]
loop = count - checked[next]
pos = 0
if K >= count:
  pos = checked[next] + (K-checked[next])%loop
else:
  pos = K
for i in range(1, N+1):
  if checked[i] == pos:
    print(i)
    exit()
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B = [i for i in range(N)]
C = []
for i in range(N):
    C.append([A[i],B[i]])
C = sorted(C,reverse=True)
dp = [[0] * (N+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    dp[i][0] = dp[i-1][0] + C[i-1][0]*(-C[i-1][1]+N-i)
    dp[0][i] = dp[0][i-1] + C[i-1][0]*(C[i-1][1]-i+1)
for i in range(1,N+1):
    for j in range(1,N+1):
        if i+j <= N:
            c = C[i+j-1][0]
            d = C[i+j-1][1]
            dp[i][j] = max(dp[i-1][j]+c*abs(N-i-d),dp[i][j-1]+c*abs(j-d-1))
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])
print(dp[N][N])

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = [i for i in range(N)]
C = []
for i in range(N):
    C.append([A[i],B[i]])
C = sorted(C,reverse=True)
dp = [[0] * (N+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    dp[i][0] = dp[i-1][0] + C[i-1][0]*(-C[i-1][1]+N-i)
    dp[0][i] = dp[0][i-1] + C[i-1][0]*(C[i-1][1]-i+1)
for i in range(1,N+1):
    for j in range(1,N+1):
        if i+j <= N:
            c = C[i+j-1][0]
            d = C[i+j-1][1]
            dp[i][j] = max(dp[i-1][j]+c*abs(N-i-d),dp[i][j-1]+c*abs(j-d-1))
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])
print(dp[N][N])
### BUGGY CODE ###

N = int(input())
d = []
for n in range(N):
    s = input()
    if s not in d:
        d.append(s)
print(len(d))

### FIXED CODE ###

N = int(input())
d = {}
for n in range(N):
    s = input()
    d[s] = True
print(len(d))
### BUGGY CODE ###

import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    n = int(stdin.readline().rstrip())
    s = str(stdin.readline().rstrip())
    #n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = n
    for i in range(n):
        left = s[:i]
        right = s[i+1:]
        l = left.count("W")
        r = right.count("E")
        ans = min(ans, r+l)
    print(ans)


main()


### FIXED CODE ###

import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    n = int(stdin.readline().rstrip())
    s = str(stdin.readline().rstrip())
    #n,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = n
    dp = [0 for j in range(n+1)]
    for i in range(n):
        if s[i] == "W":
            dp[i+1] = dp[i] + 1
        else:
            dp[i+1] = dp[i]
    for i in range(n):
        ans = min (ans, dp[i] + ( (n-i-1) - (dp[n] - dp[i+1]) ))
    print(ans)


main()
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
attend = 1
for i in range(n):
    print(a.index(attend) + 1, end=' ')
    attend += 1

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [-1] * n
for i in range (n):
    ans[a[i] - 1] = i + 1
[print(i, end=' ') for i in ans]
### BUGGY CODE ###

#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(temp)
    #if len(ls_target)>=k:
    if i==n:
        break
    i+=1

def check(num):
    for i in range(100):
        if (num < 2**i):
            return i-1, 2**(i-1)
mx = sum(ls_target[0])
digit, mx_bin = check(mx)
ans = 0
for d in range(digit+1):
#    print (mx_bin)
#    print (ls_target)
    new_idx = []
    cnt = 0
    for idx,ls in enumerate(ls_target):
        if sum(ls) & mx_bin > 0:
            cnt += 1
            new_idx.append(idx)
    if cnt >= k:
        ls_target = [ls_target[i] for i in new_idx]
        ans += mx_bin
    mx_bin = int(mx_bin/2)
print (ans)

### FIXED CODE ###

#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(sum(temp))
    if i==n:
        break
    i+=1

def check(num):
    for i in range(50):
        if (num < 2**i):
            return i-1, 2**(i-1)
mx = ls_target[0]
digit, mx_bin = check(mx)
ans = 0
for d in range(digit+1):
#    print (mx_bin)
#    print (ls_target)
    new_idx = []
    cnt = 0
    for idx,ls in enumerate(ls_target):
        if ls & mx_bin > 0:
            cnt += 1
            new_idx.append(idx)
    if cnt >= k:
        ls_target = [ls_target[i] for i in new_idx]
        ans += mx_bin
    mx_bin = int(mx_bin/2)
print (ans)