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


N = int(input())

aaa = list(map(int, input().split()))



ans = 1

for i in range(N):
    ans = ans * aaa[i]

if ans > 10 ** 18:
        ans = -1
print(ans)






### FIXED CODE ###


N = int(input())

aaa = list(map(int, input().split()))
ans = 1

if 0 in aaa:
    ans = 0
else:
    for i in range(N):
        if ans > 10 ** 18:
            ans = -1
            break
        else:
            ans = ans * aaa[i]


if ans > 10 ** 18:
    ans = -1


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

n=int(input())
num=list(map(int,input().split()))
add=sum(num)
q=int(input())
for i in range(q):
    cnt=0
    b,c=map(int,input().split())
    num.sort()
    for i in range(len(num)):
        if num[i]==b:
            num[i]=c
            cnt+=1
        elif num[i]>b:
            break
    add+=(c-b)*cnt
    print(add)

### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
sum_num=sum(a)
cnt=Counter(a)
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    sum_num+=(c-b)*cnt[b]
    print(sum_num)
    cnt[c]+=cnt[b]
    cnt[b]=0
### BUGGY CODE ###

h,w,k = list(map(int,input().split()))
arr = [[int(i) for i in input()] for _ in range(h)]

from itertools import product
ans = [0]*(2**(h-1))

for idx,h_cond in enumerate(product((True,False),repeat=h-1)):
    div = sum(h_cond)
    splits = [arr[0][:]]
    for i in range(h-1):
        if h_cond[i]:
            splits.append(arr[i+1][:])
        else:
            splits[-1] = [splits[-1][j] + arr[i+1][j] for j in range(w)]
    block = len(splits)
    count = [0]*block
    
    for v_pos in range(w):
        tmp = [splits[i][v_pos] for i in range(block)]
        if max(tmp) > k:
            div = 2000
            break
        if max([count[i] + tmp[i] for i in range(block)]) > k:
            div += 1
            count = tmp[:]
        else:
            count  = [count[i] + tmp[i] for i in range(block)]
    
    ans[idx] = div
            
print(min(ans))

### FIXED CODE ###

h,w,k = list(map(int,input().split()))
arr = [[int(i) for i in input()] for _ in range(h)]

from itertools import product
ans = 2000

for idx,cond in enumerate(product((True,False),repeat=h-1)):
    div = sum(cond)
    spl = [arr[0][:]]
    for i in range(h-1):
        if cond[i]:
            spl.append(arr[i+1][:])
        else:
            spl[-1] = [spl[-1][j] + arr[i+1][j] for j in range(w)]
    num = len(spl)
    cnt = [0]*num
    
    for v in range(w):
        tmp = [spl[i][v] for i in range(num)]
        if max(tmp) > k:
            break
        if max([cnt[i] + tmp[i] for i in range(num)]) > k:
            div += 1
            cnt = tmp[:]
        else:
            cnt  = [cnt[i] + tmp[i] for i in range(num)]
    else:    
        ans = min(ans,div)
            
print(ans)
### BUGGY CODE ###

from operator import itemgetter

s=input()
k=int(input())

S=[]
ls=len(s)
for i in range(ls):
    S.append([s[i:ls],0,ls-i])

S.sort()

S[0][1]=S[0][2]
for i in range(ls-1):
    t=0
    lS0=len(S[i][0])
    lSp1=len(S[i+1][0])
    while t<lS0 and t<lSp1 and S[i][0][t]==S[i+1][0][t]:
        t+=1
    S[i+1][1]=S[i+1][2]-t

#print(S)




k-=1
i=0
while k>=S[i][1] :
    k-=S[i][1]
    i+=1

ans=S[i][0][0:(S[i][2]-S[i][1]+k+1)]

#print(i)

print(ans)


### FIXED CODE ###

s = input()
n = len(s)
k = int(input())

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

A.sort()
# print(A)

B = []

for i in range(min(k, len(A))):
    for j in range(1, len(A[i])+1):
        B.append(A[i][:j])

B.sort()

# print(B)
co = 1
i = 1
mae = B[0]
while co < k:
    #print(i)
    if mae != B[i]:
        co += 1
        mae = B[i]
    i += 1
