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

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
k = I()
if k%2 == 0:
    print(-1)
    exit()
a = ""
for i in range(20000):
    a += "7"
    if int(a)%k == 0:
        print(i+1)
        exit()
print(k-1)


### FIXED CODE ###

#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

k = I()
a = 7
if k%2 == 0:
    print(-1)
    exit()
for i in range(10**6):
    if a%k == 0:
        print(i+1)
        exit()
    a = (a*10 + 7)%k

print(-1)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, a: "List[int]", b: "List[int]"):
    conn = [[] for _ in range(N)]
    for i in range(N - 1):
        conn[a[i] - 1].append(b[i] - 1)
        conn[b[i] - 1].append(a[i] - 1)

    def find_path(idx, target, conn, visited):
        visited[idx] = True
        if idx == target:
            return [target]
        for nex in conn[idx]:
            if not visited[nex]:
                path = find_path(nex, target, conn, visited)
                if path is not None:
                    return [idx] + path
        return None

    visited = [False] * N
    path_to_n = find_path(0, N - 1, conn, visited)
    #print(path_to_n)

    colors = [None] * N
    for i, node in enumerate(path_to_n):
        if i < (len(path_to_n) + 1) // 2:
            colors[node] = 1
        else:
            colors[node] = 0

    def dfs(idx, conn, colors, visited):
        visited[idx] = True
        colors[idx] = 1
        for nex in conn[idx]:
            if not visited[nex] and (colors[nex] is None or colors[nex] == 1):
                dfs(nex, conn, colors, visited)
        return

    visited = [False] * N
    dfs(0, conn, colors, visited)
    #print(colors)

    cnt = 0
    for c in colors:
        if c == 1:
            cnt += 1
    if cnt > (N - cnt):
        ret = 'Fennec'
    else:
        ret = 'Snuke'
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, a: "List[int]", b: "List[int]"):
    conn = [[] for _ in range(N)]
    for i in range(N - 1):
        conn[a[i] - 1].append(b[i] - 1)
        conn[b[i] - 1].append(a[i] - 1)

    def dfs(idx, cur, conn, dis):
        dis[idx] = cur
        for nex in conn[idx]:
            if dis[nex] is None:
                dfs(nex, cur + 1, conn, dis)
        return None

    f_dis = [None] * N
    f_dis[0] = 0
    dfs(0, 0, conn, f_dis)

    s_dis = [None] * N
    s_dis[N - 1] = 0
    dfs(N - 1, 0, conn, s_dis)

    cnt = 0
    for i in range(N):
        if f_dis[i] <= s_dis[i]:
            cnt += 1

    if cnt > (N - cnt):
        ret = 'Fennec'
    else:
        ret = 'Snuke'
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)

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

class Doubling():
    def __init__(self,N,log_k,perm):
        """
        与えられた順列のダブリング配列を作成する.

        Parameters
        ----------
            N :  int
                順列の数
            log_k : int
                最大移動回数の対数(切り上げ)
            perm : [int]
                1-indexed の順列が格納されたリスト
        """
        self.N = N
        self.log_k = log_k
        self.doubling = [[0]*(self.N+1) for _ in range(log_k)]

        for i in range(1,self.N+1):
            self.doubling[0][i] = perm[i]

        for j in range(1,self.log_k):
            for i in range(1,self.N+1):
                prev = self.doubling[j-1][i]
                self.doubling[j][i] = self.doubling[j-1][prev]
        
    def query(self,pos,k):
        """
        位置iからk回移動したときの移動先を計算する.

        Parameters
        ----------
            pos : int
                移動元の位置
            k : int
                移動回数(1<=k<=2^(log_k+1)-1)

        Returns
        ----------
            dest : int
                移動先の位置
        """
        for i in range(self.log_k):
            if k & (1<<i) == 0:continue
            pos = self.doubling[i][pos]
        dest = pos
        
        return dest

