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

from collections import deque
s = deque(input())
q = int(input())
a = 0
c = ""
for i in range(q):
    b = list(input().split())
    if b[0] == "1":
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        if (a, b[1]) == (0, "1") or (a, b[1]) == (1, "2"):
            s.appendleft(b[2])
        else:
            s.append(b[2])
if a == 0:
    for i in range(len(s)):
        c += s[i]
else:
    for i in range(len(s)):
        c += s[-i-1]
print(c)

### FIXED CODE ###

from collections import deque
s = deque(input())
q = int(input())
a = 0
c = ""
for i in range(q):
    b = list(input().split())
    if b[0] == "1":
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        if (a, b[1]) == (0, "1") or (a, b[1]) == (1, "2"):
            s.appendleft(b[2])
        else:
            s.append(b[2])
if a == 0:
    for i in range(len(s)):
        c += s.popleft()
else:
    for i in range(len(s)):
        c += s.pop()
print(c)
### BUGGY CODE ###

N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))

time = 0
sum_t = sum(t)
velo_cap =[float("inf")]*(2*sum_t+1)
for i in range(N):
  start_t = time
  goal_t = time + 2*t[i]
  for s in range(0,2*sum_t+1):
    if s < start_t:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(start_t-s))
    elif s<goal_t:
      velo_cap[s] = min(velo_cap[s],2*v[i])
    else:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(s-goal_t))
  time += 2*t[i]
for s in range(2*sum_t+1):
  velo_cap[s] = min(velo_cap[s],2*sum_t-s,s)


print(sum(velo_cap)/4-(velo_cap[0]+velo_cap[-1])/8)

### FIXED CODE ###

N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))

time = 0
sum_t = sum(t)
velo_cap =[float("inf")]*(2*sum_t+1)
for i in range(N):
  start_t = time
  goal_t = time + 2*t[i]
  for s in range(0,2*sum_t+1):
    if s < start_t:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(start_t-s))
    elif s<goal_t:
      velo_cap[s] = min(velo_cap[s],2*v[i])
    else:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(s-goal_t))
  time += 2*t[i]
for s in range(2*sum_t+1):
  velo_cap[s] = min(velo_cap[s],2*sum_t-s,s)


print(sum(velo_cap)/4-(velo_cap[0]+velo_cap[-1])/8)
### BUGGY CODE ###

N = int(input().strip())
A = [int(v) for v in input().strip().split(" ")]

counter = 0
for i in range(N):
    count_flag = True
    for j in range(N):
        if i == j: continue
        if A[i] % A[j] == 0:
            count_flag = False
            break
    if count_flag:
        counter += 1

print(counter)

### FIXED CODE ###

N = int(input().strip())
A = [int(v) for v in input().strip().split(" ")]

exist_in_input = [0 for _ in range(10**6 + 1)]
if_can_divide = [0 for _ in range(10**6 + 1)]

for a in A:
    exist_in_input[a] += 1

counter = 0
for i in range(1, 10**6+1):
    if if_can_divide[i] == 1 or exist_in_input[i] == 0:
        continue

    if exist_in_input[i] == 1:
        counter += 1

    for j in range(0, 10**6+1, i):
        if_can_divide[j] = 1

print(counter)
### BUGGY CODE ###

n = int(input())
S = []
for i in range(n):
    tmp = "".join(sorted(input()))
    S.append(tmp)
#print(S)
cnt = 0
for s in S:
    #print(S.count(s))
    cnt += (S.count(s)-1)
print(cnt//2)

### FIXED CODE ###

import collections
n = int(input())
s = collections.Counter(["".join(sorted(input())) for _ in range(n)]).most_common()
#print(s)
cnt = 0
for i in s:
    for j in range(1, i[1]):
        cnt += j
print(cnt)
### BUGGY CODE ###

# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import lil_matrix
import numpy

N,M,L=map(int, raw_input().split())
RG=lil_matrix((N,N))

for i in xrange(M):
    f,t,c = map(int, raw_input().split())
    RG[(f-1,t-1)] = c
    RG[(t-1,f-1)] = c

Rd = floyd_warshall(RG, directed=False)

FG=lil_matrix((N,N))
for i in xrange(N):
    for j in xrange(i+1, N):
        if Rd[i][j] <= L:
            FG[(i,j)] = 1
            FG[(j,i)] = 1

Fd = floyd_warshall(FG, directed=False)

Q=int(raw_input())
for i in xrange(Q):
    s, t = map(int, raw_input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    elif v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))



