Harryxun/stf_run huggingface dataset:
s = input()
k = int(input())
substrings = []
index = []
for ss in sorted(list(set(s))):
  index_list = [n for n, v in enumerate(s) if v == ss]
  index.append(index_list)

for ind in index:
  for i in ind:##初期位置
    for j in range(1,len(s)-i+1):##長さ
      substrings.append(s[i:i+j])
  if len(substrings) >= k:
    break
  

print(sorted(list(set(substrings)))[k-1])

### FIXED CODE ###

s = input()
k = int(input())
substrings = []
index = []
for ss in sorted(list(set(s))):
  index_list = [n for n, v in enumerate(s) if v == ss]
  for i in index_list:##初期位置
    for j in range(1,min(k+1,len(s)-i+1)):##長さ
      substrings.append(s[i:i+j])
  if len(set(substrings)) >= k:
    break
print(sorted(list(set(substrings)))[k-1])
s=list(map(str,input()))
#print(s)
ans=0
for i in range(len(s)):
    if s[i]=='A':
        sa=i
    if s[i]=='Z':
        #print("VBHJ")
        ans=max(ans,i-sa+1)

print(ans)

### FIXED CODE ###

s=list(map(str,input()))
#print(s)
for i in range(len(s)):
    if s[i]=='A':
        sa=i
        break

for i in range(len(s)-1,-1,-1):
    if s[i]=='Z':
        zg=i
        break

print(zg-sa+1)
import numpy as np

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

sub = np.bincount(A, weights=None, minlength=N+1)

for i in range(N):
    print(sub[i+1])

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 13:36:36 2020

