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

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

DIV=10**9+7

def gcd(a,b):
  if a<b:
    a,b=b,a
  while a%b!=0:
    a,b=b,a%b
  return b

def lcd(a,b):
  return a*b//(gcd(a,b))

L=1
for i in range(N):
  L=lcd(L,A[i])

ans=0
for i in range(N):
  ans+=L//A[i]
  ans%=DIV

print(ans)


### FIXED CODE ###

import math
from fractions import gcd
from functools import reduce

DIV=10**9+7

def lcm(a,b):
  return a*b//(gcd(a,b))

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

ans=sum(list(map(lambda x:g//x,A)))
print(ans%DIV)
### BUGGY CODE ###

def main():
    S = input()
    a = {j: i for i, j in enumerate('abcdefghijklmnopqrstuvwxyz')}
    S = [a[i] for i in S]

    parity = 0
    dict_parity = {0: 0}

    for i, s in enumerate(S):
        parity ^= 2**s
        ans = i+1
        if parity in dict_parity:
            ans = min(ans, dict_parity[parity]+1)
        ans = min(
            [ans]+[dict_parity.get(parity ^ 2**j, ans)+1 for j in range(26)])
        dict_parity[parity] = min(ans, dict_parity.get(parity, ans))
    print(ans)


main()


### FIXED CODE ###

def main():
    S = input()
    n = len(S)
    a = {j: i for i, j in enumerate('abcdefghijklmnopqrstuvwxyz')}
    S = [a[i] for i in S]
    dp = [10**9]*(n+1)
    dp[0] = 0

    parity = 0
    dict_parity = {0: 0}

    for i, s in enumerate(S):
        parity ^= 2**s
        ans = i+1
        if parity not in dict_parity:
            dict_parity[parity] = i+1
        else:
            ans = min(ans, dp[dict_parity[parity]]+1)
        for j in range(26):
            parity2 = parity ^ 2**j
            if parity2 in dict_parity:
                ans = min(ans, dp[dict_parity[parity2]]+1)
        dp[i+1] = ans
        if dict_parity[parity] > ans:
            dict_parity[parity] = i+1
    print(dp[-1])


main()
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
  if a[i]>=n:
    continue
  for j in range(a[i]+1,n):
    if a[j]==j-a[i]-i:
      ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 0
d = {}
for i in range(n):
  if d.get(i+a[i],0)==0:
    d[i+a[i]] = [0,0]
  if d.get(i-a[i],0)==0:
    d[i-a[i]] = [0,0]
  d[i+a[i]][0] += 1
  d[i-a[i]][1] += 1
for v in d.values():
  ans += v[0]*v[1]
print(ans)
### BUGGY CODE ###

N, K  = map(int, input().split())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(1, N):
    for k in range(1, K+1):
        if i-k <0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i-k] + abs(h[i] - h[i-k])) 

print(dp[N - 1])

### FIXED CODE ###

N, K  = map(int, input().split())
h = [int(x) for x in input().split()]

inf = float('inf')
dp = [inf] * N

dp[0] = 0

def chmin(a, b):
    if a > b:
        return b
    else:
        return a

for i in range(1, N):
    for k in range(1, K+1):
        if i-k <0:
            break
        else:
            dp[i] = chmin(dp[i], dp[i-k] + abs(h[i] - h[i-k])) 

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

import numpy as np
n = int(input())
a = [int(i) for i in input().split()] 
ls = np.array(a)

st = int(n/2)
ans =  [i+st+1 for i, n in enumerate(a[st:]) if n ==1] 
for ind in range(st, 0, -1):
    tmp = list(range(2*ind-1, n, ind))
    s = ls[tmp].sum()%2
    if a[ind-1] == s:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        ans.append(ind)
        
print(sum(ls))
print(' '.join(map(str, ans)))

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()] 
ls = a

st = int(n/2)
ans =  [i+st+1 for i, n in enumerate(a[st:]) if n ==1] 
for ind in range(st, 0, -1):
    tmp = [ls[i] for i in range(2*ind-1, n, ind)]
    s = sum(tmp)%2
    if a[ind-1] == s:
        ls[ind-1] = 0
    else:
        ls[ind-1] = 1
        ans.append(ind)
        