### FIXED CODE ###

# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int, input().split())
RG=[[0 for i in range(N)] for j in range(N)]

for i in range(M):
    f,t,c = map(int, input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c

Rd = floyd_warshall(RG, directed=False)

FG=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1

Fd = floyd_warshall(FG, directed=False)

Q=int(input())
for i in range(Q):
    s, t = map(int, input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))
### BUGGY CODE ###

N = int(input())
S = input()

nums = []
if S[0] == 'W':
    nums.append(0)

count = 0
d = S[0]
for i in range(N):
    if S[i] == d:
        count+=1
    else:
        nums.append(count)
        d = S[i]
        count = 1
nums.append(count)

min = 3 * 10**5
ans = 0
for i in range(len(nums)):
    if nums[i] == 0:
        continue
    
    ans += sum(nums[1:i:2])
    if i % 2== 0:
        ans += sum(nums[i+2::2])
    else:
        ans += sum(nums[i+1::2])
    if min > ans:
        min = ans
    ans = 0

print(min)


### FIXED CODE ###

N = int(input())
S = input()

wnums = [0]
enums = [0]
for i in range(0, N-1):
    if S[i] == 'W':
        wnums.append(wnums[i]+1)
    else:
        wnums.append(wnums[i])

j=0
for i in range(N-1, 0, -1):
    if S[i] == 'E':
        enums.append(enums[j]+1)
    else:
        enums.append(enums[j])
    j += 1

ans = 3*10**5
num = 0
for i in range(N):
    num = wnums[i] + enums[N-i-1]
    if ans > num:
        ans = num
    num = 0
print(ans)
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort(reverse = True)

def b_search(L,key,left,right):
    #L[i] > keyを満たす最小のi
    #L[i] >= key > L[i+1]
    if key > L[0]:
        return len(L)
    elif key <= L[len(L)-1]:
        return 0
    else:
        mid = (left+right)//2
        if L[mid] >= key and key > L[mid+1]:
            return len(L) - mid - 1
        elif L[mid] < key:
            return b_search(L,key,left,mid)
        else:
            return b_search(L,key,mid,right)

ans = 0
for i in reversed(range(2,N)):
    for j in reversed(range(1,i)):
        ans += b_search(L[:j],L[i]+L[j],0,len(L[:j]))
print(ans)


### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += bisect_left(L,L[i]+L[j])-(j+1)
print(ans)
### BUGGY CODE ###