print(mae)
### BUGGY CODE ###

n = int(input())
li = list(input())	
[print(li.count(str(i + 1))) for i in range(n)]

### FIXED CODE ###

import collections

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

for i in range(1, N + 1):
  print(c[i])
### BUGGY CODE ###

def spline(func=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func, iter_)


def parg(**kwargs):
    text = ''
    for item in kwargs.items():
        if text:
            text += ',\t'
        text += '{}: {}'.format(*item)
    print(text)


K, S = spline()
count = 0
k = K + 1
for x in range(k):
    if x + K * 2 < S:
        continue
    for y in range(k):
        if x + y + K < S:
            continue
        for z in range(k):
            if x + y + z == S:
                count += 1
                break
print(count)


### FIXED CODE ###

def spline(func=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func, iter_)


K, S = spline()
count = 0
k = K + 1
for x in range(k):
    for y in range(k):
        z = S - x - y
        if 0 <= z <= K:
            count += 1
print(count)
### BUGGY CODE ###

import heapq
[N,L] = [int(x) for x in input().split()]
A = [[int(x),int(i)] for i,x in enumerate(input().split())]
heapq.heapify(A)
ANS = [10**9+1]*N
for j in range(N):
    a = heapq.heappop(A)
    for i in range(L):
        try :
            if ANS[a[1]+i] == 10**9+1 : ANS[a[1]+i] = a[0]
        except IndexError : continue
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 ###

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

def judge_pm(a,b):
    if a*b<0:
        return True
    else:
        return False

