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

import numpy as np
N, K ,Q = map(int, input().split())
participant = np.full(N, K)
As = []
for i in range(Q):
    answer = int(input())
    participant[answer-1] +=1
    participant -= 1
for surviver in np.where(participant>0, "Yes", "No"):
    print(surviver)



### FIXED CODE ###

import numpy as np
N, K ,Q = map(int, input().split())
participant = np.full(N, K)
As = []
for i in range(Q):
    answer = int(input())
    participant[answer-1] +=1
participant -= Q
for surviver in np.where(participant>0, "Yes", "No"):
    print(surviver)
### BUGGY CODE ###

n=int(input())
l=[]
for _ in range(n):
    l.append(int(input()))
for i in range(n):
    a=l.pop(i)
    print(max(l))
    l.insert(i,a)

### FIXED CODE ###

n=int(input())
l=[]
mx=-1
s=1
for _ in range(n):
    x=int(input())
    l.append(x)
    if x==mx:
        s+=1
    elif x>mx:
        mx=x
        s=1
if s>1:
    for _ in range(n):
        print(mx)
else:
    j=l.index(mx)
    for i in range(n):
        if i!=j:
            print(mx)
        else:
            l.remove(mx)
            print(max(l))
### BUGGY CODE ###

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

ans1=0
s=0
for i in range(1,N+1):
    a=A.count(i)
    C.append(a)
for j in range(N):
    c=C[j]
    if c>1:
        s=c*(c-1)/2
        ans1=ans1+s
        
for k in range(N):
    b=A[k]-1
    d=C[b]
    if d<2:
        ans=ans1
    else:
        ans=ans1-(d-1)
    print(int(ans))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
C=[0]*(N+1)

ans1=0
s=0

for A_i in A:
    C[A_i]+=1

for j in range(1,N+1):
    c=C[j]
    if c>1:
        s=c*(c-1)/2
        ans1=ans1+s
        
for A_k in A:
    d=C[A_k]
    if d<2:
        ans=ans1
    else:
        ans=ans1-(d-1)
    print(int(ans))
### BUGGY CODE ###

#coding: UTF-8
N=int(input())
p=[int(input()) for i in range(0,N)]
out=p[1]-p[0]
for i in range(0,N-1):
    buy=p[i]
    sell=p[i+1]
    for j in range(i+2,N):
        if p[j]>sell:
            sell=p[j]
    if sell-buy>out:
        out=sell-buy
print(out)

### FIXED CODE ###

#coding: UTF-8
N=int(input())
p=[int(input()) for i in range(0,N)]
maxv=p[1]-p[0]
buy=p[0]
for i in range(1,N):
    if p[i]-buy>maxv:
        maxv=p[i]-buy
    if p[i]<buy:
        buy=p[i]
print(maxv)
### BUGGY CODE ###

import bisect

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

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
for i in range(n):
    num_b[i] = bisect.bisect_left(a, b[i])

ans = 0
for i in range(n):
    ans += sum(num_b[:bisect.bisect_left(b, c[i])])

print(ans)


### FIXED CODE ###

import bisect

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

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
temp_sum = 0
for i in range(n):
    while b[j] < c[i]:
        temp_sum += num_b[j]
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += temp_sum

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

mod = 10**9+7
n,m = map(int,input().split())
a = [0]*m
for i in range(m):
    a[i] = int(input())
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1) :
    dp[i] = (dp[i-1] + dp[i-2]) % mod
    if i in a :
        dp[i] = 0
print(dp[-1])

### FIXED CODE ###

mod = 10**9+7
n,m = map(int,input().split())
a = set()
for i in range(m):
    a.add(int(input()))
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1) :
    dp[i] = (dp[i-1] + dp[i-2]) % mod
    if i in a :
        dp[i] = 0
print(dp[n])
### BUGGY CODE ###

import sys

l = raw_input().split()
N = int(l[0])
Q = int(l[1])
l = raw_input().split()
S = l[0]

L = [0]*Q
R = [0]*Q

ac = 'AC'