n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
ans = 0
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
if n != 1:
  lcm = L[0]*L[1]//gcd(L[0],L[1])
  for i in range(2,n):
    p = gcd(L[i],lcm)
    lcm = L[i]*lcm//p
  for i in range(n):
    ans = (ans+((lcm//L[i])%m))%m
else:
  ans = 1
print(ans)

### FIXED CODE ###

n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
ans = 0
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
if n != 1:
  lcm = L[0]*L[1]//gcd(L[0],L[1])
  for i in range(2,n):
    p = gcd(L[i],lcm)
    lcm = L[i]*lcm//p
  for i in range(n):
    k = (lcm%m)*pow(L[i],10**9+5,m)
    ans = (ans+k)%m
else:
  ans = 1
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
r = []
for i in range(N):
  r.append(str(A.index(i+1)+1))
print(' '.join(r))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = list(range(1,N+1,1))
C = zip(A,B)
D = sorted(C)
a, b = zip(*D)
print(" ".join(str(x) for x in b))
### BUGGY CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if k == 1:
  print(0)
else:
  for i in range(1,n):
    if n-i < k-1:
      break
    ans += a[n-i]*cmb(n-i,k-1)
    ans -= a[i-1]*cmb(n-i,k-1)
  print(ans%1000000007)

### FIXED CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

from operator import mul
from functools import reduce
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5
fact = [1, 1]  
factinv = [1, 1]
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if k == 1:
  print(0)
else:
  for i in range(1,n):
    if n-i < k-1:
      break
    ans += a[n-i]*cmb(n-i,k-1,p)
    ans -= a[i-1]*cmb(n-i,k-1,p)
  print(ans%1000000007)
### BUGGY CODE ###

from collections import Counter
N = int(input())
S = list(input())
ans = 10 ** 9
for i in range(N + 1):
  ans = min(ans,Counter(S[:i])["#"] + Counter(S[i:])["."])
print(ans)  

### FIXED CODE ###

from collections import Counter
N = int(input())
S = list(input())
ans = 10 ** 9
hash = [0] * (N + 1)
memo = 0
for i in range(N):
  if S[i] == "#":
    memo += 1
  hash[i + 1] = memo
dot = [0] * (N + 1)
memo = 0
for i in range(N - 1,-1,-1):
  if S[i] == ".":
    memo += 1
  dot[i] = memo    
for i in range(N + 1):
  ans = min(ans, hash[i] + dot[i])
print(ans)
### BUGGY CODE ###


N = int(input())
A_list = [int(item) for item in input().split()]
A_max = max(A_list)
mini = 2020202020 * 200000

all_sum = sum(A_list)

j = int(N/2+1)
is_search = True

while is_search:
    if j == 1:
        is_search = False

    F = A_list[:j]
    F_sum = sum(F)
    B_sum = all_sum - F_sum
    delta = B_sum - F_sum
    abs_delta = abs(B_sum - F_sum)
    if abs_delta <= mini:
        mini = abs_delta

    if delta > 0:
        j += int(j / 2)

    elif delta < 0:
        j = int(j / 2)
    else:
        mini = 0
        is_search = False

print(mini)

### FIXED CODE ###

N = int(input())
A_list = [int(item) for item in input().split()]

all_sum = sum(A_list)

F_sum_list = [A_list[0]]

for j in range(1,N):
    F_sum_list.append(F_sum_list[-1] + A_list[j])

delta_list = [abs(all_sum - 2* i) for i in F_sum_list]

print(min(delta_list))
### BUGGY CODE ###

n=int(input())
x=input()
ans=0
for i in range(0,10):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,100):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
x=input()
ans=0
for i in range(0,10):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,100):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)
### BUGGY CODE ###

s = input()

cnt = 0
while 'BW' in s:
    s = s.replace('BW', 'WB', 1)
    cnt += 1

print(cnt)


### FIXED CODE ###

s = input()

w_cnt = 0
_b_cnt = 0
b_flag = False
cnt = 0
for si in list(s)[::-1]:
    if si == 'B':
        _b_cnt += 1
    if si == 'W':
        cnt += w_cnt * _b_cnt
        w_cnt += 1
        _b_cnt = 0
cnt += w_cnt * _b_cnt

print(cnt)
### BUGGY CODE ###