a1 = copy.deepcopy(a)
tmp_sum = a1[0]
operate_num1 = 0
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a1[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num1 =  - tmp_sum + 1 - a1[i]
        operate_num1 += tmp_operate_num1
        a1[i] += tmp_operate_num1
    else:
        tmp_operate_num1 = tmp_sum + 1 + a1[i]
        operate_num1 += tmp_operate_num1
        a1[i] -= tmp_operate_num1
    tmp_sum += a1[i]
        
a2 = copy.deepcopy(a)
tmp_sum = a2[0]
operate_num2 = 0
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a2[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num2 =  - tmp_sum + 1 - a2[i]
        operate_num2 += tmp_operate_num2
        a2[i-1] -= tmp_operate_num2
        tmp_sum -= tmp_operate_num2
    else:
        tmp_operate_num2 = tmp_sum + 1 + a2[i]
        operate_num2 += tmp_operate_num2
        a2[i-1] += tmp_operate_num2
        tmp_sum += tmp_operate_num2
    tmp_sum += a2[i]
print(min(operate_num1, operate_num2))        


### FIXED CODE ###

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

def judge_pm(a,b):
    if a*b<0:
        return True
    else:
        return False

a1 = copy.deepcopy(a)
operate_num1 = 0
if a1[0]==0:
    a1[0] = 1
    operate_num1 += 1
tmp_sum = a1[0]
for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a1[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a1[i]
        operate_num1 += tmp_operate_num
        a1[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a1[i]
        operate_num1 += tmp_operate_num
        a1[i] -= tmp_operate_num
    tmp_sum += a1[i]
        
a2 = copy.deepcopy(a)
operate_num2 = 0
if a2[0]<0:
    operate_num2 += 1 - a2[0]
    a2[0] += operate_num2
else:
    operate_num2 += a2[0] + 1
    a2[0] -= operate_num2

tmp_sum = a2[0]

for i in range(1, n):
    if judge_pm(tmp_sum, tmp_sum+a2[i]):
        pass 
    elif tmp_sum<0:
        tmp_operate_num =  - tmp_sum + 1 - a2[i]
        operate_num2 += tmp_operate_num
        a2[i] += tmp_operate_num
    else:
        tmp_operate_num = tmp_sum + 1 + a2[i]
        operate_num2 += tmp_operate_num
        a2[i] -= tmp_operate_num
    tmp_sum += a2[i]

print(min(operate_num1, operate_num2))
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]

day = 1
for ii in range(3500):
  player_in_this_game = set()
  nokori_games = 0
  
  for m in range(n): #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    la = len(a[m])
    nokori_games += la #自分の残り試合予定数を足す
    if m in player_in_this_game: #既に試合が組まれている
      pass
    elif la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      if a[teki - 1][0] == jibun:
        if teki - 1 in player_in_this_game:
          pass
        else:
          #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
          a[m].popleft() #自分の予定を消す
          a[teki - 1].popleft() #相手の予定を消す
          player_in_this_game.add(m) #自分を試合中にする
          player_in_this_game.add(teki - 1) #相手を試合中にする
          nokori_games -= 1 #残り試合予定を1つ減らす
  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1


### FIXED CODE ###

import sys
import time
from collections import deque

start = time.time()

input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
player_in_this_game = set()
rn = range(n)
for _ in r5000:
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    if m in player_in_this_game:
      #自分が既に試合が組まれている
      continue

    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      teki_idx = teki - 1
      if teki_idx in player_in_this_game:
        #相手が既に試合に組まれている
        continue

      if a[teki_idx][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki_idx].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki_idx) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1
  player_in_this_game.clear()
  elapsed_time = time.time() - start
  if elapsed_time > 1:
    print(n*(n-1)//2)
    exit()
### BUGGY CODE ###

N = int(input())
lis = [i for i in range(2,55555)]
primes = []
p=1
while(p*p < 55555):
  p = lis.pop(0)
  primes.append(p)
  for num in lis:
    if num%p == 0: lis.remove(num)
primes = primes + lis
prime2 = []
for p in primes:
  if p%5 ==1 :primes+=[p]

print(' '.join(map(str, prime2[:N])))


### FIXED CODE ###

N = int(input())
lis = [i for i in range(2,55555)]
primes = []
p=1
while(p*p < 55555):
  p = lis.pop(0)
  if p%5==1:primes.append(p)
  for num in lis:
    if num%p == 0: lis.remove(num)
while(len(primes)<=56):
  p = lis.pop(0)
  if p%5==1:primes.append(p)

print(' '.join(map(str, primes[:N])))
### BUGGY CODE ###

from collections import defaultdict
MOD = 2019
def main():
    S = input()
    dp = [0] * (len(S)+1)
    for i in range(len(S)):
        dp[i+1] = (int(S[-1-i])*(10**i) + dp[i]) % MOD
    d = defaultdict(int)
    for i in range(len(S)+1):
        d[dp[i]] += 1
    output = 0
    for i in d.keys():
        output += (d[i] * (d[i]-1) // 2)
    print(output)
    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict
MOD = 2019
def main():
    S = input()
    dp = [0] * (len(S)+1)
    ex = 1
    for i in range(len(S)):
        dp[i+1] = (int(S[-1-i])*ex + dp[i]) % MOD
        ex *= 10
        ex %= MOD
    d = defaultdict(int)
    for i in range(len(S)+1):
        d[dp[i]] += 1
    output = 0
    for i in d.keys():
        output += (d[i] * (d[i]-1) // 2)
    print(output)
    return

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

import numpy as np
import copy

S = str(input())
Q = int(input())

Que = [0]* Q
for i in range(Q):
    Que[i] = list(map(str, input().split()))

answer = copy.copy(S)
check = 1
for i in range(Q):
    T = Que[i][0]
    if int(T) == 1:
        check *= -1
    else:
        F = Que[i][1]
        if (int(F) == 1 and check == 1) or (int(F) == 2 and check == -1):
            answer = ''.join([Que[i][2], answer])
        else:
            answer = ''.join([answer, Que[i][2]])
if check == -1:
    answer = ''.join(list(reversed(answer)))
print(answer)

### FIXED CODE ###

import numpy as np
import copy
from collections import deque

S = str(input())
Q = int(input())

Que = [0]* Q
for i in range(Q):
    Que[i] = list(map(str, input().split()))

check = 1
L = deque()
R = deque()
for i in range(Q):
    T = Que[i][0]
    if int(T) == 1:
        check *= -1
    else:
        F = Que[i][1]
        if (int(F) == 1 and check == 1) or (int(F) == 2 and check == -1):
#            answer = ''.join([Que[i][2], answer])
            L.appendleft(Que[i][2])
        else:
#            answer = ''.join([answer, Que[i][2]])
            R.append(Que[i][2])
answer = ''.join(L) + S + ''.join(R)
if check == -1:
    answer = ''.join(list(reversed(answer)))
print(answer)
### BUGGY CODE ###

#-*-coding:utf-8-*-

import sys
import numpy as np

def main():
    n = int(input())
    a_numbers=np.arange(1,1001).reshape(1,1000)
    b_numbers=np.arange(1,1001).reshape(1,1000)
    t_a_numbers=a_numbers.T
    dp=np.dot(t_a_numbers,b_numbers)
    numbers=[]
    count=0
    for i in range(1,n):
        tmp=sum(np.count_nonzero(dp==n-i,axis=1))
        count+=tmp
        tmp=0
    print(count)

if __name__ == "__main__":
    main()

### FIXED CODE ###

#-*-coding:utf-8-*-

import sys

def main():
    n = int(input())
    ans=0
    b=0

    for a in range(1,n):
        #A*B+C=n → A <= n-c//b
        #cは1<=c<=nなのでbで可変
        b=(n-1)//a
        ans+=b
    print(ans)


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

N=int(input())
List=list(map(int,input().split()))
lastindex=N//2
for index in range(N):
    AList=List[:]
    AList.pop(index)
    AList.sort()
    print(AList[N//2-1])

    

### FIXED CODE ###

N=int(input())
List=list(map(int,input().split()))
AList=List[:]
List.sort()
div=List[N//2]
backdiv=List[N//2-1]
for indexnum in AList:
    if div > indexnum:
        print(div)
    else:
        print(backdiv)
### BUGGY CODE ###

# -*- coding: utf-8 -*-


def main():
    p = 1
    
    n = int(input())
    
    for i in range(1, n + 1):
        p *= i

    print(p % (10 ** 9 + 7))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import math

N = int(input())
print(math.factorial(N)%(10**9+7))
### BUGGY CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans, count = 1, 0
for k in b.keys():
    for l in b.keys():
        if 0<=(k-l)<=2:
            count += b[l]
    ans = max(ans, count)
    count = 0
print(ans)


### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
count = 1
for i in range(min(a)-1, max(a)+1):
    count = max(count, b.get(i-1,0)+b.get(i, 0)+b.get(i+1, 0))
print(count)
### BUGGY CODE ###

def fun(a,k):
    if len(a)==1:
        return 0
    dp = [float('inf')]*len(a)
    dp[0]=0
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        for j in range(k,0,-1):
            dp[i]=min(dp[i] , dp[i-j]+abs(a[i]-a[i-j]))
    return dp[-1]
n,k = map(int , input().split())
a = list(map(int , input().split()))
print(fun(a,k))

### FIXED CODE ###

def fun(a,k,n): ## k different steps can be taken
    if n==1:
        return 0
    dp = [0]*n
    dp[1]=dp[0]+abs(a[0]-a[1])
    for i in range(2,len(a)):
        t = 0
        min_ = float('inf')
        for j in range(i-1,-1,-1):
            if t==k:
                break
            else:
                t+=1
            if dp[j]+abs(a[i]-a[j]) < min_ :
                   min_ = dp[j]+abs(a[i]-a[j])
        dp[i]=min_
    return dp[-1]
from sys import stdin , stdout
n,k = map(int , stdin.readline().split())
a = list(map(int , stdin.readline().split()))
print(fun(a,k,n))
### BUGGY CODE ###

#--management

member = int(input())
mem_number = [int(i) for i in input().split()]

ans = []

for i in range(member):
  ans.append(0)

for j in range(1,member):
  k = mem_number.count(j)
  ans[j-1] = k

for i in  range(member):
  print(ans[i])



### FIXED CODE ###

#--management
from collections import Counter

member = int(input())
mem_number = [int(i) for i in input().split()]

ans = []

ans = [0] * member

mycounter = Counter(mem_number)

for i in range(member):
  ans[i] = mycounter[i+1]
  print(ans[i])
### BUGGY CODE ###

x,y,z,k=map(int,input().split())
a=[int(i)for i in input().split()]
b=[int(i)for i in input().split()]
c=[int(i)for i in input().split()]
c.sort(reverse=True)
AB=[i+j for i in a for j in b]
AB.sort(reverse=True)
ans=[i+j for i in AB[:k]for j in c]
ans.sort(reverse=True)
for i in ans[:k]:
    print(i)

### FIXED CODE ###

def ca():
    x,y,z,k=map(int,input().split())
    a=[int(i)for i in input().split()]
    b=[int(i)for i in input().split()]
    c=[int(i)for i in input().split()]
    c.sort(reverse=True)
    AB=[i+j for i in a for j in b]
    AB.sort(reverse=True)
    ans=[i+j for i in AB[:k]for j in c]
    ans.sort(reverse=True)
    for i in ans[:k]:
        print(i)
    exit()
print(ca())
### BUGGY CODE ###

X=int(input())

stack = [[0,0]]
i = 0
def bfs(a,b):
    global stack
    global X
    
    if a**5 - b**5== X:
        return True
    
    elif a**5 - b**5 > X:
        stack.append([a,b+1])
        stack.append([a-1,b])
        return False
    elif a**5 - b**5 < X:
        stack.append([a+1,b])
        stack.append([a,b-1])
        return False

while len(stack) > i:
    if bfs(stack[i][0],stack[i][1]):
        print(str(stack[i][0]) +" "+str(stack[i][1]))
        break
    
    i+=1
    




### FIXED CODE ###

X=int(input())
A=0
B=0
flag = False
for a in range(120):
    for b in range(120):
        if a**5 - b**5 == X:
            A=a
            B=b
            flag = True

        if a ** 5 + b**5 == X:
            A=a
            B=-b

        if -a**5 + b**5 ==X:
            A =-a
            B = b

        if flag:
            break
    if flag:
        break
print(str(A)+" "+str(B))
### BUGGY CODE ###

n,a,b=map(int,input().split())
k=[]
ans=0
count=(n//(a+b))
bb=[]
aa=[]
for j in range(a):
    k.append('b')
for t in range(b):
    k.append('r')
kk=k
for i in range(count):
    for y in range(len(k)):
        kk.append(k[y])
print(kk[:n].count('b'))

### FIXED CODE ###

n,a,b=map(int,input().split())
t=n//(a+b)
j=n%(a+b)
ans=0
q=t*a
if(j<=a):
    p=j
else:
    p=a
ans=p+q
print(ans)
### BUGGY CODE ###

N = int(raw_input())
A = map(int, raw_input().split())

count = 0
for i in range(N):
	h = A[i]
	for j in range(i+h+1, N):
		if j - i == h + A[j]:
			count += 1
print count

### FIXED CODE ###

N = int(raw_input())
A = map(int, raw_input().split())

x_occurance = {}
minus = []
for i in range(N):
	p = A[i] + i
	m = i - A[i]
	x_occurance[p] = x_occurance.get(p, 0) + 1
	minus.append(m)

count = 0
for i in range(N):
	count += x_occurance.get(minus[i], 0) 

print count
### BUGGY CODE ###

import math
n=int(input())
a=list(map(int,input().split()))
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(n):
    ans=0
    a1=a.copy()
    del a1[i]
    for k in  set(a1):
        if a1.count(k) != 1:
            ans+=combinations_count(a1.count(k),2)
    print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
b=[0]*(n+1)
for i in range(n):
    b[a[i]]+=1
for k in b:
    ans+=k*(k-1)//2
for i in range(n):
    print(ans-b[a[i]]+1)
### BUGGY CODE ###

from collections import defaultdict

N,Q=[int(x) for x in input().split()]
S=input()
A=defaultdict(list)
B=[1 for x in range(N)]
for i in range(N):
    A[S[i]].append(i)
killed=0
for q in range(Q):
    a,b=input().split()
    tmp=[]
    if b=="R":
        d=1
    else:
        d=-1
    for k in A[a]:
        if (k==0 and d==-1) or (k==N-1 and d==1):
            killed+=B[k]
        else:
            tmp.append([k,B[k],d])
        B[k]=0
    for t in tmp:
        B[t[0]+t[2]]+=t[1]
print(N-killed)

### FIXED CODE ###

from collections import defaultdict

def testkilled(p,S,qry,N):
    pi=p
    c=S[pi]
    for q in qry:
        a,b=q
        if b=="R":
            d=1
        else:
            d=-1
        if c==a:
            pi+=d
            if pi==-1:
                return 1
            if pi==N:
                return 2
            c=S[pi]
    return 0

N,Q=[int(x) for x in input().split()]
S=input()
B=[1 for x in range(N)]
qry=[]
for q in range(Q):
    qry.append(input().split())
l=0
r=N
ans=N
while(r-l>1):
    p=(l+r)//2
    k=testkilled(p,S,qry,N)
    if k==1:
        l=p
    else:
        r=p
if testkilled(0,S,qry,N)==1:
    if testkilled(p,S,qry,N)==1:
        ans-= p+1
    else:
        ans-= p
    #print ("p",p,l,r)    
l=-1
r=N-1
while(r-l>1):
    p=(l+r)//2
    k=testkilled(p,S,qry,N)
    if k==2:
        r=p
    else:
        l=p
if testkilled(N-1,S,qry,N)==2:
    if testkilled(p,S,qry,N)==2:
        ans-= (N-p)
    else:
        ans-= (N-p-1)
#print ("p",p,l,r)
print(ans)
#print(testkilled(0,S,qry,N))
#print(testkilled(1,S,qry,N))
#print(testkilled(N-1,S,qry,N))
### BUGGY CODE ###

s = input()
K = int(input())
n = len(s)
A = []
for i in range(n):
    for j in range(n-i): 
           A.append(s[i:j+i+1])

B = set(A)
C = []
for i in B:
    C.append(i)
C.sort()
print(C[K-1])

### FIXED CODE ###

s = input()
K = int(input())
n = len(s)
A = []
for i in range(n):
    if n < K:
       for j in range(n-i): 
           A.append(s[i:j+i+1])
    else:
       for j in range(K):
           A.append(s[i:i+j+1])
B = set(A)
C = []
for i in B:
    C.append(i)
C.sort()
print(C[K-1])
### BUGGY CODE ###

mod = 2019

a = input()
n = len(a)
x = [0] * n
for i in range(n):
    x[n - i - 1] = int(a[i])

ans = 0
cnt = [0] * mod
cnt[0] = 1
s = [0] * (n + 1)
e = 1

for i in range(n):
    s[i + 1] = ((x[i] * e) % mod + s[i]) % mod
    # print("i = ", i, "s[i + 1] = ", s[i + 1])
    ans += cnt[s[i + 1]]
    cnt[s[i + 1]] += 1
    e *= 10

print(ans)



### FIXED CODE ###

mod = 2019
# import time

a = input()
n = len(a)
x = [0] * n
# begin = time.time()
for i in range(n):
    x[n - i - 1] = int(a[i])
# print("elapsed 1 = ", time.time() - begin)

# begin = time.time()
ans = 0
cnt = [0] * mod
cnt[0] = 1
s = [0] * (n + 1)
e = 1
# print("elapsed 2 = ", time.time() - begin)

# begin = time.time()
for i in range(n):
    s[i + 1] = ((x[i] * e) % mod + s[i]) % mod
    _ = s[i + 1]
    ans += cnt[_]
    cnt[_] += 1
    e = (e * 10) % mod
# print("elapsed 3 = ", time.time() - begin)

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

num = list(map(int, input().split()))
H = list(map(int, input().split()))
N = num[0]
K = num[1]

dp = [float("inf")] * N
dp[0] = 0
for i in range(N):
    try:
        for j in range(K):
            dp[i+1] = min(dp[i+1], dp[i-j]+abs(H[i+1]-H[i-j]))
    except:
        continue

print(dp[-1])

### FIXED CODE ###

num = list(map(int, input().split()))
H = list(map(int, input().split()))
N = num[0]
K = num[1]

dp = [float("inf")] * N
dp[0] = 0
for i in range(N):
    try:
        for j in range(K):
            dp[i+1] = min(dp[i+1], dp[i-j]+abs(H[i+1]-H[i-j]))
    except:
        continue

print(dp[-1])