def main():
    n,k = tuple([int(t)for t in input().split()])

    a = [int(t) for t in input().split()]

    a.insert(0,0)
    log_k = k.bit_length()+1

    doubling = Doubling(n,log_k,a)
    print(doubling.query(1,k))

    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n,k = tuple([int(t)for t in input().split()])

    a = tuple([int(t)-1 for t in input().split()])

    route = []
    se = set([])

    t = -1
    s = -1

    looplen = 0

    pos = 0
    for i in range(n):
        route.append(pos)
        se.add(pos)
        if a[pos] in se:
            t = len(route)
            s = route.index(a[pos])
            looplen = t-s
            break  
        pos = a[pos]

    if t>k:
        print(route[k]+1)
    else:
        pos = s+(k-s)%looplen
        print(route[pos]+1)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import Counter
from itertools import combinations as cmb

N = int(input())
S = input()
ans = 0
if N >= 3:    
    for idx in list(cmb(range(N), 3)):
        a,b,c = idx[0],idx[1],idx[2]
        if b-a != c-b and S[a] != S[b] and S[a] != S[c] and S[b] != S[c]:
            ans += 1

print(ans)

### FIXED CODE ###

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

if N<4:
    print(0)
else:
    a = [0] * N
    R, G, B = 0, 0, 0
    for i in range(N):
        if S[i] == "R":
            a[i] = 1
            R += 1
        if S[i] == "G":
            a[i] = 2
            G += 1
        if S[i] == "B":
            a[i] = 4
            B += 1

    rgb = R * G * B
    cnt = 0
    for i in range(N-2):
        for d in range(1, (N-i-1) // 2+1):
            if a[i] + a[i+d] + a[i+2*d] == 7:
                cnt += 1

    print(rgb -cnt)
### BUGGY CODE ###

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def give_p(G, v, p, P):
    P[v] = p
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue
        give_p(G, c, v, P)


def dfs(G, v, p, point, x):
    """G: graph, v: vertex, p: parent"""
    point[v] += x
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue
        dfs(G, c, v, point, x)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    # Give parent for each child
    P = [-1] * N
    give_p(G, 0, -1, P)

    point = [0] * N
    for i in range(Q):
        p, x = map(int, input().split())
        p -= 1
        dfs(G, p, P[p], point, x)

    print(" ".join(map(str, point)))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def dfs(G, v, p, point):
    """G: graph, v: vertex, p: parent"""
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue
        point[c] += point[v]
        dfs(G, c, v, point)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    point = [0] * N
    for i in range(Q):
        p, x = map(int, input().split())
        p -= 1
        point[p] += x

    dfs(G, 0, -1, point)
    print(" ".join(map(str, point)))


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

def n_gram(target,n):
    a = (int(target[idx:idx + n]) for idx in range(len(target) - n + 1))
    return tuple(a)

count = 0
s = input()
n = 4
num_list = ()
s_len = len(s)
while n <= s_len:
    num_list = num_list + n_gram(s,n)
    n += 1
for num in num_list:
    if num % 2019 == 0:
        count += 1
print(count)

### FIXED CODE ###

s = input()[::-1]

count = [0]*2019
count[0] = 1  # そもそもあまりが0ってことは2019の倍数確定なので

num, d = 0, 1  # 初期化

for char in s:
    num += int(char)*d
    num %= 2019
    d *= 10
    d %= 2019
    count[num] += 1  # 2019で割ったあまりをキーとして値を追加していく

ans = 0
for c in count:
    ans += c*(c-1)//2
print(ans)
### BUGGY CODE ###

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

a = [e for e in a if e < k]
n = len(a)

dp = [[False] * k for _ in range(n + 1)]
dp[0][0] = True
for i, e in enumerate(a, 1):
    for j in range(k):
        dp[i][j] = dp[i-1][j]

    for j in range(k - e):
        if dp[i-1][j]:
            dp[i][j+e] = True

dp2 = [[False] * k for _ in range(n + 1)]
dp2[0][0] = True
for i, e in enumerate(a[::-1], 1):
    for j in range(k):
        dp2[i][j] = dp2[i-1][j]

    for j in range(k - e):
        if dp2[i-1][j]:
            dp2[i][j+e] = True

ans = 0
for i, e in enumerate(a, 1):
    li = [j for j in range(k) if dp[i-1][j]]
    li2 = [j for j in range(k) if dp2[n-i][j]]

    j = len(li2) - 1
    mx = 0
    for e2 in li:
        while e2 + li2[j] >= k:
            j -= 1

        mx = max(mx, e2 + li2[j])

    if mx + e < k:
        ans += 1

print(ans)


### FIXED CODE ###

import numpy as np


def check(x):
    dp = np.zeros(k, np.bool)
    dp[0] = True
    for e in a[:x] + a[x+1:]:
        dp[e:] |= dp[:-e]

    return dp[-a[x]:].any()


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

a.sort()

lb = -1
ub = n
while ub - lb > 1:
    m = (lb + ub) // 2
    if check(m):
        ub = m
    else:
        lb = m

print(ub)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 10 ** 18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
if 0 in a:
    print(0)
else:
    for i in range(n):
        ans *= a[i]
        if ans > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)