n = int(input())
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = min(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print(curr_a + curr_b)


### FIXED CODE ###

n = int(input())
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = max(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print(curr_a + curr_b)
### BUGGY CODE ###

N = int(input())
S = input()

stoi = {'R':0, 'G':1, 'B':2}
itos = {1:'R', 2:'G', 3:'B'}
li = [[0] * 3 for _ in range(N)]
ans = 0

for ind, s in enumerate(S):
    if(ind == 0):
        li[ind][stoi[s]] = 1
    else:
        for i in range(3):
            li[ind][i] = li[ind - 1][i]
        li[ind][stoi[s]] += 1

for i in range(N):
    for j in range(i + 1, N):
        if(S[i] == S[j]):
            continue
        k = 2 * j - i
        kc = 6 - (stoi[S[i]] + stoi[S[j]] + 2)
        res = li[-1][kc-1] - li[j][kc-1]
        if(k<N):
            if(kc == stoi[S[k]] + 1):
                res -= 1
        ans += res

print(ans)

### FIXED CODE ###

N = int(input())
S = input()

stoi = {'R':0, 'G':1, 'B':2}
itos = {1:'R', 2:'G', 3:'B'}
li = [[0] * N for _ in range(3)]
ans = 0

for ind, s in enumerate(S):
    if(ind == 0):
        li[stoi[s]][ind] = 1
    else:
        for i in range(3):
            li[i][ind] = li[i][ind - 1]
        li[stoi[s]][ind] += 1

for i in range(N):
    for j in range(i + 1, N):
        if(S[i] == S[j]):
            continue
        k = 2 * j - i
        kc = 6 - (stoi[S[i]] + stoi[S[j]] + 2)
        res = li[kc-1][-1] - li[kc-1][j]
        if(k < N and kc == stoi[S[k]] + 1):
            res -= 1
        ans += res

print(ans)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def comb_mod_p(n, k, p):
  x = 1
  for ik in range(k):
    x *= ((n-ik) * pow(ik+1, p-2, p))
    x %= p
  return x

def main():
  n, k = map(int, input().strip().split())
  for i in range(1,k+1):
    print((comb_mod_p(n-k+1, i, MAX) * comb_mod_p(k-1, i-1, MAX)) % MAX)

if __name__=='__main__':
  main()



### FIXED CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

MAX = 10**9 + 7

def pow_mod_p(n, k, p):
  x = 1
  while k:
    if k % 2 == 1:
      x *= n
      x %= p
    n **= 2
    n %= p
    k >>= 1
  return x

def comb_mod_p(n, k, p):
  x = 1
  for ik in range(k):
    x *= ((n-ik) * pow_mod_p(ik+1, p-2, p))
    x %= p
  return x

def main():
  n, k = map(int, input().strip().split())
  a, b = comb_mod_p(n-k+1, 1, MAX), comb_mod_p(k-1, 1-1, MAX)
  for i in range(1,k+1):
    if i != 1:
      a = (a * (n-k+1-(i-1))) * pow_mod_p(i, MAX-2, MAX)
      b = (b * (k-1-((i-1)-1))) * pow_mod_p(i-1, MAX-2, MAX)
    print((a * b) % MAX)

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

import copy

# standart input
# n = int(input())
# a = list(map(int, input().split()))

N = 13
MOD = 10 ** 9 + 7

s = input()
rs = reversed(s)

dp = [0 for i in range(N)]
dp[0] = 1
nextdp = [0 for i in range(N)]

for i, si in enumerate(rs):
    nextdp = [0 for j in range(N)]

    for j in range(10):
        c = 0
        if si == "?":
            c = (j * 10 ** i) % N
        elif j == 0:
            c = (int(si) * 10 ** i) % N
        else:
            break

        for k in range(N):
            nextdp[(k + c) % N] = (nextdp[(k + c) % N] + dp[k]) % MOD

    dp = copy.copy(nextdp)

print(dp[5])


### FIXED CODE ###

# standart input
# n = int(input())
# a = list(map(int, input().split()))

N = 13
MOD = 10 ** 9 + 7

s = input()[::-1]

dp = [0 for i in range(N)]
nextdp = [0 for i in range(N)]
zeros = [0 for i in range(N)]
dp[0] = 1

r = 1
for i, si in enumerate(s):
    nextdp = zeros[:]

    for j in range(10):
        jj = j
        if si == "?":
            pass
            # c = (j * 10 ** i) % N
        elif j == 0:
            jj = int(si)
        else:
            break

        for k in range(N):
            l = (k + r * jj) % N
            nextdp[l] = (nextdp[l] + dp[k]) % MOD

    dp = nextdp
    r = r * 10 % N

print(dp[5])
### BUGGY CODE ###

#coding:utf-8
#1_9_C
l = list()
while True:
    cmd = input().split()
    if cmd[0] == "end":
        break
    elif cmd[0] == "insert":
        l.append(int(cmd[1]))
    else:
        print(max(l))
        l.remove(max(l))

### FIXED CODE ###

#coding:utf-8
#1_9_C
import heapq

h = []
while True:
    cmd = input().split()
    if cmd[0] == "end":
        break
    elif cmd[0] == "insert":
        heapq.heappush(h, -int(cmd[1]))
    else:
        print(-heapq.heappop(h))
### BUGGY CODE ###

n= input()

def digit_sum(s):
	ans=0
	for digit in s:
		ans+= int(s)
	return ans

if digit_sum(n)%9==0:
	print('Yes')
else:
	print('No')

### FIXED CODE ###

n= int(input())

def digit_sum(s):
	ans=0
	for digit in str(s):
		ans+= int(digit)
	return ans

if digit_sum(digit_sum(digit_sum(n)))%9==0:
	print('Yes')
else:
	print('No')
### BUGGY CODE ###

n,m = map(int,input().split())
count_ac = 0
count_wa = 0
l = []
for i in range(m):
    t = tuple(input().split())
    l.append(t)
set_l = list(set(l))
for i in range(len(set_l)):
    if set_l[i][1] == 'AC':
        count_ac += 1
for i in range(1,n+1):
    if (str(i), 'AC') in l:
        idx = l.index((str(i), 'AC'))
        count_wa += l[:idx].count((str(i),'WA'))

print(str(count_ac) + " " + str(count_wa))

### FIXED CODE ###

n,m = map(int,input().split())
ac = [0]*n
wa = [0]*n
for i in range(m):
    p,s = input().split()
    p = int(p)
    if ac[p-1]:
        continue
    if s == 'AC':
        ac[p-1] = 1
    else:
        wa[p-1] += 1
count_ac = 0
count_wa = 0
for i in range(n):
    count_ac += ac[i]
    if ac[i]:
        count_wa += wa[i]
print(str(count_ac) + " " + str(count_wa))
### BUGGY CODE ###

total = 0
N,K = list(map(int,input().split()))
number_list = list(map(int,input().split()))
a = [sum(number_list[i:i+K]) for i in range(N-K+1)]
max_pattern = a.index(max(a))
for r in number_list[max_pattern:max_pattern+K]:
    total += r * (1+r) / (2 * r)
print(total)

### FIXED CODE ###

N,M=list(map(int,input().split()))
l_n=list(map(int,input().split()))
k=[]
j=0
for i in range(1,1001):
   j+=i
   k.append(j/i)
l_n=[k[l_n[i]-1] for i in range(N)]
ans=sum(l_n[0:M])
sum_n=ans
for i in range(N-M):
   sum_n+=l_n[i+M]
   sum_n-=l_n[i]
   ans=max(ans,sum_n)
print(ans)
### BUGGY CODE ###

import itertools

[N,M]=list(map(int,input().split()
              )
          )
XYZ=[[int(i) for i in input().split()] for i in range(N)] 
maxabs=0
for indextupl in list(itertools.permutations(range(N), M)):
  maxabs=max(sum([abs(sum([XYZ[i][j] for i in indextupl])) for j in range(3)]),
             maxabs
            )
  
print(maxabs)

### FIXED CODE ###

[N,M]=list(map(int,input().split()
              )
          )
XYZ=[[int(i) for i in input().split()] for i in range(N)] 
maxabs=0

for i in range(8):
  pm=list(map(int,format(i, 'b')))
  pm=[0,]*(3-len(pm))+pm
  pm=[(-1)**item for item in pm]
  
  newXYZ=sorted([[item[0]*pm[0],item[1]*pm[1],item[2]*pm[2]] for item in XYZ],
                key=lambda x:sum(x),
                reverse=True)
  
  maxabs=max(sum([abs(sum([newXYZ[m][j] for m in range(M)]
                             )
                         ) for j in range(3)
                 ]
                ),
             maxabs
            )


print(maxabs)
### BUGGY CODE ###

N = int(input())
P = input().split(" ")

t = 0
list = []
for i in range(N):
    list.append(int(P[i]))
    m = min(list)
    if m == int(P[i]):
        t = t + 1

print(t)

### FIXED CODE ###

N = int(input())
P = input().split(" ")

t = 1
list = []
for i in range(N):
    list.append(int(P[i]))
    if i == 0:
        m = int(P[0])
    elif int(P[i]) < m:
        m = int(P[i])
        t = t + 1
        
print(t)
### BUGGY CODE ###

from math import factorial as f
N, M, K = map(int, input().split())
mod = 10 ** 9 + 7

def combi(n, r):
  return f(n) // f(n - r) // f(r) % mod

res = 0
c = combi(N * M - 2, K - 2)
cn = c * M ** 2 % mod
cm = c * N ** 2 % mod
temp = ((N - 1 + 1) * (N - 1) // 2) * cn % mod
for i in range(1, N):
  res += temp % mod
  res %= mod
  temp -= (N - i) * cn % mod
#print(res)
temp = ((M - 1 + 1) * (M - 1) // 2) * cm % mod
for i in range(1, M):
  res += temp % mod
  res %= mod
  temp -= (M - i) * cm % mod

print(res % mod)

### FIXED CODE ###

from math import factorial as f
N, M, K = map(int, input().split())
mod = 10 ** 9 + 7

def combi(n, r):
  return f(n) // (f(n - r) * f(r)) % mod

res = 0
c = combi(N * M - 2, K - 2)
for i in range(1, N):
  res += ((N - i + 1) * (N - i) // 2) * c * M * M % mod
  res %= mod

for i in range(1, M):
  res += ((M - i + 1) * (M - i) // 2) * c * N * N % mod
  res %= mod

print(res % mod)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

N,M = map(int,input().split())
L = []
for i in range(N):
  tmp = list(map(int,input().split()))
  L.append(tmp[1:])

dicL = {}
for i in range(N):
  for l in L[i]:
    if l not in dicL:
      dicL[l] = [i]
    else:
      dicL[l].append(i)
#print(dicL)
E = [set() for _ in range(N)]
for k,v in dicL.items():
  if len(v) > 1:
    for i in range(len(v)-1):
      for j in range(i+1,len(v)):
        E[v[i]].add(v[j])
        E[v[j]].add(v[i])
#print(E)
Visited = [0 for _ in range(N)]
def dfs(v):
  Visited[v] = 1
  for u in E[v]:
    if Visited[u] == 0:
      dfs(u)
dfs(0)
print('YES' if sum(Visited) == N else 'NO')
    


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

N,M = map(int,input().split())
L = []
for i in range(N):
  tmp = list(map(int,input().split()))
  L.append(tmp[1:])
#print(L)

# 人(0~N-1)と言語(N~M-1)の間で二部グラフを作る
E = [set() for _ in range(N+M)]
for i in range(N):
  for l in L[i]:
    E[i].add(l+N-1)
    E[l+N-1].add(i)
#print(E)

# 人のノードすべてに到達可能であればYES
Visited = [0 for _ in range(N+M)]
def dfs(v):
  Visited[v] = 1
  for u in E[v]:
    if Visited[u] == 0:
      dfs(u)
dfs(0)
print('YES' if sum(Visited[:N]) == N else 'NO')
### BUGGY CODE ###

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

for i in range(1,N+1):
  print(li.count(i))

### FIXED CODE ###

import collections

N = int(input())
li = list(map(int,input().split()))
clist = collections.Counter(li)
for i in range(1,N+1):
  print(clist[i])
### BUGGY CODE ###

N = int(input())
S = input()

ret = N
for i in range(N):
    a = S[:i]
    b = S[i + 1 :]
    n = a.count("W") + b.count("E")
    if n == 0:
        continue
    ret = min(ret, n)
print(ret)


### FIXED CODE ###

N = int(input())
S = input()
x = 0
a = 0
idx = 0

for i in range(N):
    if S[i] == "W":
        x += 1
    else:
        x -= 1

    if x < a:
        a = x
        idx = i

w = S[0:idx].count("W")
e = S[idx + 1 : N].count("E")
print(w + e)