for i in range(Q):
    l = raw_input().split()
    L[i] = int(l[0])
    R[i] = int(l[1])

#print(N,Q,S,L,R)

def count(S):
    length = len(S)
    c = 0
    for i in range(length - 1):
        # print(S[i:i+2])
        if ac == S[i:i+2]:
            c += 1
    return c

for i in range(Q):
    p = S[L[i]-1:R[i]]
    # print(p)
    print(count(p))


### FIXED CODE ###

import sys

l = raw_input().split()
N = int(l[0])
Q = int(l[1])
l = raw_input().split()
S = l[0]

L = [0]*Q
R = [0]*Q

ac = 'AC'

for i in range(Q):
    l = raw_input().split()
    L[i] = int(l[0])
    R[i] = int(l[1])

#print(N,Q,S,L,R)

def count(S, table):
    length = len(S)
    c = 0
    for i in range(length - 1):
        # print(S[i:i+2])
        if ac == S[length - i - 2:length - i]:
            c += 1
        table[i+1] = c

length_S = len(S)
table = [0]*length_S

count(S, table)
# print(table)

for i in range(Q):
    print(table[length_S - L[i]] - table[length_S - R[i]])
### BUGGY CODE ###

import math

v = int(input())
sum = 0

for i in range(v):
    i += 1
    for j in range(v):
        j += 1
        for k in range(v):
            k += 1
            if i == 1 or j == 1 or k == 1:
                sum += 1
            else:
                sum += math.gcd(math.gcd(i, j), k)

print(sum)

### FIXED CODE ###

from math import gcd

v = int(input())
sum = 0

for i in range(1, v + 1):
    for j in range(1, v + 1):
        for k in range(1, v + 1):
            sum += gcd(gcd(i, j), k)

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

from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
pab = [(i, k[0], k[1]) for i, k in enumerate(sorted(ab, key=lambda x: (-x[1], x[0])))]
hq = []
result = 0
for i in range(1, m + 1):
    for j in [k for k in pab if k[1] == i]:
        heappush(hq, j)
    if hq:
        result += heappop(hq)[2]
print(result)

### FIXED CODE ###

from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)
### BUGGY CODE ###

from itertools import permutations 
inf=float('inf')
n, m, r = map(int, input().split())
r=list(map(int, input().split()))
abc=[list(map(int, input().split())) for _ in range(m)]
d=[[inf]*n for i in range(n)]
for i in range(n):
    d[i][i]=0
for ai, bi, ci in abc:
    d[ai-1][bi-1]=ci
    d[bi-1][ai-1]=ci
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j]=min(d[i][j], d[i][k]+d[k][j])
p=list(permutations(r))
print(min(sum(d[pi[i]-1][pi[i+1]-1] for i in range(len(r)-1)) for pi in p))


### FIXED CODE ###

from itertools import permutations
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
E = [list(map(int, input().split())) for _ in range(M)]
INF = 10 ** 9
d = [[INF for j in range(N)] for i in range(N)]
for i, j, c in E:
    d[i - 1][j - 1] = c
    d[j - 1][i - 1] = c
for k in range(N):
    for i in range(N - 1):
        for j in range(i, N):
            dk = d[i][k] + d[k][j]
            if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
ans = 10 ** 9
for ri in permutations(r):
    x = 0
    for i in range(R - 1):
        x += d[ri[i] - 1][ri[i + 1] - 1]
    if ans > x:
        ans = x
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
for a in A:
    if a==A_max:
        print(sorted(A)[-2])
    else:
        print(A_max)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = [int(input()) for _ in range(N)]
A_max = max(A)
A_max2 = sorted(A)[-2]
for a in A:
    if a==A_max:
        print(A_max2)
    else:
        print(A_max)
### BUGGY CODE ###

A, B, K = map(int, input().split())
for i in range(A, B+1):
    if A <= i < A + K or B - K < i <= B:
        print(i)

### FIXED CODE ###

A, B, K = map(int, input().split())

if B - A + 1 < 2 * K:
    for i in range(A, B+1):
        print(i)
else:
    for i in range(A, A+K):
        print(i)
    for i in range(B-K+1, B+1):
        print(i)