@author: hiroki
"""

import math

a = input()
print(int(a)*2*math.pi)
import math
a,b,x = map(int,input().split())
s = a*a*b
if x*2 < s :
    ans = 90 - math.degrees(math.atan(2*x/(a*b*b)))
elif x**2 == s :
    ans = math.degrees(math.atan(b/a))
else :
    ans = 90 - math.degrees(math.atan(a**3/(s-x)/2))
print(ans)


### FIXED CODE ###

import math
a,b,x = map(int,input().split())
s = a*a*b
if x*2 < s :
    ans = 90 - math.degrees(math.atan(2*x/(a*b*b)))
elif x == s :
    ans = 0
else :
    ans = 90 - math.degrees(math.atan(a**3/(s-x)/2))
print(ans)
H,W,A,B=map(int,input().split())

if A==0 and B==0:
    for i in range(H):
        ans=["1"]*W
        print("".join(ans))
        exit()
elif A==0:
    ans = ["1"] * W
    for i in range(B):
        print("".join(ans))
    ans=["0"]*W
    for i in range(H-B):
        print("".join(ans))
elif B==0:
    ans1 = ["1"] * A
    ans2 = ["0"] * (W - A)
    for i in range(H):
        ans1.extend(ans2)
        print("".join(ans1))
elif W%A==0 and H%B==0:
    for j in range(H//B):
        ans=[]
        for i in range(W//A):
            if i==j:
                temp=["1"]*A
                ans.extend(temp)
            else:
                temp=["0"]*A
                ans.extend(temp)
        for k in range(B):
            print("".join(ans))
else:
    print("No")

### FIXED CODE ###

H, W, A, B = map(int, input().split())

if A == 0 and B == 0:
    for i in range(H):
        ans = ["1"] * W
        print("".join(ans))
elif A == 0:
    for i in range(B):
        ans=[]
        temp = ["1"] * W
        ans.extend(temp)
        print("".join(ans))
    for i in range(H - B):
        ans=[]
        temp = ["0"] * W
        ans.extend(temp)
        print("".join(ans))
elif B == 0:
    for i in range(H):
        ans1=[]
        ans1 = ["1"] * A
        ans2 = ["0"] * (W - A)
        ans1.extend(ans2)
        print("".join(ans1))
else:
    for i in range(B):
        ans1 = ["1"]*A
        ans2=["0"]*(W-A)
        ans1.extend(ans2)
        print("".join(ans1))
    for i in range(H-B):
        ans1=["0"]*A
        ans2=["1"]*(W-A)
        ans1.extend(ans2)
        print("".join(ans1))
import sys


def dfs(i,p,edges,num):
    
    for j in edges[i]:
        if(j!=p):
            
            num[j] += num[i]
            
            dfs(j,i,edges,num)
    

N,Q = map(int,input().split())
sys.setrecursionlimit(N**2)

a=[]
b=[]

p=[]
x=[]

#隣接リスト
edges = [ [] for i in range(N)]
num = [0]*N


for i in range(N-1):
    a0,b0 = map(int,input().split())
    a.append(a0)
    b.append(b0)
    
    edges[a0-1].append(b0-1)
    edges[b0-1].append(a0-1)
    
for i in range(Q):
    p0,x0 = map(int,input().split())
    p.append(p0)
    x.append(x0)
    num[p0-1] += x0
    
dfs(0,-1, edges, num)
    
for i in range(N):
    print(num[i], end=" ")

### FIXED CODE ###

# https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
sys.setrecursionlimit(2*2*10**5)

def dfs(i,p,edges,num):
    
    for j in edges[i]:
        if(j!=p):
            
            num[j] += num[i]
            
            dfs(j,i,edges,num)
    
def input():
    return sys.stdin.readline()[:-1]

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


#隣接リスト
edges = [ [] for i in range(N)]
num = [0]*N


for i in range(N-1):
    a0,b0 = map(int,input().split())

    edges[a0-1].append(b0-1)
    edges[b0-1].append(a0-1)
    
for i in range(Q):
    p0,x0 = map(int,input().split())

    num[p0-1] += x0
    
dfs(0,-1, edges, num)
    
for i in range(N):
    print(num[i], end=" ")
import sys
input = sys.stdin.readline

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

#output
from collections import Counter
import bisect

l = Counter(A).most_common()
l = [b for a, b in l]
M = len(l)

number_of_operation = [0] * O
maximum_operation = [0] * N

ll = []
for x in reversed(range(1, N+1)):
    ll.append(sum([min(x, i) for i in l]) / x)

for K in range(M):
    maximum_operation[K] = N-bisect.bisect_left(ll, K+1)

for m in maximum_operation:
    print(m)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

#output
from collections import Counter
import bisect

l = Counter(A).most_common()
l = [b for a, b in l]
M = len(l)
l.sort()
p = sum(l)

maximum_operation = [0] * N

ll = []
for x in reversed(range(1, N+1)):
    a = bisect.bisect_left(l, x)
    if a == 0:
        b = M*x
        c = 0
    elif a >= M:
        b = 0
        c = p
    else:
        b = (M-a)*x
        c = sum(l[0:a]) 
    ll.append((b + c)/x)

for K in range(M):
    maximum_operation[K] = N - bisect.bisect_left(ll, K+1)

for m in maximum_operation:
    print(m)
s=list(input())
count = 0
for i in range(2):
    if s[i] == 1 :
        count +=1    
print(count())

### FIXED CODE ###

s=list(input())
count = 0
for i in range(3):
    if s[i] == '1':
        count = count + 1    
print(count)
# -*- coding: utf-8 -*
import sys
#if False:
if True:
    fh=open('ALDS1_1_D6.txt','r')
else:
    fh=sys.stdin
input=fh.readline

def main():
    n = int(input())
    a=[]
    for _ in range(n):
        a.append(int(input()))

    pmax=a[1]-a[0]
    for k in range(0, n-1):
        p=max(a[k+1:])-a[k] 
        if p > pmax:
            pmax=p

    print(pmax)
    
if __name__ == "__main__":
    main()



### FIXED CODE ###

# -*- coding: utf-8 -*
import sys
if False:
#if True:
    fh=open('ALDS1_1_D1.txt','r')
else:
    fh=sys.stdin
input=fh.readline

def main():
    n = int(input())
    a=[]
    for _ in range(n):
        a.append(int(input()))

    pmax=a[1]-a[0]
    pmin=a[0]
    for j in range(1, n):
        pmax = max(a[j]-pmin,pmax)
        pmin = min(pmin,a[j])

    print(pmax)
    
if __name__ == "__main__":
    main()
n=input()
b=list(map(int , input().slice()))
c=1
for i in b:
  c=c*i
if c>10**18:
  print(-1)  
else:
  print(c)

### FIXED CODE ###

n=int(input())
a=list(map(int, input().split( )))
if 0 in a:
  print(0)
  
else:
    c=1
    for i in a:
        c= c*i
        if c> 10**18:
            c=-1
            break
    print(c)
n=int(input())
while (n != 0):
  sum = sum + n % 10; 
  n = n/10; 
if(sum%9==0):
  print("Yes")
else:
  print("No)    
     
    

### FIXED CODE ###

n=str(input())
sum=0
for i in range(len(n)):
    sum+=int(n[i]); 
if(sum%9==0):
  print("Yes")
else:
  print("No")
import bisect
n = int(input())

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

count = 0

for i in range(n-2):
	for j in range(i+1, n-1):
    	bi = bisect.bisect_left(li, li[i] + li[j])
    	count += bi - j - 1
print(count)

### FIXED CODE ###

import bisect
n = int(input())

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

count = 0

for i in range(n - 2):
  for j in range(i + 1, n - 1):
    bi = bisect.bisect_left(li, li[i] + li[j])
    count += bi - j - 1
print(count)
import sys

N = int(input())
nums = list(map(int, input().split(' ')))

output = 1

if 0 in nums:
  print(0)
  sys.exit()
  
else:
  for x in nums:
    output *= x

    if output > 10**18:s
      print('-1')
      sys.exit()

  print(output)

### FIXED CODE ###

import sys

N = int(input())
nums = list(map(int, input().split(' ')))

output = 1

if 0 in nums:
  print(0)
  sys.exit()
  
else:
  for x in nums:
    output *= x

    if output > 10**18:
      print(-1)
      sys.exit()

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

if A in 0:
    print(0)
    exit()

prod = 1
for i in range(len(A)):
    prod *= A[i]
    if prod > 10 ** 18:
        print(-1)
        exit()

print(prod)

### FIXED CODE ###

N = input()
A = list(map(int, input().split()))
 
if 0 in A:
    print(0)
    exit()
 
A = sorted(A)[::-1]
val = 1
 
for a in A:
    val *= a
    if val > 10 ** 18:
        print(-1)
        exit()
print(val)
N, a, b = map(int, input().split())

sum = pow(2, N)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
X = 2 * 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, X + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ax = cmb(N, a, mod)
bx = cmb(N, b, mod)

print((sum - ax - bx - 1)%(10**9+7))

### FIXED CODE ###

N, a, b = map(int, input().split())

MOD = 10**9+7

def modcmb(n, r, m):
    x = 1
    y = n
    for i in range(2,r+1):
        x *= i
        x %= MOD
        y *= n-i+1
        y %= MOD
    return y * pow(x, m-2, m) % m

ans = pow(2, N, MOD) - modcmb(N, a, MOD) - modcmb(N, b, MOD) - 1
print(ans % MOD)
d,n = map(int,input())

if d == 0:
  print(n)
elif d == 1:
  print(100*n)
elif d == 2:
  print(10000*n)

### FIXED CODE ###

d,n = map(int,input().split())
 
if d == 0:
  if n == 100:
    print(101)
  else:
    print(n)
elif d == 1:
  if n == 100:
    print(10100)
  else:
    print(100*n)
elif d == 2:
  if n == 100:
    print(1010000)
  else:
    print(10000*n)
str = input()
l = []
while str != "0 0":
    l.append(str)
    str = input()

for i in range(len(l)):
    numl = l[i].split(' ')
    a = int(numl[0])
    b = int(numl[1])
    sum = a + b
    digitstr = "{0}".format(sum)
    print(len(digitstr))

### FIXED CODE ###

import sys
l = []
for line in sys.stdin:
    l.append(line)

for i in range(len(l)):
    numl = l[i].split(' ')
    a = int(numl[0])
    b = int(numl[1])
    sum = a + b
    digitstr = "{0}".format(sum)
    print(len(digitstr))
k=int(input())
ans=2
s_1=7%k
s_2=10%k
m=0
j=0
if k%2==0 or k%5==0:
  print(-1)
elif k==1 or k==7:
  print(1)
elif k%7==0:
  l=9*k/7
  s=10%l
  while j==0:
    m=(m+s_1*(s-1))%l
    if m==0:
      j==1
    else:
      ans+=1
      s=(s*10)%l
  print(ans)
else:
  l=9*k
  i=0
  while j==0:
    m=(m+s_1*(s-1))%l
    if m==0:
      j==1
    else:
      ans+=1
      s=(s*10)%l
  print(ans)


### FIXED CODE ###

k=int(input())
m=0
for i in range(k):
  m=(m*10+7)%k
  if m==0:
    break
  elif i==k-1:
    print(-1)
    exit()
print(i + 1)
N, X = map(int, input().split())
L = list(map(int, input().split()))
d = 0
for i in range(1, N + 2):
    d += L[i - 1]
    if d > X:
        print(i)
        exit()

### FIXED CODE ###

N, X = map(int, input().split())
L = list(map(int, input().split()))
d = 0
if L[0] > X:
    print(0)
for i in range(1, N + 1):
    d += L[i - 1]
    if d > X:
        print(i)
        exit()
print(N + 1)
N,Q = map(int,input().split())
S = input()

AC_list = [0]*N
for i in range(N):
    if S[i:i+2] == "AC":
        AC_list[i] = AC_list[i-1]+1
    else:
        AC_list[i] = AC_list[i-1]

for i in range(Q):
    l, r = map(int,input().split())
    print(ans[r-1]-ans[l-2])

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()

AC_list = [0]*(N+1)
for i in range(N):
    if S[i:i+2] == "AC":
        AC_list[i+1] = AC_list[i]+1
    else:
        AC_list[i+1] = AC_list[i]

for i in range(Q):
    l, r = map(int,input().split())
    print(AC_list[r-1]-AC_list[l-1])
S = int(input())
W = int(input())
print('unsafe') if W>= S else print('safe')

### FIXED CODE ###

S, W = map(int, input().split())
print('unsafe') if W>= S else print('safe')
N, A, B = map(int, input().split())

balls = ""

while len(balls) < N:
  balls += "b"*A + "r"*B

print(len(balls[0:N].replace("r","")))

### FIXED CODE ###

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

a = N//(A + B)
b = N%(A + B)

if A <= b:
  print(a*A + A)
else:
  print(a*A + b)
A=int(input(" enter no of apples")
P=int(input(" enter no of peices ")
n=A*3
pe=n+P
apple=pe//2
print(apple)



### FIXED CODE ###

A, P = map(int, input().split())
P += A * 3
print(int(P / 2))
a, b = input().split()
ans = -1
if a < 10 and b < 10:
    ans = a * b
print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
ans = -1
if a < 10 and b < 10:
    ans = a * b
print(ans)
import math

a,b,h,m=map(int,input().split())
deg=abs(h*30+m*0.5)-(m*6)
if deg>=180:
 deg=360-deg
c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.pi*deg/180))
print(c)

### FIXED CODE ###

N = int(input())
n = N % 10

if n == 3:
    print('bon')
elif n in [0, 1, 6, 8]:
    print('pon')
else:
    print('hon')
import sys
r=sys.stdin.readline
for e in iter(r,'0'):
 R=[[]for _ in[0]*-~int(e)]
 for _ in[0]*int(r()):
  a,b=map(int,r().split())
  R[a]+=[b];R[b]+=[a]
 for m in R[1][:]:R[1]+=R[m]
 print(len({*R[1]}-{1}))


### FIXED CODE ###

def s():
 import sys
 r=sys.stdin.readline
 for e in iter(r,'0\n'):
  R=[[]for _ in[0]*-~int(e)]
  for _ in[0]*int(r()):
   a,b=map(int,r().split())
   R[a]+=[b];R[b]+=[a]
  for m in R[1][:]:R[1]+=R[m]
  print(len({*R[1]}-{1}))
s()
A=int(input("A"))
B=int(input("B"))
print(A*B)

### FIXED CODE ###

a,b=(int(x) for x in input().split())
print(a*b)
N,K =[int(i) for i in input().split(' ')]

A = [int(i) for i in input().split(' ' )]
index_1 = -1

for i in range(len(A)):
    #print(index_1)
    if A[i]==1:
        index_1 = i
        break

ans = 0
if index_1%(K-1)==0:
    ans += index_1 // (K-1)
else:
    ans += index_1 //(K-1) + 1

if (N-index_1 -1)%(K-1)==0:
    ans += (N - index_1-1) // (K-1)
else:
    ans += (N - index_1 -1) //(K-1) + 1
    
print(ans)


### FIXED CODE ###

S = input()
ans =0
for i in S:
    if i=='+':
        ans +=1
    else:
        ans-=1

print(ans)
import math
N=int(input())
engines = tuple((complex(*map(int, input().split())) for _ in range(N)))
engines = sorted(list((engine, math.atan2(engine.imag, engine.real))for engine in engines if engine != 0), key=lambda x:x[1])
N=len(engines)
if N == 0:
    print(0)
else:
    total = sum(engine[0] for engine in engines)
    head_index = max(i if engines[i][0].imag < 0 else -1 for i in range(N))
    tail_index = 0
    tmp = sum(engines[i][0] for i in range(tail_index,head_index+1))
    maximum = max(abs(tmp), abs(total - tmp))

    while True:
        if head_index < N-1:
            if (engines[head_index+1]/engines[tail_index]).imag >= 0:
                head_index += 1
            else:
                tail_index += 1
        else:
            if (engines[0]/engines[tail_index]).imag < 0:
                tail_index += 1
            else:
                break
        tmp = sum(engines[i][0] for i in range(tail_index,head_index+1))
        maximum = max(maximum, abs(tmp), abs(total - tmp))

    print(maximum)

### FIXED CODE ###

import math
N=int(input())
engines = tuple((complex(*map(int, input().split())) for _ in range(N)))
engines = sorted(list((engine, math.atan2(engine.imag, engine.real))for engine in engines if engine != 0), key=lambda x:x[1])
N=len(engines)
if N == 0:
    print(0)
else:
    total = sum(engine[0] for engine in engines)
    head_index = max(i if engines[i][0].imag < 0 else -1 for i in range(N))
    tail_index = 0
    tmp = sum(engines[i][0] for i in range(tail_index,head_index+1))
    maximum = max(abs(tmp), abs(total - tmp))

    while True:
        if head_index < N-1:
            if (engines[head_index+1][0]/engines[tail_index][0]).imag >= 0:
                head_index += 1
            else:
                tail_index += 1
        else:
            if (engines[0][0]/engines[tail_index][0]).imag < 0:
                tail_index += 1
            else:
                break
        tmp = sum(engines[i][0] for i in range(tail_index,head_index+1))
        maximum = max(maximum, abs(tmp), abs(total - tmp))

    print(maximum)
A = map(int, input())
A = sorted(A)
ans = 0
for i in range(1, 3):
    ans += abs(A[i - 1] - A[i])
print(ans)


### FIXED CODE ###

A = map(int, input().split())
A = sorted(A)
ans = 0
for i in range(1, 3):
    ans += abs(A[i - 1] - A[i])
print(ans)
from math import factorial
from scipy.special import comb
x,y = map(int, input().split())

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res % (10**9+7))


### FIXED CODE ###

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

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0 or y / x < 1/2 or y/x > 2:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res)
r = int(input());g = int(input());print(2*G-r)

### FIXED CODE ###

r = int(input());g = int(input());print(2*g-r)
from sys import stdin
import math

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) // 2 for x in stdin.readline().rstrip().split()]
ans = 0
g = 1

for i in range(len(A)):
    g = g * A[i] // math.gcd(g % A[i], A[i])

for i in range(len(A)):
    if (g // A[i]) % 2 == 0:
        print(0)
        exit()

ans = M // g
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + 1) // 2)


### FIXED CODE ###

from sys import stdin
import fractions

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) // 2 for x in stdin.readline().rstrip().split()]
ans = 0
g = 1

for i in range(len(A)):
    g = g * A[i] // fractions.gcd(g % A[i], A[i])
    if g > M:
        print(0)
        exit()

for i in range(len(A)):
    if (g // A[i]) % 2 == 0:
        print(0)
        exit()

ans = M // g
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + 1) // 2)
n,k=map(int,input().split())
h=list(map(int,input()split()))
c=0
for i in range(n):
  if i<=k:
    c=c+1
print(c)

### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
c=0
for i in range(n):
  if k<=h[i]:
    c=c+1
print(c)
import math

alphabets = [chr(i) for i in range(97, 97+26)]

N = int(input())

a = 0
for i in range(1, 12):
    if math.pow(26, i) >= N:
        break
    N -= int(math.pow(26, i))

ans = ''
for j in range(i):
    b = N // int(math.pow(26, i-j-1))
    if i-j != 1:
        ans += alphabets[b]
    else:
        ans += alphabets[b-1]
    N = N % int(math.pow(26, i-j-1))
print(ans)

### FIXED CODE ###

import math

alphabets = [chr(i) for i in range(97, 97+26)]

N = int(input())

def run(n):
    a = 0
    for i in range(1, 12):
        if math.pow(26, i) >= n:
            break
        n -= int(math.pow(26, i))

    ans = ''
    for j in range(i-1):
        b = n // int(math.pow(26, i-j-1))
        amari = n % int(math.pow(26, i-j-1))
        if amari == 0:
            b -= 1
        ans += alphabets[b]
        n = n % int(math.pow(26, i-j-1))
    ans += alphabets[n-1]
    return ans
    
print(run(N))
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=input().rstrip()
td=[]
for _ in range(q):
	t,d=input().split()
	td.append((t,d))
l=-1;r=n+1
while r-l>1:#l以上r未満
	mid=(l+r)//2
	now=mid
	for i in range(q):
		if s[now]==td[i][0]:
			if td[i][1]=="L":
				now-=1
			else:
				now+=1
		if not 0<=now<n:
			f=0
			break
	if now==-1:
		l=mid
	else:
		r=mid
Left=l
l=-1;r=n
while r-l>1:#l over r以下
	mid=(l+r)//2
	now=mid
	for i in range(q):
		if s[now]==td[i][0]:
			if td[i][1]=="L":
				now-=1
			else:
				now+=1
		if not 0<=now<n:
			f=0
			break
	if now==n:
		r=mid
	else:
		l=mid
Right=r
print(Right-Left-1)

### FIXED CODE ###

import sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=input().rstrip()
td=[]
for _ in range(q):
	t,d=input().split()
	td.append((t,d))
l=-1;r=n+1
while r-l>1:#l以上r未満
	mid=(l+r)//2
	now=mid
	if not 0<=now<n:
		if now==-1:
			l=mid
		else:
			r=mid
		continue
	for i in range(q):
		if s[now]==td[i][0]:
			if td[i][1]=="L":
				now-=1
			else:
				now+=1
		if not 0<=now<n:
			f=0
			break
	if now==-1:
		l=mid
	else:
		r=mid
Left=l
l=-2;r=n
while r-l>1:#l over r以下
	mid=(l+r)//2
	now=mid
	if not 0<=now<n:
		if now==n:
			r=mid
		else:
			l=mid
		continue
	for i in range(q):
		if s[now]==td[i][0]:
			if td[i][1]=="L":
				now-=1
			else:
				now+=1
		if not 0<=now<n:
			f=0
			break
	if now==n:
		r=mid
	else:
		l=mid
Right=r#Right,Leftはどこまで排除されるか
print(Right-Left-1)
import string

# 1千兆 + 1
N = int(input())
n_digits = len(str(1000000000000001))
letters = string.ascii_lowercase

x = N - 1
ans = []
# while True:
#     x -= 1
#     mod = x % 26
#     ans = [ mod ] + ans
#     x = x // 26
#     if x <= 0:
#         break

# print(ans)
# print("".join([ letters[v] for v in ans ]))

while True:
    x -= 1
    mod = x % 26
    # div = x // 26
    x = x // 26
    
    ans.append(mod)
    if div == 0:
        break

ans = ans[::-1]
print("".join([ letters[v] for v in ans ]))

### FIXED CODE ###

import string

# 1千兆 + 1
N = int(input())
n_digits = len(str(1000000000000001))
letters = string.ascii_lowercase

x = N - 1
ans = []
# while True:
#     mod = x % 26
#     ans = [ mod ] + ans
#     x = x // 26
#     if x <= 0:
#         if ans[0] == 0:
#             ans = [0] + ans
#         break

# print(ans)
# print("".join([ letters[v] for v in ans ]))

while True:
    mod = x % 26
    div = x // 26
    
    ans.append(mod)
    if div == 0:
        break
    x = div - 1

ans = ans[::-1]
# print(ans)
print("".join([ letters[v] for v in ans ]))
import fractions as fr
import copy
from functools import reduce
 
N = int(input())
yaku = [0]*N
X = input().split()
X = list(set(X))
if len(X) == 1:
    print(X[0])
    exit()
X = list(map(int, X))
 
 
def gcd_list(numbers):
    return reduce(fr.gcd, numbers)
 
 
for i in range(N):
    Xwork = copy.copy(X)
    del(Xwork[i])
    yaku[i] = gcd_list(Xwork)
 
print(max(yaku))

### FIXED CODE ###

from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
L_A = [0] * (N+1)
R_A = [0] * (N+1)
for i in range(N):
    L_A[1+i] = gcd(L_A[i], A[i])
for i in reversed(range(N)):
    R_A[i] = gcd(R_A[i+1], A[i])
print(max(gcd(L_A[i], R_A[i+1]) for i in range(N)))
n = int(input())
lis = [0] + list(map(int,input().split())) + [0]
b = 0
for i in range(n+1):
 b += abs(lis[i+1]-lis[i])
for i in range(1,n+1):
 if lis[i-1] <= lis[i] <= lis[i+1] or lis[i-1] => lis[i] => lis[i+1]:
   print(b)
 else:
  print(b-abs(lis[i-1] - lis[i]) - abs(lis[i+1] - lis[i]) + abs(lis[i+1] - lis[i-1]))

### FIXED CODE ###

n = int(input())
lis = [0] + list(map(int,input().split())) + [0]
b = 0
for i in range(n+1):
 b += abs(lis[i+1]-lis[i])
for i in range(1,n+1):
 if (lis[i-1] <= lis[i] <= lis[i+1]) or (lis[i+1] <= lis[i] <= lis[i-1]):
   print(b)
 else:
  print(b-abs(lis[i-1] - lis[i]) - abs(lis[i+1] - lis[i]) + abs(lis[i+1] - lis[i-1]))