print(sum(ls))
print(' '.join(map(str, ans)))
### BUGGY CODE ###

n=int(input())

l=[0 for i in range(n+1)]

for i in range(1,n+1):

    for j in range(1,n+1):

        if j*i<=n:
            l[i*j]+=1
s=0
for j in range(1,n+1):
    s+=j*l[j]
print(s)


### FIXED CODE ###

n=int(input())
#n=10000000
ksum=0
for k in range(1,n+1):
    m=n//k
    ksum+=k*m*(m+1)//2
    
print(ksum)
### BUGGY CODE ###

N = int(input())
A = [0] * (N)
for i in range(N):
	A[i] = int(input())

D=max(A)
for j in range(N):
	if A[j] != D:
		print(D)
	else:
		X = A.pop(j)
		print(max(A))
		A.insert(j,X)

### FIXED CODE ###

N = int(input())
A = [0] * (N)
for i in range(N):
	A[i] = int(input())

D=max(A)
C=sorted(A)[-2]
for j in range(N):
	if A[j] != D:
		print(D)
	else:
		print(C)
### BUGGY CODE ###

n, k, q = map(int, input().split())
a_list = [int(input()) for i in range(q)]

point_dic = []
for i in range(n):
    point_dic.append(k)

for a in a_list:
    # for i in range(n):
    #     if i+1 == a:
    #         pass
    #     else:
    #         point_dic[i+1] -= 1
    point_dic = list(map(lambda x: x-1, point_dic))
    point_dic[a-1] = point_dic[a-1] + 1


for point in point_dic:
    if point > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n, k, q = map(int, input().split())
a_list = [int(input()) for i in range(q)]

point_dic = []
for i in range(n):
    point_dic.append(k-q)

for a in a_list:
    point_dic[a-1] = point_dic[a-1] + 1


for point in point_dic:
    if point > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import heapq
def SME(start,end):
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in range(L):
        if ANS[i] : continue
        else : ANS[i] = min(Whole[:i+1])
    i = L
    while i < N :
        if ANS[i] : 
            i += 1
            continue
        else : 
            ANS[i] = min(Whole[i+1-L:i+1])
            if None not in ANS[i:i+L] :
                i += L
                continue
            i+=1
    return ANS