### BUGGY CODE ###

import string, sys

alpha = 'abcdefghijklmnopqrstuvwxyza'
tbl = string.maketrans(alpha[:-1], alpha[1:])

for s in sys.stdin:
	while 'the' not in s or 'that' not in s or 'this' not in s:
		s = s.translate(tbl)
	print s

### FIXED CODE ###

import string, sys

alpha = 'abcdefghijklmnopqrstuvwxyza'
tbl = string.maketrans(alpha[:-1], alpha[1:])

for s in sys.stdin:
	while not('the' in s or 'that' in s or 'this' in s):
		s = s.translate(tbl)
	print s[:-1]
### BUGGY CODE ###

N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort()
def func(list1,num = 1):
    for i in range(len(list1)):
        wait = list1[i] - list1[0]
        if wait > K or i + 1 > C:
            return func(list1[i:],num + 1)
    return num
print(func(T))

### FIXED CODE ###

N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort()
num = 1
begin = 0
for j in range(100000):
    for i in range(begin + 1,N):
        wait = T[i] - T[begin]
        if wait > K or i - begin + 1> C:
            num += 1
            begin = i
            break
    else:
        break
print(num)
### BUGGY CODE ###

N, M = tuple(map(int, input().split()))
mod = 10**9+7
broken = []
dp = []

for i in range(M):
    broken.append(int(input()))

for i in range(N+2):
    dp.append(0)

dp[N] = 1

for i in reversed(range(N)):
    if (i in broken):
        continue
    dp[i] = (dp[i+1] + dp[i+2]) % mod

print(dp[0])

### FIXED CODE ###

N, M = map(int, input().split())
A = set(int(input()) for _ in range(M))
mod = 10 ** 9 + 7

dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    if i in A:
        continue
    if i == 1:
        dp[i] = 1
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= mod

print(dp[N] % mod)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from math import log2

ROUND = 10 ** 100

def main():
    S = input()
    N = len(S)
    to = []
    for _ in range(int(log2(ROUND))):
        l = [0] * N
        to.append(l)
    
    for i in range(N):
        to[0][i] = i + 1 if S[i] == "R" else i - 1
    
    for i in range(1, int(log2(ROUND))):
        for j in range(N):
            to[i][j] = to[i - 1][to[i - 1][j]]

    a = []
    for i in range(int(log2(ROUND))):
        if ROUND>>i & 1:
            a.append(i)

    ans = [0] * N
    for j in range(N):
        now = j
        for i in reversed(a):
            now = to[i][now]
        ans[now] += 1

    L = [str(i) for i in ans]
    print(" ".join(L))
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from itertools import groupby

# RUN LENGTH ENCODING
def rfe_tupple(S: str):
    grouped = groupby(S)
    res = []
    for k, v in grouped:
        res.append((k, str(len(list(v)))))
    return res

def main():
    S = input()
    N = len(S)
    
    now = 0
    compressed = rfe_tupple(S)
    ans = [0] * N
    for lr, i in compressed:
        i = int(i)
        if lr == "R":
            now += i
            ans[now - 1] += i - i // 2
            ans[now] += i // 2
        else:
            ans[now - 1] += i // 2
            ans[now] += i - i // 2
            now += i
    
    L = [str(i) for i in ans]
    print(" ".join(L))
    return

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

import math

K = int(input())

output = 0

for i in range(1,K+1):
	for j in range(1,K+1):
		for k in range(1,K+1):
			output += math.gcd(i,math.gcd(j,k))

print(output)



### FIXED CODE ###

import math
 
K = int(input())
 
output = 0
 
for i in range(1,K+1):
	for j in range(1,K+1):
		gcd_ij = math.gcd(i,j)
		for k in range(1,K+1):
			output += math.gcd(gcd_ij,k)
 