### BUGGY CODE ###

a=list(map(int,input().split()))
b=[]
c=[1]*(a[0]-1)
for i in range(a[1]):
  b.append(list(map(int,input().split())))
b=sorted(b,key=lambda b:b[1])
for i in range(a[1]):
  if i!=0 and b[i-1][0]>b[i][0]:
    continue
  if 0 in c[(b[i][0]-1):b[i][1]]:
    continue
  else:
    c[(b[i][1])-2]=0

print(c.count(0))

### FIXED CODE ###

a=list(map(int,input().split()))
b=[]
c=0
r=0
for i in range(a[1]):
  b.append(list(map(int,input().split())))
b=sorted(b,key=lambda b:b[1])

for i in range(a[1]):
  if b[i][0]<=r:
    continue
  else:
    c=c+1
    r=b[i][1]-1

print(c)
### BUGGY CODE ###

K=input()
D=int(input())
mod=10**9+7

L=len(K)

DP=[0]*D#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数
LIMIT=[]

for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        LIMIT=j%D
    else:
        DP[j%D]+=1

for ketanum in K[1:]:
    NDP=[0]*D

    for i in range(D):
        for j in range(10):
            NDP[(i+j)%D]=(NDP[(i+j)%D]+DP[i])%mod

    for j in range(int(ketanum)):
        NDP[(LIMIT+j)%D]+=1

    LIMIT=(LIMIT+int(ketanum))%D

    DP=NDP

print((DP[0]-1+ (LIMIT==0) )%mod)


### FIXED CODE ###

K=input()
D=int(input())
mod=10**9+7

L=len(K)

DP=[0]*D#DP[num][limit]で,一つ前の桁について,「桁和,そこまでKと一致していれば1」の場合の数
LIMIT=[]

for j in range(10):
    if j>int(K[0]):
        continue
    if j==int(K[0]):
        LIMIT=j%D
    else:
        DP[j%D]+=1

for ketanum in K[1:]:
    NDP=[0]*D

    for i in range(D):
        for j in range(10):
            NDP[(i+j)%D]=(NDP[(i+j)%D]+DP[i])%mod

    for j in range(int(ketanum)):
        NDP[(LIMIT+j)%D]+=1

    LIMIT=(LIMIT+int(ketanum))%D

    DP=NDP

print((DP[0]-1+ (LIMIT==0) )%mod)
### BUGGY CODE ###

s = input()
t = input()

ss = len(s)
tt = len(t)

dp = [['' for _ in range(tt)] for __ in range(ss)]

if s[0] == t[0]:
    dp[0][0] = s[0]

for i in range(1,ss):
    if s[i] == t[0]:
        dp[i][0] = t[0]
    else:
        dp[i][0] = dp[i-1][0]

for j in range(1,tt):
    if s[0] == t[j]:
        dp[0][j] = s[0]
    else:
        dp[0][j] = dp[0][j-1]

for i in range(1, ss):
    for j in range(1, tt):
        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1] + s[i]
            if len(dp[i][j]) < len(dp[i][j-1]):
                dp[i][j] = dp[i][j-1]
            if len(dp[i][j]) < len(dp[i-1][j]):
                dp[i][j] = dp[i-1][j]
        else:
            if len(dp[i][j-1]) < len(dp[i-1][j]):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = dp[i][j-1]

print(dp[ss-1][tt-1])


### FIXED CODE ###

s = input()
t = input()

ss = len(s)
tt = len(t)

dp = [[0 for _ in range(tt+1)] for __ in range(ss+1)]