[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
A = []
parameter = 0.991
ANS = [None]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

from collections import Counter


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


A2 = list(set(A))
A2.sort()
basis = []

for a in A2:
    for b in basis:
        if a % b == 0:
            break
    else:
        basis.append(a)

ans = 0
c = Counter(A)
for b in basis:
    if c[b] == 1:
        ans += 1

print(ans)

### FIXED CODE ###

from collections import Counter

_ = int(input())
A = list(map(int, input().split()))
a_max = 10 ** 6

c = Counter(A)
b = list(set(A))
b.sort()

dp = [True] * (a_max + 1)
ans = 0
for a in b:
    if dp[a]:
        if c[a] == 1:
            ans += 1
        for i in range(2 * a, a_max + 1, a):
            dp[i] = False

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

def main():
    s = input()
    mod = 10 ** 9 + 7
    table1 = {i: 0 for i in range(13)}
    table2 = {i: 0 for i in range(13)}
    table1[0] = 1
    pre = {i: [((10 * i + j) % 13) for j in range(10)] for i in range(13)}

    for l in s:
        if l == '?':
            for i in range(13):
                q = table1[i]
                for k in pre[i]:
                    table2[k] += q % mod
        else:
            for i in range(13):
                q = table1[i]
                k = pre[i][int(l)]
                table2[k] += q % mod

        table1 = table2
        table2 = {i: 0 for i in range(13)}

    print(table1[5] % mod)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s = input()
    mod = 10 ** 9 + 7
    table1 = [0] * 13
    table2 = [0] * 13
    table1[0] = 1
    pre = [[((10 * i + j) % 13) for j in range(10)] for i in range(13)]

    for l in s:
        for i in range(13):
            q = table1[i] % mod
            if q == 0:
                continue
            if l == '?':
                for k in pre[i]:
                    table2[k] += q
            else:
                k = (10 * i + int(l)) % 13
                table2[k] += q

        table1 = table2
        table2 = [0] * 13

    print(table1[5] % mod)


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

from collections import Counter
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
B = list(set(A[:]))
dict = defaultdict(int)
for i in range(len(B)):
    dict[B[i]] = A.count(B[i])
count = 0
for k, v in dict.items():
    if k > v:
        count += v
    elif k < v:
        count += v-k
print(count)


### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(set(A[:]))
count = 0

B = Counter(A).most_common()
for k, v in B:

    if k < v:
        count += v-k
    elif k > v:
        count += v
print(count)
### BUGGY CODE ###

n = int(input())
sum = 0
for i in range(n):
    sum = sum + i;
print(sum)

### FIXED CODE ###

n = int(input())
print(n*(n-1)//2)
### BUGGY CODE ###

n= int(input())
s = input()
S = []
for i in s:
    S.append(i)
import itertools
A = []
for v in itertools.combinations(S, 3):
    a = int("".join(v))
    A.append(a)
print(len(set(A)))

### FIXED CODE ###

n = int(input())

s = input()

A = []
for i in range(10):
    A.append([])
for i in range(n):
    A[int(s[i])].append(i)

total = 0
for i in range(1000):
    a = "{0:03d}".format(i)
    B = []
    for j in a:
        B.append(int(j))
    c = -1
    check = 0
    for j in B:
        check = 0
        if len(A[j]) > 0:
            for k in A[j]:
                if k > c:
                    c = k
                    check = 1
                    break
        else:
            break
        if check == 0:
            break
    if check == 1:
        total += 1
print(total)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    P = tuple(map(float, input().split()))
    if K == 1:
        ans = (1 + max(P)) * 0.5
    else:
        pl = [(K + sum(P[i:i+K])) * 0.5 for i in range(N-K+1)]
        ans = max(pl)

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
E = list(map(lambda x: (int(x)+1)/2, input().split()))
E_cumsum = np.cumsum(E)

ans = E_cumsum[K-1]
for i in range(0, N-K):
    e = E_cumsum[i+K] - E_cumsum[i]
    ans = max(ans, e)
print(ans)
### BUGGY CODE ###

from sys import stdin
from collections import Counter
n,W = map(int,stdin.readline().split())
dp = Counter({0:0})
for _ in range(n):
    w,v = map(int,stdin.readline().split())
    r = dp.copy()
    for i in r:
        if i+w <= W:
            dp[i+w] = max(r[i+w],r[i]+v)
print(dp[max(dp,key=dp.get)])

### FIXED CODE ###

from sys import stdin
from math import inf
n,W = map(int,stdin.readline().split())
dp = [inf]*(1000*n)
for _ in range(n):
    w,v = map(int,stdin.readline().split())
    for i in range(1000*n-v-1,-1,-1):
        if dp[i] and dp[i]+w <= W:
            dp[i+v] = min(dp[i+v],dp[i]+w)
    dp[v-1] = min(dp[v-1],w)
for i in range(len(dp)-1,-1,-1):
    if dp[i] != inf:
        print(i+1)
        break
### BUGGY CODE ###

import numpy as np

N = int(input())
As = list(map(int, input().split()))
Q = int(input())
BCs = [list(map(int, input().split())) for _ in range(Q)]

#rint(BCs)

ansArray = np.zeros(10**5 + 1, dtype = int)
indexArray = np.array(range(10**5+1))

for A in As:
    ansArray[A] += 1

#print(ansArray)
#print(indexArray)

for BC in BCs:
    B = BC[0]
    C = BC[1]

    tmp = ansArray[B]
    ansArray[B] = 0
    ansArray[C] += tmp

    print(np.dot(ansArray, indexArray))



### FIXED CODE ###

import numpy as np

N = int(input())
As = list(map(int, input().split()))
Q = int(input())
BCs = [list(map(int, input().split())) for _ in range(Q)]

#rint(BCs)

ansArray = np.zeros(10**5 + 1, dtype = int)
indexArray = np.array(range(10**5+1))

for A in As:
    ansArray[A] += 1

#print(ansArray)
#print(indexArray)
ans = np.dot(ansArray, indexArray)

for BC in BCs:

    ans = ans + (BC[1] - BC[0]) * ansArray[BC[0]]
    print(ans)
    ansArray[BC[1]] += ansArray[BC[0]]
    ansArray[BC[0]] = 0
### BUGGY CODE ###

import sys
input=sys.stdin.readline

h,w=map(int,input().split())
S=[["#"]+list(input())+["#"] for _ in range(h)]
S.insert(0,["#"]*(w+2))
S.append(["#"]*(w+2))

C=[[[0]*4 for _ in range(w+2)] for _ in range(h+2)]
for i in range(1,h+1):
    for n, flag in enumerate((1, -1)):
        for j in range(1,w+1)[::flag]:
            if S[i][j]!="#":C[i][j][n] +=C[i][j-flag][n]+1
for i in range(1,w+1):
    for n, flag in enumerate((1, -1)):
        for j in range(1,h+1)[::flag]:
            if S[j][i]!="#":C[j][i][n+2] +=C[j-flag][i][n+2]+1

print(max([sum(C[i][j])-3 for i in range(1,h+1) for j in range(1,w+1)]))

### FIXED CODE ###

import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w),dtype=np.int64) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(int(np.max(left+right+up+down)-3))
### BUGGY CODE ###

