Harryxun/stf_run huggingface dataset:
A=str(input())
a=A.index("A")
Z=[]
for i in enumerate(A):
    if i[1]=="Z":
        Z.append(i[0])
if len(Z)>=2:
    b=max(Z)
else:
    b=A.index("B")
print(len(A[a:b+1]))

### FIXED CODE ###

A=str(input())
a=A.index("A")
Z=[]
for i in enumerate(A):
    if i[1]=="Z":
        Z.append(i[0])
if len(Z)>=2:
    b=max(Z)
else:
    b=A.index("Z")

print(len(A[a:b+1]))
kl


### FIXED CODE ###

s = int(input())
h = s // 3600
m = s % 3600 // 60
s = s % 60
print(f"{h}:{m}:{s}")
x = int(input().rsplit(" "))
a = x[0] * x[1]
b = x[0] + x[1] + x[0] + x[1]
print(str(a) + str(b)


### FIXED CODE ###

x = input().split(" ")
a = int(x[0]) * int(x[1])
b = int(x[0]) + int(x[1]) + int(x[0]) + int(x[1])
print(str(a) +" " + str(b))
from collections import deque

N=input()

nl=[ [] for i in range(N+1) ]

q=deque()
for i in range(N-1):
	u,v,w=map(int, raw_input().split())
	nl[u].append( (v,w) )
	nl[v].append( (u,w) )

	if i==0:
		Visit[u]=0
		q.append(1)

Visit=[ None for i in range(N+1) ] 


while q:
	x=q.popleft()
	for to,kyori in nl[x]:
		if Visit[to] is None:
			if kyori%2==0:
				Visit[to]=Visit[x]
			else:
				Visit[to]=(Visit[x]+1)%2
			q.append(to)
			

for i in Visit[1:]:
	print i


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N,M=map(int, raw_input().split())
par=[ i for i in range(N+1)  ]

def root(x):
	if par[x]==x:
		return x
	else:
		par[x]=root( par[x] )
		return par[x]

def same(x,y):
	return root(x)==root(y)

def unite(x,y):
	x=root(x)
	y=root(y)
	if x==y: return
	par[x]=y


for i in range(M):
	x,y,z=map(int, raw_input().split())
	unite(x,y)


S=set()
for i in range(1,N+1):
	S.add(root(i))

print len(S)
N = int(input())
a = list(map(int, input().split()))

avg = 0
for i in range(N):
    avg += a[i]
avg /= N
a = list(set(a))
result = 100


if avg in a:
    result = a.index(avg)
else:
    for i in range(len(a)):
        temp = abs(avg-a[i])
        if temp <= result:
            result = temp
    result = a.index(round(result))
print(result)


### FIXED CODE ###

import numpy as np
N = int(input())
a = list(map(int, input().split()))

avg = 0
for i in range(N):
    avg += a[i]
avg /= N

idx = np.abs(np.asarray(a)-avg).argmin()
print(idx)
s=intput()
ss=intput()
c=0
for i in range(len(s)):
  if(s[i]!=ss[i]):
    c+=1
print(c)

### FIXED CODE ###

n=input()
nn=input()
c=0
for i in range(len(n)):
    if(n[i]!=nn[i]):
        c+=1
print(c)
n , k = map(int,input().split())
steps = list(map(int,input().split()))
dp = []

def frog(list,n,max):
    global dp

    if n == 0:
        dp.append(0)
    else:
        global k
        temp = 10000
        for i in range(k):
            if n == i:
                break
            jump = abs(list[n]-list[n-(i+1)])+dp[n-(i+1)]
            if jump <= temp:
                temp = jump
        dp.append(temp)
for i in range(n):
    frog(steps,i,n)
print(dp[n-1])


### FIXED CODE ###

n = int(input())
steps = list(map(int,input().split()))
dp = []

def frog(list,n,max):
    global dp
    if n == 0:
        dp.append(0)
    else:
        temp1 = abs(list[n] - list[n-1]) + dp[n-1]

        if n == 1:
            dp.append(temp1)
        else:
            temp2 = abs(list[n] - list[n-2]) + dp[n-2]
            if temp1 >= temp2:
                dp.append(temp2)
            else:
                dp.append(temp1)
for i in range(n):
    frog(steps,i,n)
print(dp[n-1])
K = int(input())
A,B = map(int,input().split())

a = (B//K) - (A//K)

if A==B:
    if A % K = 0:
        print("OK")

    else:
        print("NG")

else:
    if a==0:
        print("NG")
    
    else:
        print("OK")

### FIXED CODE ###

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

a = (B//K)*K - A

if a < 0:
    print("NG")

else:
    print("OK")
def get_par(x):
  if x == par_list[x]:
    return x
  else:
    par = get_par(par_list[x])
    par_list[x] = par
    return par

N,M=map(int,input().split())
par_list = [i for i in range(N+1)]
for i in range(M):
  Xi,Yi,Zi=map(int,input().split())
  par_Xi = get_par(Xi)
  par_Yi = get_par(Yi)
  if par_Xi != par_Yi:
    par_list[par_Yi] = par_list[par_Xi]
    
#print(par_list)
set_uf = set()
for par in par_list[1:]:
  set_uf.add(get_par(par))
  
print(len(set_uf))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

def get_par(x):
  if x == par_list[x]:
    return x
  else:
    par_list[x] = get_par(par_list[x])
    return par_list[x]

N,M=map(int,input().split())
par_list = list(range(N))
for i in range(M):
  Xi,Yi,Zi=map(int,input().split())
  par_Xi = get_par(Xi-1)
  par_Yi = get_par(Yi-1)
  if par_Xi != par_Yi:
    par_list[par_Yi] = par_Xi
    
set_uf = set()
for par in par_list:
  set_uf.add(get_par(par))
  
print(len(set_uf))
n=input()
print'Yes' if (n.count('7')) >= 1 else: 'No'

### FIXED CODE ###

n=input()
if (n.count('7')) >= 1:
  print('Yes')
else:
  print('No')
# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
num=[0]*(n+1)
for i in range(1,n+1):
    num[i%k]+=1

for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k:continue
    cnt+=num[a]*num[b]*num[c]
    
print(cnt)

### FIXED CODE ###

# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
a=n//k
b=(n+(k//2))//k if k%2==0 else 0
print(a**3+b**3)
t = map(int, input().split())
if t[0]＊t[1] % 2 == 0:
 print("No")
else:
 print("Yes")

### FIXED CODE ###

s, t = map(int, input().split())
if s * t % 2 == 0:
  print("No")
else:
  print("Yes")
K, X = map(int, input().split())
print("Yes" if 500*K > = 2000 else "No")

### FIXED CODE ###

K, X = map(int, input().split())
print("Yes" if 500*K >= X else "No")
# cook your dish here
s = input()
c = 0 
if(s[0]==s[1] and s[2]==s[3]):
    c=1 
elif(s[0]==s[2] and s[1]==a[3]):
    c=1 
elif(s[0]==s[3] and s[1]==s[2]):
    c=1 
if(c==1):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

# cook your dish here
s = input()
a=[0,0,0,0]
b=[1,1,1,1]
for i in range(4):
    for j in range(4):
        if(s[i]==s[j] and i != j):
            a[i]+=1 
if(a==b):
    print("Yes")
else:
    print("No")
N = int(input())
K = []
for i in range(N):
    x, y = map(int,input().split())
    t = x + y
    if x <= 0:
        t -= 4*abs(x)
    if y <= 0:
        t -= 4*abs(y)
    K.append([t, x, y])

K.sort()
ans = K[-1][0] - K[0][0]
for i in range(N-1):
    if K[i][0] == K[i+1][0]:
        A.append(K[i+1][1])
    else:
        ans = max(ans, max(A) - min(A))
        A = [K[i][1]]
print(ans)

### FIXED CODE ###

N = int(input())
A = []
B = []
for i in range(N):
    x, y = map(int, input().split())
    A.append(x+y)
    B.append(x-y)
print(max(max(A)-min(A), max(B)-min(B)))
def main(N,K,p):
    sumi = 0
    ruiseki = [0] * (N+1)
    for i in range(N):
        ruiseki[i+1] = ruiseki[i] + p[i]
    for j in range(K):
        sumi = max(sumi, (ruiseki[j+K]-ruiseki[j]))
    return (sumi + K) /2
N,K = map(int,input().split())
p = list(map(int,input().split()))
print(main(N,K,p))


### FIXED CODE ###

def main(N,K,p):
    sumi = 0
    ruiseki = [0] * (N+1)
    for i in range(N):
        ruiseki[i+1] = ruiseki[i] + p[i]
    for j in range(N-K+1):
        sumi = max(sumi, (ruiseki[j+K]-ruiseki[j]))
    return (sumi + K) / 2
N,K = map(int,input().split())
p = list(map(int,input().split()))
print(main(N,K,p))
S = input()
X = int(S[0:2])
Y = int(S[2:4])

if X > 12 and Y > 12:
    print("NA")
elif X == 0 or Y == 0:
    if X == 0:
        if Y > 12:
            print("NA")
        else:
            pirnt("YYMM")
    else:
        if X > 12:
            print("NA")
        else:
            print("MMYY")
elif X < 13 and Y < 13:
    print("AMBIGUOUS")
elif X > Y:
    print("YYMM")
else:
    print("MMYY")


### FIXED CODE ###

S = input()
X = int(S[0:2])
Y = int(S[2:4])

if X > 12 and Y > 12:
    print("NA")
elif X == 0 or Y == 0:
    if X == 0:
        if Y > 12 or Y == 0:
            print("NA")
        else:
            print("YYMM")
    else:
        if X > 12:
            print("NA")
        else:
            print("MMYY")
elif X < 13 and Y < 13:
    print("AMBIGUOUS")
elif X > Y:
    print("YYMM")
else:
    print("MMYY")
from operator import itemgetter
from collections import Counter
import heapq
N, K = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(N)]
td.sort(key=itemgetter(1, 0), reverse=True)
t, d = zip(*td)

cnt_all = Counter(t)
cnt_all = cnt_all.most_common()
kind = len(cnt_all)
tmp = 0
i = 0
while tmp < K:
    tmp += cnt_all[i][1]
    i += 1
init_kind = i
S = []
heapq.heapify(S)
cnt = Counter()
for i in range(K):
    cnt[t[i]] += 1
    heapq.heappush(S, (d[i], i, t[i]))
sums = [0]*(K+1)
sums[init_kind] = sum(list(zip(*S))[0])
for i in range(init_kind, kind):
    nS = []
    heapq.heapify(nS)
    keys = cnt.keys()
    remove_flag = False
    for _ in range(K):
        tmp = heapq.heappop(S)
        if cnt[tmp[2]] == 1:
            heapq.heappush(nS, tmp)
        else:
            if remove_flag:
                heapq.heappush(nS, tmp)
            else:
                remove_flag = True
                cnt[tmp[2]] -= 1
    for j in range(N):
        if t[j] not in keys:
            heapq.heappush(nS, (d[j], j, t[j]))
            cnt[t[j]] += 1
            break
    sums[i+1] = sum(list(zip(*nS))[0])
    S = nS
for i in range(len(sums)):
    sums[i] += i**2
print(max(sums))


### FIXED CODE ###

from operator import itemgetter
N, K = map(int, input().split())
td = [list(map(int, input().split())) for _ in range(N)]
td.sort(key=itemgetter(1, 0), reverse=True)
t, d = zip(*td)

s = set()
q = []
tmp = 0
now = 0
for i in range(K):
    if t[i] not in s:
        s.add(t[i])
    else:
        q.append(d[i])

    tmp += d[i]
    now += 1
kind = len(s)
sums = [-100000000000]*(kind+1)
sums[kind] = tmp
#for i in range(K, N):
#    if not q:
#        break
#    if t[i] not in s:
#        s.
while q:
    kind += 1
    tmp = q.pop()
    for i in range(now, N):
        now += 1
        if t[i] not in s:
            s.add(t[i])
            sums.append(sums[kind-1] + d[i] - tmp)
            break
for i in range(len(sums)):
    sums[i] += i**2
print(max(sums))
N = int(raw_input())
A = map(int, raw_input().split())
D = dict()
for a in A:
   if a not in D:
      D[a] = 0
   D[a] += 1

total = 0
for num, count in D.iteritems():
   if count > 1: total += count - 1
if total % 2 != 0: total += 1
print N - total

### FIXED CODE ###

X = int(raw_input())
minZ = (X / 11)*2
remainder = X % 11
if remainder == 0:
   print minZ
elif remainder > 6:
   print minZ+2
else:
   print minZ+1
n=int(input())
ans=0
a=list(map(int,input().split()))
now=max(a)
noww=now
ka=n+2*now
matc=[0]*ka
mat2=[0]*ka
for i in range(n):
  matc[now-a[i]]+=1
  mat2[now+a[i]]+=1
  now+=1
#print(matc)
for j in range(noww,noww+n+1):
  ans+=matc[j]*mat2[j]
print(ans)
       
       




### FIXED CODE ###

import numpy as np
n=int(input())
ans=0
a=list(map(int,input().split()))
now=max(a)
noww=now
k=n+2*now
matc=[0]*(n+2)
mat2=[0]*(n+2)
for i in range(n):
  neg=i-a[i]
  pos=i+a[i]
  if neg>=0:
    matc[neg]+=1
  if pos<=n:
    mat2[pos]+=1
  now+=1
#print(matc)
for j in range(n+2):
  ans+=matc[j]*mat2[j]
print(ans)
def dfs_v(u):
  color[u] = 1
  d[u] = ++t
  for v in range(n):
    if M[u][v] == 0 and color[v] == 0:
      dfs_v(v)
  color[u] = 2
  f[u] = ++t

def dfs():
  color = [0 for i in range(n)]
  t = 0
  for u in range(n):
    dfs_v(u)
  for u in range(n):
    print "%d %d %d" %(u+1, d[u], f[u])

n = input()

d = [0 for i in range(n)]
f = [0 for i in range(n)]
M = [0 for i in range(n)]0 for j in range(n)]

for i in range(n):
  u, k = map(int, raw_input().split())
  for j in range(k):
   v = input()
   M[u-1][v-1] = 1

dfs()
    

### FIXED CODE ###

n = int(raw_input())
 
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
col = [0 for i in range(n)]
t = [0]
 
def DFS_visit(u):
    col[u] = 1
    t[0] += 1
    d[u] = t[0]
    for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
    col[u] = 2
    t[0] += 1
    f[u] = t[0]
 
def DFS():
    for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
    for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
     
for i in range(n):
    X = map(int, raw_input().split())
    for j in range(X[1]):
        M[X[0]-1][X[2+j]-1] = 1
 
DFS()
n,m = map(int,input().split())
l = [map(int, input().split()) for i in range(n)]
ans = 0
l.sort()
for a,b in l:
  if b >= m:
    ans += a * m
    break
  else:
    ans += a*b
    m -= b
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
l = []
for i in range(n):
    a,b = map(int, input().split())
    l.append((a,b))
ans = 0
l.sort()
for a,b in l:
  if b >= m:
    ans += a * m
    break
  else:
    ans += a*b
    m -= b
print(ans)
#!/usr/bin/env python
# coding: utf-8

# In[13]:


import sys
input = sys.stdin.readline


# In[24]:


N,K = list(map(int, input()))
A = list(map(int, input()))


# In[16]:


def main():
    x0 = 1
    for i in range(K):
        x0 *= A[i]
    x = x0
    for j in range(K,N):
        score = x*A[j]//A[j-K]
        if score > x:
            print("Yes")
        else:
            print("No")
        x = score


# In[17]:


if __name__ == '__main__':
    main()


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[2]:


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


# In[9]:


def main():
    for j in range(K,N):
        if A[j] > A[j-K]:
            print("Yes")
        else:
            print("No")


# In[10]:


if __name__ == '__main__':
    main()


# In[ ]:
h,w = map(int, input().split())
s = []
for i in range(w):
    s.append(str(input()))
    
flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            check = False
            if i+1 < h:
                if s[i+1][j] == '#':
                    check = True
            if j+1 < w:
                if s[i][j+1] == '#':
                    check = True
            if i-1 >= 0:
                if s[i-1][j] == '#':
                    check = True
            if j-1 >= 0:
                if s[i][j-1] == '#':
                    check = True
            if check == False:
                flag = False
if flag:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

H, W = map(int, input().split())
Sij = []
for _ in range(H):
    Sij.append(input())
result = []
for a in range(H):
    for b in range(W):
        check = []    
        if Sij[a][b] == '#':
            if a-1 >= 0:
                H_up = a - 1
                S_H_up = Sij[H_up][b]
                check.append(S_H_up)
            if a+1 <= H-1:
                H_down = a + 1
                S_H_down = Sij[H_down][b]
                check.append(S_H_down)
            if b-1 >= 0:
                W_right = b - 1
                S_W_right = Sij[a][W_right]
                check.append(S_W_right)
            if b+1 <= W-1: 
                W_left = b + 1
                S_W_left = Sij[a][W_left]
                check.append(S_W_left)
            if '#' in check:
                result.append('good')
            else:
                result.append('bad')
                
if 'bad' in result:
    print('No')
else:
    print('Yes')
x=int(input())-1
if int(input())>=x:
  x+=1
print(x)

### FIXED CODE ###

x,y=map(int,input().split())
if y<x:
  x-=1
print(x)
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = sum(B) - sum(A)
a, b = cnt, cnt
for i in range(N):
    if A[i] < B[i]:
        cnt -= (B[i]-A[i+1])//2
    elif A[i] > B[i]:
        a -= A[i]-B[i]
    if a < 0 or b < 0:
        print("No")
        break
else:
    print("Yes")

### FIXED CODE ###

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

cnt = sum(B) - sum(A)
a, b = cnt, cnt
for i in range(N):
    if A[i] < B[i]:
        b -= (B[i]-A[i]+1)//2
    elif A[i] > B[i]:
        a -= A[i]-B[i]
    if a < 0 or b < 0:
        print("No")
        break
else:
    print("Yes")
import math
def main():
	N = int(input())
	P = int(math.log(N,5))
	ans = 0
	if N%2 == 1:
		print(0)
	else:
		N = int(N/2)
		ans = [ int(N/(5**p)) for p in range(1,P+1)]
		print(sum(ans))

if __name__ == '__main__':
	main()

### FIXED CODE ###

import math
def main():
	N = int(input())
	if N%2 == 1 or N==0:
		print(0)
	else:
		N = N//2
		P = int(math.log(N,5))
		ans = [ N//(5**p) for p in range(1,P+1)]
		print(sum(ans))

if __name__ == '__main__':
	main()
N, A, B, C, D, E = map(int, input().split())
list=[A, B, C, D, E]
min=min(list)
print(-(-N//min)

### FIXED CODE ###

N=int(input())
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
min=min(A, B, C, D, E)
print(-(-N//min)+4)
n, m = map(int, input().split())
ans = ['t'] * n

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] =='t' or ans[s-1] == str(c):
        ans[s-1]= str(c)
    else:
        print(-1)
        exit(0)
if ans[0] == 't':
    ans[0]=1
ans = ''.join(ans).replace('t', str(0))
ans = int(ans)
l = str(ans)
if len(l) != n:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
ans = ['t'] * n

for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] =='t' or ans[s-1] == str(c):
        ans[s-1]= str(c)
    else:
        print(-1)
        exit(0)
if ans[0] == 't' and n >1:
    ans[0]=str(1)

ans = ''.join(ans).replace('t', str(0))
ans = int(ans)
l = str(ans)
if len(l) != n:
    print(-1)
else:
    print(ans)
import copy
s = list(input())

def check01(s):
    if len(s) > 1:
        for i in range(len(s)-1):
            if s[i] != s[i+1]:
                del s[i:i+2]
                return check01(s)
    return s
s2 = copy.deepcopy(s)
s2 = check01(s2)
print(len(s) - len(s2))



### FIXED CODE ###

import numpy as np
s = list(input())

cnt = np.empty(2)
for i in range(len(s)):
    cnt[int(s[i]) - 0] += 1
ans = np.min(cnt) * 2
print(int(ans))
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


x,y=map(int,input().split())
s=(2*y-x)/3
t=(2*x-y)/3
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
else:
    a = cmb(s+t, t)
    print(a%(10**9+7))

### FIXED CODE ###

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


x,y=map(int,input().split())
s=int((2*y-x)/3)
t=int((2*x-y)/3)
if (2*y-x)%3!=0 or (2*x-y)%3!=0:
    print(0)
elif s<0 or t<0:
    print(0)
else:
    a = cmb(s+t, t)
    print(a%(10**9+7))
# coding: utf-8
# Your code here!
N,K=map(int,input().split())

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

mod=10**9+7
cand=[0]


def comb(n):
    if n==N-1:
        return 0
    
    if n<K-2:
        cand.append(0)
    elif n==K-2:
        cand.append(1)
    else:
        cand.append(cand[-1]*n/(n-K+2))
        
    comb(n+1)
    
    return 0

comb(0)

for i in range(N-1):
    cand[i+1]=cand[i]+cand[i+1]

up=sorted(A)
down=sorted(A,reverse=True)
down=list(map(lambda x:-x,down))

ans=0
for i in range(N):
    ans+=(up[i]+down[i])*cand[i]

print(int(ans%mod))

### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10000000)

N,K=map(int,input().split())

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

mod=10**9+7
cand=[0]

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def comb(n):
    if n==N-1:
        return 0
    
    if n<K-2:
        cand.append(0)
    elif n==K-2:
        cand.append(1)
    else:
        cand.append((cand[-1]*n)%mod*mod_inv((n-K+2),mod)%mod)
        
    comb(n+1)
    
    return 0

comb(0)

for i in range(N-1):
    cand[i+1]=cand[i]+cand[i+1]

up=sorted(A)
down=sorted(A,reverse=True)
down=list(map(lambda x:-x,down))

ans=0
for i in range(N):
    ans+=(up[i]+down[i])*cand[i]

print(int(ans%mod))
# https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け


x, y = map(int, input().split())
if x * y < 0:  # 異符号ならば答えは一つ
    print(abs(abs(x) - abs(y)) + 1)
elif 0 <= x < y:
    print(y - x)
elif 0 <= y < x:
    print(x + y + 1)
    raise ValueError()
elif x < y <= 0:
    print(y - x)
else:
    print(2 + x - y)


### FIXED CODE ###

# https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け


x, y = map(int, input().split())
if x * y < 0:  # 異符号ならば答えは一つ
    print(abs(abs(x) - abs(y)) + 1)
    exit()
elif 0 <= x < y:
    print(y - x)
    exit()
elif 0 < y < x:
    print(2 + x - y)
    exit()
elif y == 0 and y < x:
    print(1 + x)
    exit()
elif x < y <= 0:
    print(y - x)
    exit()
elif y < x < 0:
    print(2 + x - y)
    exit()
elif x == 0 and y < x:
    print(1 - y)
    exit()
raise ValueError()
x = input()
y = input()
x = int(x)
y = int(y)

if x >= y:
    print(10)
else:
    print(0)

### FIXED CODE ###

x, y= map(int, input().split())

if x >= y:
    print(10)
else:
    print(0)
N = int(input())
for i in range(1,1+int(N)):
    if N % i == 0:
        tmp = i
s = max(len(str(N // tmp)),len(str(tmp)))
ans = min(ans,s)
print(ans)

### FIXED CODE ###

N = int(input())
for i in range(1,1+int(N**(1/2))):
    if N % i == 0:
        tmp = i
print(max(len(str(N // tmp)),len(str(tmp))))
a, b = int(raw_input().split())

if a > b:
  print "a > b"
elif a < b:
  print "a < b"
else:
  print "a == b"

### FIXED CODE ###

a, b = map(int, raw_input().split())

if a == b:
  print 'a == b'
elif a < b:
  print 'a < b'
else:
  print 'a > b'
n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if s[l] == t:
            l = min(l + 1, n)

        if r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n)
    else:
        if 0 < l and s[l - 1] == t:
            l = max(0, l - 1)

        if s[r] == t:
            r = max(0, r - 1)


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))


### FIXED CODE ###

n, q = [int(i) for i in input().split()]
s = input()
td = reversed([input().split() for _ in range(q)])

l = 0
r = n - 1
for t, d in td:
    if d == "L":
        if 0 <= l < n and s[l] == t:
            l = l + 1

        if 0 <= r + 1 < n and s[r + 1] == t:
            r = min(r + 1, n - 1)
    else:
        if 0 <= l-1 < n and s[l - 1] == t:
            l = max(0, l - 1)

        if 0 <= r < n and s[r] == t:
            r = r - 1


'''
    if s[l] == t:
        if d == "L":
            l += 1
        else:
            l -= 1
        l = max(0, min(n - 1, l))
    if s[r] == t:
        if d == "L":
            r += 1
        else:
            r -= 1
        r = max(0, min(n - 1, r))
'''
print(max(0, r-l+1))