for i in range(1, ss+1):
    for j in range(1, tt+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = max(dp[i-1][j-1] + 1, dp[i][j-1], dp[i-1][j])
        else:
            dp[i][j] = max(dp[i][j-1],dp[i-1][j])

i = ss
j = tt
ans = []

while i>0 and j>0:
    if s[i-1] == t[j-1]:
        ans.append(s[i-1])
        i -= 1
        j -= 1
    else:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        else:
            j -= 1

print(''.join(reversed(ans)))
### BUGGY CODE ###

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


### FIXED CODE ###

import sys
N = int(input())
num = list(map(int,input().split()))
num.sort(reverse=True)
a = 1
if num[-1] == 0:
  print(0)
else:
  for n in range(N):
    a = num[n]*a
    if a> 10**18:
      print(-1)
      sys.exit()
  print(a)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
h = np.array(input().split(), dtype='int')
bad_tower = np.zeros((), dtype='int')

for i in range(m):
    a, b = map(int, input().split())
    ha = h[a-1]
    hb = h[b-1]

    if ha > hb:
        bad_tower = np.append(bad_tower, b)
    elif ha < hb:
        bad_tower = np.append(bad_tower, a)
    elif ha == hb:
        bad_tower = np.append(bad_tower, a)
        bad_tower = np.append(bad_tower, b)

bad_tower = np.unique(bad_tower)

ans = n - len(bad_tower) + 1

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np

n, m = map(int, input().split())
h = np.array(input().split(), dtype='int')
bad_tower = np.zeros((n), dtype='int')

for i in range(m):
    a, b = map(int, input().split())
    ha = h[a-1]
    hb = h[b-1]

    if ha > hb:
        bad_tower[b-1] = 1
    elif ha < hb:
        bad_tower[a-1] = 1
    elif ha == hb:
        bad_tower[a-1] = 1
        bad_tower[b-1] = 1

ans = n - np.sum(bad_tower)

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

import math
from collections import Counter
def ip():return int(input())
def imp():return map(int,input().split())
def impstr():return map(str,input().split())
def limp():return list(map(int,input().split()))
def limpstr():return list(map(str,input().split()))
def prime(x):
    for i in range(2,int(math.sqrt(x))+1):
        if x%i==0:return False
    return True


n=ip()
l=limp()
if 1 in l:
    if l.count(1)==1:print(1)
    else:print(0)
    exit()
else:
    l.sort()
    c=Counter(l)
    ans=0
    for k,v in c.items():
        if v>1:continue
        elif prime(k)==True:ans+=1
        else:
            f=True
            for i in range(l.index(k)):
                if k%l[i]==0:
                    f=False
                    break
            if f==True:ans+=1
    print(ans)



### FIXED CODE ###

import math
from collections import Counter
def ip():return int(input())
def imp():return map(int,input().split())
def impstr():return map(str,input().split())
def limp():return list(map(int,input().split()))
def limpstr():return list(map(str,input().split()))

n=ip()
l=limp()
if 1 in l:
    if l.count(1)==1:print(1)
    else:print(0)
    exit()
else:
    mark=[0]*(10**6+5)
    for x in l:
        if mark[x]>=1:   #X已经出现了一次
            mark[x]=2
            continue
        mark[x]=1
        i=2
        while x*i<10**6+1:
            mark[x*i]=2
            i+=1
    ans=0
    for x in l:
        if mark[x]==1:ans+=1
    print(ans)
### BUGGY CODE ###

n=int(input())
b=[0]
for i in range(n):
    b.append(int(input()))
x=1
r=[1]
while 1:
    i=b[x]
    if i==2:
        print(len(r))
        break
    elif i in r:
        print(-1)
        break
    x=i
    r.append(i)

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):a.append(int(input()))
x=1
for i in range(n):
    x=a[x-1]
    if x==2:
        print(i+1)
        break
else:print(-1)
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()][:N]

mod = 10**9 + 7

WA = [sum(A[:n+1])%mod for n in range(N)]

total = 0
for i in range(N-1):
    total += A[i] * (WA[N-1]-WA[i]) % mod

print(total%mod)

### FIXED CODE ###

mod = 10**9 + 7
  
N = int(input())
A = [int(i)%mod for i in input().split()][:N]

wa = sum(A)

total = 0
for n in range(N-1):
    wa -= A[n]

    total += A[n] * wa
    total %= mod

print(total)
### BUGGY CODE ###

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

ans = 0
for ai in A:
    if ai % 2 == 0:
        while ai != 1:
            ai /= 2
            ans += 1