k,n=map(int,input().split())
l1=list(map(int,input().split()))
l2 = [x+k for x in l1]
l=l1+l2
ans=[]
for i in range(n):
    tmpList=[x-l[i] for x in l[i+1:i+n]]
    ans.append(max(tmpList))
print (min(ans))

### FIXED CODE ###

k,n,*a=map(int,open(0).read().split())
a+=[k+a[0]]
print(k-max(y-x for x,y in zip(a,a[1:])))
### BUGGY CODE ###

N = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(1,max(d) + 1):
    if sum(x > i for x in d) == N//2:
        ans += 1
    else:
        pass
print(ans)

### FIXED CODE ###

N = int(input())
d = sorted(list(map(int, input().split())))

print(d[N//2] - d[N//2 - 1])
### BUGGY CODE ###


H, W = map(int, input().split())
edges = [["#" for i in range(W+2)]] + [["#"] + [None for i in range(W)] + ["#"] for j in range(H)] + [["#" for i in range(W+2)]]
from collections import deque

for i in range(1, H+1):
  S = input()
  for j in range(1, W+1):
    edges[i][j] = S[j-1]

def dfs(x, y):
  if edges[y][x] == "#":
    return []

  flag = [[False for i in range(W+2)] for j in range(H+2)]
  flag[y][x] = True

  for next in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
    a, b = next
    while edges[b][a] == ".":
      flag[b][a] = True
      if x - a > 0:
        a -= 1
      elif x - a < 0:
        a += 1
      elif y - b > 0:
        b -= 1
      elif y - b < 0:
        b += 1
  
  return flag

ans = -1
for h in range(1, H+1):
  for w in range(1, W+1):
    flag = dfs(w, h)
    
    tmp = 0
    for x in flag:
      for y in x:
        if y:
          tmp += 1
    
    ans = max(ans, tmp)

print(ans)

### FIXED CODE ###


H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

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

X, Y, Z, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
ans = [A[i]+B[j]+C[k] for k in range(Z) for j in range(Y) for i in range(X) if (i+1)*(j+1)*(k+1) <= K]
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
t =[]
for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k) <= K:
                t.append(A[i]+B[j]+C[k])
            else:break
t.sort(reverse=True)
for i in range(K):
    print(t[i])
### BUGGY CODE ###

def solve():
    k, a = read()
    result = think(k, a)
    write(result)


def read():
    n, k = read_int(2)
    a = read_int(n)
    return k, a


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(k, a):
    max_n = 100
    max_k = 10 ** 5

    # dp[i] = True/False; True means First player win if num of stone is i
    dp = [False] * (max_n * max_k + 1)

    for i in range(len(dp)):
        for elem in a:
            if i >= elem:
                dp[i] |= not dp[i - elem]

    return dp[k]


def write(result):
    if result:
        print('First')
    else:
        print('Second')


if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    k, a = read()
    result = think(k, a)
    write(result)


def read():
    n, k = read_int(2)
    a = read_int(n)
    return k, a


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(k, a):
    max_n = 100

    # dp[i] = True/False; True means First player win if num of stone is i
    dp = [False] * (k + max_n + 1)

    for i in range(len(dp)):
        for elem in a:
            if i >= elem:
                dp[i] |= not dp[i - elem]

    return dp[k]


def write(result):
    if result:
        print('First')
    else:
        print('Second')


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

x,n = map(int, input().split())
p = list(map(int, input().split()))

up = x
down = x
ans = 0
while ans == 0:
    for i in range(n + 1):
        if p.count(down) == 0:
            ans = down
            break
        elif p.count(up) == 0:
            ans = up
            break
        else:
            up += 1
            down -= 1

print(ans)

### FIXED CODE ###

x,n = map(int, input().split())
p = list(map(int, input().split()))

up = x
down = x
ans = 0

while ans == 0:
    if p.count(down) == 0:
        ans = down
        break
    elif p.count(up) == 0:
        ans = up
        break
    else:
        up += 1
        down -= 1

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

N = int(input())
A = list(map(int,input().split()))
#from collections import deque

ANS = []
for i in range(1,N+1):
  ANS.append(A.index(i)+1)
  
print(*ANS)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
#from collections import deque

ANS = [0]*N
for i,j in enumerate(A):
  ANS[j-1] = i+1
  
print(*ANS)
### BUGGY CODE ###

N = int(input())
power = 1
for i in range(1,N+1):
  power *= i
answer = power % (10**9 +7)
print(answer)

### FIXED CODE ###

N = int(input())
answer = 1
for i in range(1,N+1):
  answer = answer*i%(10**9+7)
print(answer)
### BUGGY CODE ###

#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
S = input()
ans = []
for i in range(N+1):
    ans.append(S[0:i].count('W') + S[i + 1:N + 1].count('E'))
print(str(min(ans)))


### FIXED CODE ###

#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
S = input()
ans = S[1:N].count('E')
tmp = ans
for i in range(N-1):
    if S[i] == 'W':
        tmp += 1
    if S[i + 1] == 'E':
        tmp -= 1
    ans = min(tmp, ans)
print(str(ans))
### BUGGY CODE ###

A, B, K = map(int, input().split())
while A > 0 and K > 0:
    A -= 1
    K -= 1
while B > 0 and K > 0:
    B -= 1
    K -= 1
print(str(A) + ' ' + str(B))

### FIXED CODE ###

A, B, K = map(int, input().split())
a = max(0, A-K)
K = max(0, K-A)
b = max(0, B-K)
print(str(a) + ' ' + str(b))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
dic = {"a":[],"b":[],"c":[],"d":[],"e":[],"f":[],"g":[],"h":[],"i":[],"j":[],"k":[],"l":[],"m":[],"n":[],"o":[],"p":[],"q":[],"r":[],"s":[],"t":[],"u":[],"v":[],"w":[],"x":[],"y":[],"z":[]}
for i,c in enumerate(s):
    dic[c] += [i]
#print(dic)
cnt = 0
ind = -1
ans = 0
for c in t:
    d = dic[c]
#    print("c=",c,"d=",d)
    for i in d: #iは各文字のindex 昇順
#        print("i=",i)
        if ind < i: #もし現在位置<iなら
            ind = i
#            print("found, ind=",i)
            break
    else:
#        print("not found")
        cnt += 1
        if d:
            ind = d[0]
        else:
#            print("!!!!!!!!!!!!!")
            ans = -1
            break
print(cnt*len(s)+ind+1 if ans > -1 else -1)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect

s = input().rstrip()
t = input().rstrip()
d = defaultdict(list)

for i,c in enumerate(s):
    d[c].append(i)
ans = 0
ind = -1
for c in t:
    #print("c=",c,"d[c]=",d[c])
    if not d[c]:
        ans = -1
        break
    ins = bisect.bisect_left(d[c],ind+1)
    if ins < len(d[c]):
        ind =d[c][ins]
     #   print("ins=",ins,end = "")
    else:
      #  print("追加",end = "")
        ans += len(s)
        ind = d[c][0]
    #print("ind=", ind)
    #print()
else:
    ans += ind+1

print(ans)