print(output)
### BUGGY CODE ###

n = int(input())
s = input()
sum = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if s[i] == s[j] or s[j] == s[k] or s[k] == s[i] or k-j == j-i:
                continue
            else:
                sum += 1

print(sum)


### FIXED CODE ###

n = int(input())
s = input()
sum = 0
r = 0
g = 0
b = 0

for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1
sum += r*g*b

for i in range(n):
    wi = (n-i+1)//2
    for w in range(1,wi):
        if s[i] == s[i+w] or s[i+w] == s[i+2*w] or s[i] == s[i+2*w]:
            continue
        else:
            sum -= 1

print(sum)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5 * 2)

N, Q = map(int, input().split())
V = {i: [] for i in range(1,N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1,N+1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)

propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1,N+1)))


### FIXED CODE ###

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

N, Q = map(int, input().split())
V = {i: [] for i in range(1,N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1,N+1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)

propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1,N+1)))
### BUGGY CODE ###

import math
def yn(a, f, k, x):
  k_yt = 0
  for i in range(len(a)):
    ki = max(0, a[i]-math.floor(x/f[i]))
    k_yt += ki
  if k_yt <= k:
    return True
  else:
    return False

n, k = map(int, input().split())
a = list((map(int, input().split())))
f = list((map(int, input().split())))
a.sort()
f.sort(reverse = True)
xo = max([a[i]*f[i] for i in range(len(a))])
# binary search
if xo == 0:
  print(0)
else:
  l = 0
  r = xo
  m = xo
  while l <= r:
    piv = int((r+l)/2)
    if yn(a, f, k, piv):
      r = piv - 1 
      m = piv
    else:
      l = piv +1
  print(m)
   
    



### FIXED CODE ###

import math
import numpy as np
def yn(a, f, k, x):
  k_yt = np.maximum(np.zeros(a.shape),a - np.floor(np.divide(x, f)))
  k_yt = np.sum(k_yt)
  if k_yt <= k:
    return True
  else:
    return False

n, k = map(int, input().split())
a = list((map(int, input().split())))
f = list((map(int, input().split())))
a.sort()
f.sort(reverse = True)
xo = max([a[i]*f[i] for i in range(n)])
a = np.array(a)
f = np.array(f)
# binary search
if xo == 0:
  print(0)
else:
  l = 0
  r = xo
  m = xo
  while l <= r:
    piv = int((r+l)/2)
    if yn(a, f, k, piv):
      r = piv - 1 
      m = piv
    else:
      l = piv +1
  print(m)
### BUGGY CODE ###

N,M=map(int,input().split())
List = []
for i in range (M):
  List.append(list(map(int, input().split())))
resList = [0]*N
for i in range(M):
  l = List[i][0]
  r = List[i][1]
  for j in range(l,r+1):
    resList[j-1] += 1
print(resList.count(M))

### FIXED CODE ###

N,M=map(int,input().split())
List = []
for i in range (M):
  List.append(list(map(int, input().split())))
resList = [0]*N
for i in range(M):
  resList[List[i][0]-1] +=1
  if List[i][1]<N:
    resList[List[i][1]] +=-1
for j in range(1,N):
  resList[j] = resList[j] + resList[j-1]
print(resList.count(M))
### BUGGY CODE ###

import math
sum=0
K=int(input())+1
for a in range(1,K):
  for b in range(1,K):
    for c in range(1,K):
      sum+=math.gcd(math.gcd(a,b),c)
print(sum)

### FIXED CODE ###

import math
sum=0
K=int(input())+1
for a in range(1,K):
  for b in range(1,K):
    ab=math.gcd(a,b)
    for c in range(1,K):
      sum+=math.gcd(ab,c)
print(sum)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
  b, c = map(int, input().split())
  if min(a) < c:
    a += [c] * b
    a.sort()
    a = a[-n:]
print(sum(a))

### FIXED CODE ###

from heapq import heappop, heappush

n, m = map(int, input().split())
a = list(map(int, input().split()))
q = []
for x in a:
  heappush(q, [-x, 1])
for i in range(m):
  b, c = map(int, input().split())
  heappush(q, [-c, b])
r = []
k = 0
while k < n:
  c, b = heappop(q)
  c = -c
  r += [c] * b
  k += b