print(ans)

### FIXED CODE ###

from collections import defaultdict

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

m = defaultdict(int)

ans = 0
for ai in A:
    if ai % 2 == 0:
        while ai % 2 == 0:
            ai //= 2
            ans += 1
print(ans)
### BUGGY CODE ###

import heapq
N,Q=map(int,input().split())

event_list=[]
for i in range(N):
  S,T,X=map(int,input().split())
  event_list.append((S-X-0.5,1,X))
  event_list.append((T-X-0.5,-1,X))
  
dlist=[]
for i in range(Q):
  D=int(input())
  event_list.append((D,0,X))  
  dlist.append(D)
event_list.sort()
#print(event_list)

answer_dic={}
stop_set=set()
min_set=10**9
for t,f,x in event_list:
  if f==1:
    stop_set.add(x)
    if x<min_set:
      min_set=x
  elif f==-1:
    stop_set.remove(x)
    if x==min_set:
      if len(stop_set)>0:
        min_set=min(stop_set)
      else:
        min_set=10**9
  else:
    if len(stop_set)>0:
      answer_dic[t]=min_set
    else:
      answer_dic[t]=-1
#print(answer_dic)

for d in dlist:
  print(answer_dic[d])

### FIXED CODE ###

import heapq
import sys
input=sys.stdin.readline
N,Q=map(int,input().split())

event_list=[]
for i in range(N):
  S,T,X=map(int,input().split())
  event_list.append((S-X-0.5,1,X))
  event_list.append((T-X-0.5,-1,X))
  
dlist=[]
for i in range(Q):
  D=int(input())
  event_list.append((D,0,X))  
  dlist.append(D)
event_list.sort()
#print(event_list)

answer_dic={}
stop_set=set()
min_set=float("inf")
for t,f,x in event_list:
  if f==1:
    stop_set.add(x)
    if x<min_set:
      min_set=x
  elif f==-1:
    stop_set.remove(x)
    if x==min_set:
      if len(stop_set)>0:
        min_set=min(stop_set)
      else:
        min_set=float("inf")
  else:
    if len(stop_set)>0:
      answer_dic[t]=min_set
    else:
      answer_dic[t]=-1
#print(answer_dic)

for d in dlist:
  print(answer_dic[d])
### BUGGY CODE ###

N=int(input())
S=list(map(int,input().split( )))
tri=[]
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            a = [S[i],S[j],S[k]]
            a = sorted(a)
            if a[0] + a[1] > a[2]:
                tri.append(a)

for i in range(len(tri)):
    n=0
    for j in range(i+1,len(tri)):
        if tri[i] == tri[j-n]:
            tri.pop(j-n)
            n=n+1


print(len(tri))

### FIXED CODE ###

N=int(input())
S=list(map(int,input().split( )))
S = sorted(S)
tri_num=0
for i in range(N-2):
    k = i+2
    for j in range(i+1,N-1):
        while k < N:
            if S[i] + S[j] <= S[k]:
                tri_num = tri_num + k-j-1
                if k == i+2:
                    k+=1
                break
            if k == N-1:
                tri_num = tri_num + k-j
                break
            k+=1
print(tri_num)
### BUGGY CODE ###

s=input()
ls=len(s)
while "01" in s or "10" in s:s=s.replace("01","").replace("10","")
print(ls-len(s))

### FIXED CODE ###

s=input()
print(min(s.count("0"),s.count("1"))*2)
### BUGGY CODE ###



n=int(input())

list=[int(input()) for i in range(n)]

max=list[1]-list[0]


for i in range(n-1,-1,-1):
	for j in range(i):
		x=list[i]-list[j]
		if x>max:
			max=x

		
print(max)



### FIXED CODE ###


n=int(input())
a=[int(input()) for i in range(n)]
min1=a[0]
max1=-float('inf')
for i in range(1, n):
    max1=max(a[i]-min1,max1)
    min1=min(a[i],min1)
print(max1)
### BUGGY CODE ###

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

min_num = 300000
for i in range(n):
    min_num = min(s[:i].count("W") + s[i+1:].count("E"), min_num)
