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

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
m = Counter(A).most_common()[0][0]
l = A.index(m)
r = n - A.index(m, l + 1)


n += 1
fac = [1] * (n + 1)
inv = [1] * (n + 1)
i = 1
for j in range(1, n + 1):
    i = i * j % mod
    fac[j] = i
    inv[j] = pow(i, mod - 2, mod)



def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


for j in range(1, n + 1):
    ret = comb(n, j)
    for k in range(j):
        ret = (ret - comb(l, k) * comb(r, j - k - 1)) % mod
    print(ret)

### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I() + 1
A = LI()
D = defaultdict(lambda:-1)
for i in range(n):
    if D[A[i]] != -1:
        l = D[A[i]]
        r = n - i - 1
        break
    else:
        D[A[i]] = i


fac = [1] * (n + 1)
inv = [1] * (n + 1)
i = 1
for j in range(1, n + 1):
    i = i * j % mod
    fac[j] = i
    inv[j] = pow(i, mod - 2, mod)



def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


for j in range(1, n + 1):
    print((comb(n, j) - comb(r + l, j - 1)) % mod)
### BUGGY CODE ###

def main():
    from collections import deque
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    check = [[1]*n for i in range(n)]
    d = [[float("INF")]*n for i in range(n)]

    dx = [1,-1,0,0]
    dy = [0,0,1,-1]
    for i in range((n+1)//2):
        for j in range(i,n-i):
            d[i][j] = i
            d[-1-i][j] = i
        for j in range(i,n-i):
            d[j][i] = i
            d[j][-1-i] = i
    def update(x,y):
        check[x][y] = 0
        for i in range(4):
            nx = x+dx[i]
            ny = y+dy[i]
            if 0 <= nx < n and 0 <= ny < n:
                d[x][y] = min(d[x][y],d[nx][ny]+check[nx][ny])
        q = deque([])
        q.append((x,y))
        while q:
            bx,by = q.popleft()

            for i in range(4):
                nx = bx+dx[i]
                ny = by+dy[i]

                if 0 <= nx < n and 0 <= ny < n:
                    if d[nx][ny] > d[bx][by]+check[bx][by]:
                        d[nx][ny] = d[bx][by]+check[bx][by]
                        q.append((nx,ny))
                    

    ans = 0
    for i in l:
        i -= 1
        x = i//n
        y = i%n
        ans += d[x][y]
        update(x,y)
    print(ans)

if __name__ =="__main__":
    main()

### FIXED CODE ###

def main():
    from collections import deque
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    check = [[1]*n for i in range(n)]
    d = [[float("INF")]*n for i in range(n)]

    for i in range((n+1)//2):
        for j in range(i,n-i):
            d[i][j] = i
            d[-1-i][j] = i
        for j in range(i,n-i):
            d[j][i] = i
            d[j][-1-i] = i
    def solve(l):
        ans = 0
        for t in l:
            t -=1
            x = t//n
            y = t%n
            check[x][y] = 0
            ans += d[x][y]
            q = deque([])
            q.append((x,y,d[x][y]))
            while q:
                bx,by,z = q.popleft()

                if bx != 0:
                    if d[bx-1][by] > z:
                        d[bx-1][by] = z
                        q.append((bx-1,by,z+check[bx-1][by]))
                if bx != n-1:
                    if d[bx+1][by] > z:
                        d[bx+1][by] = z
                        q.append((bx+1,by,z+check[bx+1][by]))
                if by != 0:
                    if d[bx][by-1] > z:
                        d[bx][by-1] = z
                        q.append((bx,by-1,z+check[bx][by-1]))
                if by != n-1:
                    if d[bx][by+1] > z:
                        d[bx][by+1] = z
                        q.append((bx,by+1,z+check[bx][by+1]))  
        return ans

    
    print(solve(l))

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

n=input()
m=len(n)

cnt=0
for i in range(m):
    cnt +=n[i+1:].count(n[i])
print(m*(m-1)//2-cnt+1)

### FIXED CODE ###

n=input()
m=len(n)

A={chr(i):0 for i in range(97,97+26)}
B={chr(i):0 for i in range(97,97+26)}

cnt=0
for i in range(m):
    A[n[i]] +=1
for i in range(m):
    B[n[i]] +=1
    cnt +=A[n[i]]-B[n[i]]
print(m*(m-1)//2-cnt+1)
### BUGGY CODE ###

import sys
import math
import collections
from collections import deque
#n = int(input())
#a, b = map(int, input().split())
s = input()
#x = list(map(int, input().split()))
q = int(input())
d = deque([])
for i in range(len(s)):
    d.append(s[i])

rev = 1
for i in range(q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        rev *= -1

    else:
        if rev == 1:
            if que[1] == "1":
                d.appendleft(que[2])
            else:
                d.append(que[2])

        else:
            if que[1] == "1":
                d.append(que[2])
            else:
                d.appendleft(que[2])

if rev == 1:
    for i in range(len(d)):
        print(d[i], end="")
else:
    for i in range(len(d)):
        print(d[len(d) - i - 1], end="")



### FIXED CODE ###

import sys
import math
import collections
from collections import deque
def main():
    #n = int(input())
    #a, b = map(int, input().split())
    s = input()
    #x = list(map(int, input().split()))
    q = int(input())
    d = deque([])
    for i in range(len(s)):
        d.append(s[i])

    rev = 1
    for i in range(q):
        que = sys.stdin.readline().split()
        if que[0] == "1":
            rev *= -1

        else:
            if rev == 1:
                if que[1] == "1":
                    d.appendleft(que[2])
                else:
                    d.append(que[2])

            else:
                if que[1] == "1":
                    d.append(que[2])
                else:
                    d.appendleft(que[2])


    if rev == 1:
        for i in range(len(d)):
            print(d.popleft(), end="")
    else:
        for i in range(len(d)):
            print(d.pop(), end="")

main()
### BUGGY CODE ###

# from pprint import pprint
# import math
# import collections
from numba import jit

N = int(input())

loops = 0

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

@jit(cache=True)
def calc(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x


p = []
p_equal = []
for x in range(1, 100):
    for y in range(x, 100 - x):
        if x + y > 100:
            break
        for z in range(y, 100 - (x + y)):
            loops += 1
            if x + y + z > 100:
                break
            p.append((x, y, z))

p_set = set(p)

p_equal = []
p_nonequal = []
for _p in p_set:
    loops += 1
    x, y, z = _p[0], _p[1], _p[2]

    if x == y == z:
        p_equal.append(calc(x, y, z))
    else:
        p_nonequal.append(calc(x, y, z))

# print(p_equal)
# print(p_nonequal)

for i in range(1, N + 1):
    loops += 1
    if i in p_equal:
        print(1)
    elif i in p_nonequal:
        print(3)
    else:
        print(0)

# print('lp',loops)

### FIXED CODE ###

# from pprint import pprint
# import math
# import collections
from numba import jit

N = int(input())

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

@jit(cache=True)
def calc(x, y, z):
    return x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x


res = [0] * 1000009

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n = calc(x, y, z)
            res[n - 1] += 1

for i in range(N):
    print(res[i])
### BUGGY CODE ###

n,k,q=map(int,input().split())
a=[input() for i in range(q)]
for j in range(n):
    if k+a.count(str(j+1))-q>0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n,k,q=map(int,input().split())
a=[0]*n
for i in range(q):
  b=int(input())
  a[b-1]+=1
for i in range(n):
  if k-q+a[i]>0:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

def test(N, A):
  B = 0
  mx = A[0]
  if N != 1: 
    for i in range(1,N):
      if A[i] - mx < 0:
        B = B + mx - A[i]
      mx = max(A[1:i+1])  
  return B

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

B = test(N, A)

print(B)

### FIXED CODE ###

def test(N, A):
  B = 0
  mx = A[0]
  if N != 1: 
    for i in range(1,N):
      if A[i] - mx < 0:
        B = B + mx - A[i]
      else:
        mx = A[i];
  return B

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

B = test(N, A)

print(B)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().rstrip().rsplit()))
A_dict = {}

for val in A:
    A_dict[val] = A_dict.get(val, 0) + 1

limit = 10**18
ans = 1
for val in A_dict:
    ans *= val ** A_dict[val]

if ans > limit:
    ans = -1

print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().rstrip().rsplit()))
A_dict = {}

for val in A:
    A_dict[val] = A_dict.get(val, 0) + 1

limit = 10**18
ans = 1

if A_dict.get(0, 0) > 0:
    ans = 0
else:
    for val in A_dict:
        ans *= val ** A_dict[val]

        if ans > limit:
            ans = -1
            break

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

n=int(input())
l=input()

a=l.count("R")
b=l.count("G")
c=l.count("B")

ans=0
d=0
e=0
f=0

for _ in range(a):
  x=l.find("R",d)
  d=x+1
  for _ in range(b):
    y=l.find("G",e)
    e=y+1
    if e==l.rfind("G")+1:
      e=0
    for _ in range(c):
      z=l.find("B",f)
      f=z+1
      if f==l.rfind("B")+1:
        f=0
      if (abs(x-y)==abs(y-z)) or (abs(x-z)==abs(z-y)) or (abs(y-x)==abs(x-z)):
        ans+=1
    
print(a*b*c-ans)

### FIXED CODE ###

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

ans = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i

        if k >= n:
            continue

        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1

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

from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions,time
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

st = time.time()
n = inp()
a = []
for i in range(n):
    b = inpl()
    a.append(deque(b))
zan = n*(n-1)//2
res = 0
while True:
    res += 1
    now = zan
    s = set()
    for i in range(n):
        if i in s or a[i] == deque([]): continue
        end = True
        chk = a[i][0] - 1
        if not chk in s and a[chk][0] == i+1:
            zan -= 1
            if not zan: 
                print(res); quit()
            a[i].popleft(); a[chk].popleft()
            s.add(i); s.add(chk)
        # print(res,i,chk,a)
    if now == zan or time.time() - st > 1.8:
        print(-1)
        quit()

            


### FIXED CODE ###

from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions,time
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

st = time.time()
n = inp()
a = []
for i in range(n):
    b = inpl()
    a.append(deque(b))
zan = n*(n-1)//2
res = 0
while True:
    res += 1
    now = zan
    s = set()
    for i in range(n):
        if i in s or a[i] == deque([]): continue
        end = True
        chk = a[i][0] - 1
        if not chk in s and a[chk][0] == i+1:
            zan -= 1
            if not zan: 
                print(res); quit()
            a[i].popleft(); a[chk].popleft()
            s.add(i); s.add(chk)
        # print(res,i,chk,a)
        nnn = time.time()
    if now == zan:
        print(-1)
        quit()
    if nnn - st > 1.7:
        print(n*(n-1)//2)
        quit()
### BUGGY CODE ###

N, H = map(int,input().split())
damage_low = [0 for i in range(0,N)]
damage_high = [0 for i in range(0,N)]
count = 0

for i in range(0,N):
    a, b = map(int,input().split())
    damage_low[i] = a
    damage_high[i] = b

damage_low.sort()  #小さいもの順に並べる
damage_high.sort()  
damage_high.reverse()  #降順になる

for i in range(0,N):  #刀を強いもの順に投げる
    if damage_high[i] > damage_low[N-1]:  #一番強い刀の振りより小さければ投げる必要はない
        H = H - damage_high[i]
        count += 1
    if H <= 0:  #投げてる途中でHPが0になったら抜け出す
        break

while H > 0:  #まだHPがのこっているなら一番強い刀で振りまくる
    H = H -damage_low[N-1]
    count += 1

print(count)

### FIXED CODE ###

N, H = map(int,input().split())
damage_low = [0 for i in range(0,N)]
damage_high = [0 for i in range(0,N)]
count = 0

for i in range(0,N):
    a, b = map(int,input().split())
    damage_low[i] = a
    damage_high[i] = b

damage_low.sort()  #小さいもの順に並べる
damage_high.sort()

for i in range(0,N):  #刀を強いもの順に投げる
    if damage_high[N-1-i] > damage_low[N-1]:  #一番強い刀の振りより小さければ投げる必要はない

        H = H - damage_high[N-1-i]  #昇順になってるので逆から指定
        count += 1
    if H <= 0:  #投げてる途中でHPが0になったら抜け出す
        break

while H > 0:  #まだHPがのこっているなら一番強い刀で振りまくる
    if H % damage_low[N-1] == 0:
        count = count + (H // damage_low[N-1])
        break
    else:
        count = count + (H // damage_low[N-1]) + 1
        break

print(count)
### BUGGY CODE ###

a = int(input())
alist = list(map(int, input().split()))
mod = 10**9+7
sumlist = []
ans = 0
for i in range(1, len(alist)+1):
    sumlist.append(sum(alist[0:i]))
for i in range(len(alist)):
    ans += alist[i]*(sumlist[-1]-sumlist[i])
print(ans%mod)

### FIXED CODE ###

a = int(input())
alist = list(map(int, input().split()))
mod = 10**9+7
total = sum(alist)
sumlist = []
ans = 0
for i in range(len(alist)-1):
    total -= alist[i]
    ans += alist[i]*(total)
print(ans%mod)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
cy, cx = map(lambda x:int(x)-1, input().split())
gy, gx = map(lambda x:int(x)-1, input().split())
S = [input() for _ in range(h)]
seen = [[-1]*w for _ in range(h)]
def f(sy, sx, cnt):
    que = []
    que.append((sy, sx))
    seen[sy][sx] = cnt
    while que:
        y, x = que.pop()
        for dy, dx in ((-1,0),(0,-1),(1,0),(0,1)):
            ny, nx = y+dy, x+dx
            if 0 <= ny < h and 0 <= nx < w:
                if seen[ny][nx] != -1:
                    continue
                if S[ny][nx] == "#":
                    continue
                seen[ny][nx] = cnt
                que.append((ny, nx))
cnt = 0
for i in range(h):
  for j in range(w):
    if S[i][j] == "." and seen[i][j] == -1:
      f(i, j, cnt)
      cnt += 1
G = [set() for _ in range(cnt+1)]
for i in range(h):
  for j in range(w):
    for dy in range(-2, 3):
      for dx in range(-2, 3):
        y, x = i+dy, j+dx
        if 0 <= y < h and 0 <= x < w:
          if S[i][j] == "#":
            continue
          if S[y][x] == "#":
            continue
          G[seen[i][j]].add(seen[y][x])
          G[seen[y][x]].add(seen[i][j])
s = seen[cy][cx]
g = seen[gy][gx]
dist = [-1]*(cnt+1)
dist[s] = 0
que = deque()
que.append((s, 0))
while que:
  v, d = que.popleft()
  dist[v] = d
  if g == v:
    print(dist[g])
    exit()
  for i in G[v]:
    if dist[i] != -1:
      continue
    que.append((i, d+1))
print(-1)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
cy, cx = map(lambda x:int(x)-1, input().split())
gy, gx = map(lambda x:int(x)-1, input().split())
S = [input() for _ in range(h)]
seen = [[-1]*w for _ in range(h)]
def f(sy, sx, cnt):
    que = []
    que.append((sy, sx))
    seen[sy][sx] = cnt
    while que:
        y, x = que.pop()
        for dy, dx in ((-1,0),(0,-1),(1,0),(0,1)):
            ny, nx = y+dy, x+dx
            if 0 <= ny < h and 0 <= nx < w:
                if seen[ny][nx] != -1:
                    continue
                if S[ny][nx] == "#":
                    continue
                seen[ny][nx] = cnt
                que.append((ny, nx))
cnt = 0
for i in range(h):
  for j in range(w):
    if S[i][j] == "." and seen[i][j] == -1:
      f(i, j, cnt)
      cnt += 1
G = [set() for _ in range(cnt+1)]
for i in range(h):
  for j in range(w):
    for dy in range(-2, 3):
      for dx in range(-2, 3):
        y, x = i+dy, j+dx
        if 0 <= y < h and 0 <= x < w:
          if S[i][j] == "#":
            continue
          if S[y][x] == "#":
            continue
          G[seen[i][j]].add(seen[y][x])
          G[seen[y][x]].add(seen[i][j])
s = seen[cy][cx]
g = seen[gy][gx]
dist = [-1]*(cnt+1)
dist[s] = 0
que = deque()
que.append(s)
while que:
  v = que.popleft()
  if g == v:
    print(dist[g])
    exit()
  for i in G[v]:
    if dist[i] != -1:
      continue
    dist[i] = dist[v]+1
    que.append(i)
print(-1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
S = li()
Alist = []
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = mi()
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    if AClist[l[i] - 1] != AClist[l[i]]:
        print(AClist[r[i]] - AClist[l[i]])
    else:
        print(AClist[r[i]] - AClist[l[i]-1])


### FIXED CODE ###

import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
# print(N, Q)
S = li()
Alist = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
Aset = set(Alist)
AClist = [0]*(N+1)
for i in range(N-1):
    if i in Aset:
        AClist[i + 2] = AClist[i + 1] + 1
    else:
        AClist[i+2] = AClist[i+1]
        # print(AClist)

for i in range(Q):
    l, r = mi()
    if AClist[l - 1] != AClist[l]:
        print(AClist[r] - AClist[l])
    else:
        print(AClist[r] - AClist[l-1])
### BUGGY CODE ###

arr=[]
n,w=map(int,input().split())
for _ in range(n):
	arr.append(tuple(map(int,input().split())))
dp=[-1]*((n+1)*(w+1))
def f(pos,W):
	if(pos==n):
		return 0
	if dp[pos*(w+1)+W]!=-1:
		return dp[pos*(w+1)+W]
	res=f(pos+1,W)
	if(arr[pos][0]<=W):
		res=max(res,f(pos+1,W-arr[pos][0])+arr[pos][1])
	dp[pos*(w+1)+W]=res
	return res
print(f(0,w))

### FIXED CODE ###

ln = input()
n, cap = ln.split()
n = int(n)
cap = int(cap)

'''
weights = [[0 for x in range(2)] for y in range(n)] 
values = [[0 for x in range(2)] for y in range(n)] 
mat = [[0 for x in range(2)] for y in range(1000000)] 
'''
weights = [0 for x in range(n)] 
values =  [0 for x in range(n)] 
mat =  [0 for x in range(1000000)] 

for i in range(n):
    ln = input()
    ln = ln.split()
    weights[i] = int(ln[0])
    values[i] = int(ln[1])
 
for i in range(n):
    for j in range(cap,weights[i]-1,-1):
        '''
        print(j)
        print(values[i])
        print(mat[j-weights[i]])
        '''
        mat[j] = max(mat[j], mat[j-weights[i]] + values[i])
 
        
print(mat[cap])
### BUGGY CODE ###

import string
alp=string.ascii_lowercase
s=input()
k=int(input())
ans=''
i=0
while i<len(s)-1:
    t=s[i]
    d=(26-alp.index(t))%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
if k>0:
    ans+=alp[(alp.index(s[-1])+k%26)%26]
else:
    ans+=s[-1]
print(ans)

### FIXED CODE ###

#n,x=map(int,input().split())
#a=[int(i) for i in input().split()]
import string
alp=string.ascii_lowercase
di={}
for i in range(26):
    di[alp[i]]=i
s=input()
a=[]
for i in s:
    a.append(i)
l=a.pop()
if a:
    a=a[::-1]
k=int(input())
ans=''
i=0
while a:
    t=a.pop()
    d=(26-di[t])%26
    if d<=k:
        k-=d
        ans+='a'
    else:
        ans+=t
    i+=1
kk=k%26
ans+=alp[(alp.index(l)+kk)%26]
print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
min_num = 3 * 10**5
for i in range(0, n):
  if i == 0:
    temp = s[1:].count("E")
  elif i == n-1:
    temp = s[:-1].count("W")
  else:
    s_1 = s[:i-1].count("W")
    s_2 = s[i+1:].count("E")
    temp = s_1 + s_2
  if min_num > temp:
    min_num = temp
print(min_num) 

### FIXED CODE ###

n = int(input())
s = input()
list_num = []
for i in range(0, n):
  if i == 0:
    temp = s[1:].count("E")
    list_num.append(temp)
  else:
    temp = list_num[-1]
    if s[i] == "E":
      temp -= 1
    if s[i-1] == "W":
      temp += 1
    list_num.append(temp)
print(min(list_num))
### BUGGY CODE ###

N, Q = map(int, input().rstrip().split())
S = input()

count = [0 for i in range(len(S))]

list_lr = [map(int, input().rstrip().split()) for i in range(Q)]

for i in list_lr:
    l, r = i
    s = S[l-1:r]
    count = 0
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'C':
            count += 1

    print(count)


### FIXED CODE ###

N, Q = map(int, input().rstrip().split())
S = [i for i in input()]

list_lr = [list(map(int, input().rstrip().split())) for i in range(Q)]

t = [0]
ct = 0
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ct += 1
    t.append(ct)

for i in list_lr:
    l, r = i[0], i[1]
    print(t[r-1]-t[l-1])
### BUGGY CODE ###

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
for _ in range(M):
    B, C = map(int, input().split())
    for i in range(N):
        if A[i] >= C:
            A.sort()
            break
        else:
            A[i] = C
            B -= 1
        if B == 0:
            A.sort()
            break

print(sum(A))


### FIXED CODE ###

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()
BC = [0]*M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))

BC.sort(key=lambda x: x[1], reverse=True)

idx, flg = 0, 0
for i in BC:
    B, C = i
    for i in range(B):
        if idx > N-1:
            flg = 1
            break
        if A[idx] >= C:
            flg = 1
            break
        else:
            A[idx] = C
            idx += 1
            B -= 1
            if B == 0:
                break
    if flg:
        break

print(sum(A))