print(sum(r[:n]))
### BUGGY CODE ###

def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf

n = int(input())
a = list(map(int,input().split()))
ans = 0
for j in a:
	targ = pfact(j)
	ans += targ.get(2, 0)
print(ans)

### FIXED CODE ###

def twos(m):
	rt = 0
	while m%2 == 0:
		m //= 2
		rt += 1
	return rt

n = int(input())
a = list(map(int,input().split()))
ans = 0
for j in a:
	ans += twos(j)
print(ans)
### BUGGY CODE ###

s=input()
c=0
tem=''
te=''
for tc in range(int(input())):
    q=input()
    if q=='1':
        s=s[::-1]
    else:
        q=q.split()
        if q[1]=='1':
            s=q[2]+s
        else:
            s+=q[2]
print(s)

### FIXED CODE ###

from collections import deque
S = deque(input())
N = int(input())
is_inversed = False
for i in range(N):
    Q = input()
    if Q[0] == '1':
        is_inversed = not (is_inversed)
    else:
        if (Q[2] == '1' and is_inversed) or (Q[2] == '2' and not (is_inversed)):
            S.append(Q[4])
        else:
            S.appendleft(Q[4])
if is_inversed:
    print(''.join(list(S)[::-1]))
else:
    print(''.join(S))
### BUGGY CODE ###

import numpy as np
def resolve():
    N = int(input())
    d = [int(i) for i in input().split()]
    d = np.array(d)
    count = 0
    for i in range(100000):
        if (np.where(d >= i)[0].size == np.where(d < i)[0].size):
            count += 1
    print(count)
resolve()

### FIXED CODE ###

import numpy as np
def resolve():
    N = int(input())
    d = [int(i) for i in input().split()]
    d = np.array(d)
    d = np.sort(d)
    print(d[N // 2] - d[N // 2 - 1])
resolve()
### BUGGY CODE ###

n = int(input())
s = list(map(str, input()))

a = []
for i in range(n):
    cnt = 0
    if "E" in s[i + 1 :]:
        cnt += s[i + 1 :].count("E")
    if "W" in s[:i]:
        cnt += s[:i].count("W")
    a.append(cnt)
print(min(a))


### FIXED CODE ###

n = int(input())
s = list(map(str, input()))
a = []
cnt = s.count("E")
s.insert(0, 0)
s.append(0)
for i in range(1, n + 1):
    if s[i - 1] == "W":
        cnt += 1
    if s[i] == "E" and cnt != 0:
        cnt -= 1
    a.append(cnt)
print(min(a))
### BUGGY CODE ###

import fractions
k = int(input())
cnt = 0
lists = []
for i in range(1,k+1):
    for j in range(1,k+1):
        lists.append(fractions.gcd(i,j))

for i in lists:
    for j in range(1,k+1):
        cnt += fractions.gcd(i,j)
print(cnt)


### FIXED CODE ###

from math import gcd
k = int(input())
cnt = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        tmp = gcd(i,j)
        for m in range(1,k+1):
            cnt += gcd(m,tmp)
print(cnt)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

S = input().rstrip()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]

ans = S
flag = True

for i in range(Q):
    if query[i][0] == '1':
        if flag:
            flag = False
        else:
            flag = True
        continue
    elif query[i][0] == '2':
        f = query[i][1]
        c = query[i][2].rstrip()
        if f == '1' and flag:
            ans = c + ans
        elif f == '1' and not flag:
            ans = ans + c
        elif f == '2' and flag:
            ans = ans + c
        elif f == '2' and not flag:
            ans = c + ans
if flag:
    print(ans)
else:
    print(ans[::-1])


### FIXED CODE ###

import sys
input = sys.stdin.readline

S = input().rstrip()
Q = int(input())
head = ''
tail = ''
rev = False

for _ in range(Q):
    query = list(input().split())
    if query[0] == '1':
        if rev:
            rev = False
        else:
            rev = True
    elif query[0] == '2':
        f = query[1]
        c = query[2].rstrip()
        if f == '1':
            if rev:
                tail = tail + c
            else:
                head = c + head
        else:
            if rev:
                head = c + head
            else:
                tail = tail + c
if rev:
    tmp = head + S + tail
    print(tmp[::-1])
else:
    print(head + S + tail)