print(min_num)

### FIXED CODE ###

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

min_num = 300000
w_west = 0
e_east = s.count("E")
for s_i in s:
    if s_i == "E":
        e_east -= 1
    else:
        w_west += 1
    tmp = w_west + e_east - bool(s_i == "W")
    if tmp < min_num:
        min_num = tmp
print(min_num)
### BUGGY CODE ###

n, m = map(int, input().split())
a = [input().split() for _ in range(m)]
A = set()
B = set()

for i in range(m):
    if a[i][0] == "1":
        A.add(a[i][1])
    if a[i][1] == str(n):
        B.add(a[i][0])
    if A & B:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")


### FIXED CODE ###

n, m = map(int, input().split())
a = [input().split() for _ in range(m)]
A = []
B = []

for i in range(m):
    if a[i][0] == "1":
        A.append(a[i][1])
    if a[i][1] == str(n):
        B.append(a[i][0])
print("POSSIBLE" if set(A) & set(B) else "IMPOSSIBLE")
### BUGGY CODE ###

def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = list(map(lambda x: x, inputs[0]))
    N = len(persons)
    counts = []
    for leader, _ in enumerate(persons):
        count = 0
        for p in range(0, leader):
            if persons[p] == "W":
                count += 1
        for p in range(leader + 1, N):
            if persons[p] == "E":
                count += 1
        counts.append(count)
    min = counts[0]
    for count in counts:
        if min > count:
            min = count

    return min


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


### FIXED CODE ###

import sys
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = list(inputs[0])

    count = [persons[1:].count("E")]

    for i in range(1, len(persons)):
        if i == 0:
            continue

        tmp = count[-1]
        if persons[i - 1] == 'W':
            tmp += 1
        if persons[i] == 'E':
            tmp -= 1
        count.append(tmp)

    return min(count)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)
### BUGGY CODE ###

H, N = (int(i) for i in input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = (int(j) for j in input().split())
A_max = max(A)

DP = [0]*(H+A_max)
for i in range(1, H+A_max):
    dp = float('inf')
    for a, b in zip(A,B):
        if i-a>=0:
            dp = min(dp, DP[i-a] + b)
    DP[i] = dp
print(min(DP[H:]))

### FIXED CODE ###

H, N = (int(i) for i in input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = (int(j) for j in input().split())
A_max = max(A)

DP = [0]*(H+A_max)
for i in range(1, H+A_max):
    dp = float('inf')
    for a, b in zip(A,B):
        if i-a>=0:
            dp = min(dp, DP[i-a] + b)
    DP[i] = dp
print(min(DP[H:]))
### BUGGY CODE ###

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

S = str(input())
N = len(S)
M = 13

dp = [[0]*M for _ in range(N)]
c = [0]*(N)
for i in range(N):
    c[i] = (10**i)%M
#print(c)
c.reverse()
#print(c)

if S[0] == "?":
    for l in range(10):
        m = l * c[0]%M
        dp[0][m] += 1
else:
    m = int(S[0]) * c[0]%M
    dp[0][m] = 1
for i in range(1,N):
    for j in range(M):
        if S[i] == "?":
            for l in range(10):
                m = l*c[i]%M
                dp[i][j] += dp[i-1][(M+j-m)%M]
        else:
            m = int(S[i])*c[i]%M
            dp[i][j] = dp[i-1][(M+j-m)%M]

#print(dp)
print(dp[N-1][5]%mod)




### FIXED CODE ###

import sys
 
 
def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    ls = [[0] * 13 for _ in range(len(s))]
    for i in range(len(s)):
        if i == 0:
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                ls[i][int(s[-i-1])] += 1
        else:
            mult = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        ls[i][(k * mult + j) % 13] += ls[i-1][j]
            else:
                st = int(s[-i-1])
                for j in range(13):
                    ls[i][(st * mult + j) % 13] += ls[i-1][j]
        for j in range(13):
            ls[i][j] = ls[i][j] % mod
    print(ls[-1][5])
 
 
if __name__ == '__main__':
    solve()