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

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

result = []
for i in range(1, len(entry)+1):
    print(entry.index(i)+1, " ", end="")

### FIXED CODE ###

from operator import itemgetter

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

result =[]
for i in range(len(entry)):
    result.append([i+1, entry[i]])
result2 = sorted(result, key=itemgetter(1))
    
for i in range(len(result)):
    print(result2[i][0], " ", end="")
### BUGGY CODE ###

l, r = map(int, input().split())
x = []
y = []
 
for i in range(l, r):
  for j in range(i+1, r+1):
    m = i * j % 2019
    x.append(m)
    y.append(i*j)

print(min(x))

### FIXED CODE ###

l, r = map(int, input().split())
x = []

if l <= 2019 <= r:
  print(0)
elif r - l > 2018:
  print(0)
else:
  x = []
  for i in range(l, r):
    for j in range(i+1, r+1):
      m = i * j % 2019
      x.append(m) 
  print(min(x))
### BUGGY CODE ###

n = int(input())
list_A = list(map(int, input().split()))
ans = []
for i in range(n):
    ans.append(list_A[i])
    ans.reverse()

print(*ans)

### FIXED CODE ###

from collections import deque
n = int(input())
list_A = list(map(int, input().split()))
ans = deque([])
for i in range(n):
    if i % 2 == 0:
        ans.append(list_A[i])
    else:
        ans.appendleft(list_A[i])

if n % 2 == 1:
    ans.reverse()
print(*ans)
### BUGGY CODE ###

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

import numpy as np
s = list(map(int, input().split()))
N = s[0]
M = s[1]

s = [list(map(int, input().split())) for i in range(M)]

IDs = np.arange(1,N+1) # カードの番号

for i in range(M):
    IDs = IDs[s[i][0] <= IDs]
    IDs = IDs[IDs <= s[i][1]]

print(len(IDs))


### FIXED CODE ###

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

import numpy as np
s = list(map(int, input().split()))
N = s[0]
M = s[1]

s = np.array([list(map(int, input().split())) for i in range(M)])

print(max(np.min(s[:,1]) - np.max(s[:,0]) +1, 0))
### BUGGY CODE ###

from collections import deque
def main():
    N,M = map(int,input().split())
    G = [deque([]) for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    visited = [-1] * N
    stack = deque([0])
    visited[0] = 0
    sign = [0] * N
    while stack:
        v = stack[0]
        if G[v]:
            w = G[v].pop()
            if visited[w] == 1 or w in stack:
                continue
            visited[w] = 1
            sign[w] = v+1
            stack.append(w)
        else:
            stack.popleft()

    sign = sign[1:]
    if all(s > 0 for s in sign):
        print('Yes')
        for s in sign:
            print(s)
    else:
        print('No')
        
main()

### FIXED CODE ###

from collections import deque
def main():
    N,M = map(int,input().split())
    G = [deque([]) for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    stack = deque([0])
    sign = [0] * N
    while stack:
        v = stack.popleft()
        for w in G[v]:
            if sign[w] == 0:
                sign[w] = v+1
                stack.append(w)   

    sign = sign[1:]
    if all(s > 0 for s in sign):
        print('Yes')
        for s in sign:
            print(s)
    else:
        print('No')
        
main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

args = input().split()
n = int(args[0])
m = int(args[1])
ok_list = [0] * 100000
ng_dict = {}
ok_cnt = 0
ng_cnt = 0
args_results = [input().split() for i in range(m)]
for args_result in args_results:
    target = int(args_result[0])
    score = args_result[1]
    if target in ok_list:
        continue
    else:
        if score == 'AC':
            ok_list[ok_cnt] = target
            ok_cnt += 1
        else:
            if target in ng_dict:
                ng_dict[target] += 1
            else:
                ng_dict[target] = 1

for num in ok_list:
    if num in ng_dict:
        ng_cnt += ng_dict[num]

print(ok_cnt, ng_cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline

args = input().split()
n = int(args[0])
m = int(args[1])
ok = [False] * n
ng = [0] * n
for _ in range(m):
    target, score = input().split()
    target = int(target) - 1
    if score == 'AC':
        ok[target] = True
    else:
        if not ok[target]:
            ng[target] += 1

ok_cnt = 0
ng_cnt = 0
for i in range(n):
    if ok[i]:
        ok_cnt += 1
        ng_cnt += ng[i]
print(ok_cnt, ng_cnt)
### BUGGY CODE ###

import math
from collections import defaultdict
d = defaultdict(str)
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n - 1, r) + cmb(n - 1, r - 1)
    return nCr[(n, r)]


ai = a[0]
ai_fct = math.factorial(ai)
max_fct = 0
for i in range(n):
    if (i == 0):
        continue
    fct = cmb(a[0], a[i])
    d[fct] = str(ai) + ' ' + str(a[i])
    max_fct = max(max_fct, fct)

print(d[max_fct])


### FIXED CODE ###

import bisect
n = int(input())
a = sorted(map(int, input().split()))

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (i_left == i_right and i_left == 0):
    print(ai, a[0])
    exit()

if (abs(half_ai - a[i_left - 1]) >=
        abs(half_ai - a[i_right]) and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    s = input().strip()
    q = int(input())
    flg = True
    for i in range(q):
        t = input_list_str()
        if len(t) == 1:
            n = t[0]
            flg = False if flg is True else True
        else:
            n, f, c = t
            c = str(c).strip()
            if f == '1':
                if flg:
                    s = c + s
                else:
                    s = s + c
            else:
                if flg:
                    s = s + c
                else:
                    s = c + s
    if flg is False:
        s = s[::-1]
    print(s)


def bi(num, a, b, x):
    print((a * num) + (b * len(str(b))))
    if (a * num) + (b * len(str(b))) <= x:
        return False
    return True

def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  reverse_count = 0
  for i in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count = 1 - reverse_count
      continue
    q, f, c = t
    if int(f) + reverse_count == 2:
      s.append(c)
    else:
      s.appendleft(c)
  if reverse_count == 1:
    s.reverse()
  print(''.join(s))

    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()
### BUGGY CODE ###

N, M = (int(i) for i in input().split())

tiles = [[True for i in range(M + 2)] for j in range(N + 2)]
for i in range(1, N + 1):
    for j in range(1, M + 1):
        tiles[i - 1][j - 1] = not (tiles[i - 1][j - 1])
        tiles[i - 1][j] = not (tiles[i - 1][j])
        tiles[i - 1][j + 1] = not (tiles[i - 1][j + 1])
        tiles[i][j - 1] = not (tiles[i][j - 1])
        tiles[i][j] = not (tiles[i][j])
        tiles[i][j + 1] = not (tiles[i][j + 1])
        tiles[i + 1][j - 1] = not (tiles[i + 1][j - 1])
        tiles[i + 1][j] = not (tiles[i + 1][j])
        tiles[i + 1][j + 1] = not (tiles[i + 1][j + 1])

count = 0

for i in range(1, N + 1):
    for j in range(1, M + 1):
        if not tiles[i][j]:
            count = count + 1
print(count)

### FIXED CODE ###

N, M = (int(i) for i in input().split())

if N == 1 and M == 1:
    print(1)

elif N == 2 or M == 2:
    print(0)

elif N == 1 or M == 1:
    if N == 1:
        print(M - 2)
    else:
        print(N - 2)

else:
    print((N - 2) * (M - 2))
### BUGGY CODE ###

a = int(input())
aa = []
for i in range(a):
    n = input()
    if aa.count(n) == 0:
        aa.append(n)
print(len(aa))

### FIXED CODE ###

a = int(input())
aaa = set([])
for i in range(a):
    n = input()
    aaa.add(n)
print(len(aaa))
### BUGGY CODE ###

from collections import Counter as cnt
n = int(input())
s = list(input())

count = cnt(s)
num_rest = []
for i in range(n):
  count[s[i]] -= 1
  rest = 0
  for value in count.values():
    if value != 0:
      rest += 1
  num_rest.append(rest)
#print(num_rest)

checked = {}
total = 0
for i in range(n-2):
  if s[i] not in checked:
    checked[s[i]] = set()
  elif len(checked[s[i]]) == 10:
    continue
  for j in range(i+1, n-1):
    if s[j] not in checked[s[i]]:
      checked[s[i]].add(s[j])
      total += num_rest[j]
print(total)

### FIXED CODE ###

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

def search(s, c, left):
  for idx in range(left, len(s)):
    if s[idx] == c:
      return idx
  return -1

total = 0
for keta1 in range(10):
  first_keta1 = search(s, str(keta1), 0)
  if first_keta1 == -1 or first_keta1 >= n-2:
    continue
  for keta2 in range(10):
    first_keta2 = search(s, str(keta2), first_keta1 + 1)
    if first_keta2 == -1 or first_keta2 >= n-1:
      continue
    for keta3 in range(10):
      first_keta3 = search(s, str(keta3), first_keta2 + 1)
      if first_keta3 != -1:
        total += 1
print(total)
### BUGGY CODE ###

import sys
msg = sys.stdin.readlines()
a = []
for x in msg:
  a.append(x.replace('\n', ''))
arra = a[1].split(' ')
dump = []
res = 'YES'
for x in range(int(a[0])):
  if arra[x] in dump:
    res = 'NO'
  dump.append(arra[x])
print(res)



### FIXED CODE ###

import sys
msg = sys.stdin.readlines()
a = []
for x in msg:
  a.append(x.replace('\n', ''))
arra = a[1].split(' ')
arra = [int(x) for x in arra]
if len(arra) == len(set(arra)):
  print('YES')
else:
  print('NO')
### BUGGY CODE ###

import numpy as np
N,M = map(int, input().split())
H = list(map(int, input().split()))
a = np.array([list(map(int, input().split())) for i in range(M)])
c = 0
for i in range(1,N+1):
  d = 0
  b = [j for j, x in enumerate(a[:, 0]) if x== i]
  B = [j for j, x in enumerate(a[:, 1]) if x== i]
  for j in b:
    if d == 0 and H[a[j][1]-1] >= H[i-1]:
      d = 1
  for j in B:
    if d == 0 and H[a[j][0]-1] >= H[i-1]:
      d = 1
  if d == 0:
    c += 1
print(c)

### FIXED CODE ###

N,M = map(int, input().split())
H = list(map(int, input().split()))
dp = [1]*N
for i in range(M):
  A,B = map(int, input().split())
  if H[A-1] <= H[B-1]:
    dp[A-1] = 0
  if H[B-1] <= H[A-1]:
    dp[B-1] = 0
print(dp.count(1))
### BUGGY CODE ###

N = int(input())
D = list(map(int, input().split()))
ans = 0
for i in range(max(D)) :
  cnt = len(list(filter(lambda x : x <= i, D)))
  if(cnt == N // 2) :
    ans += 1
  else :
    pass
print(ans)

### FIXED CODE ###

N = int(input())
D = list(map(int, input().split()))
D.sort()
ans = 0
for i in range(N // 2) :
  cnt = len(list(filter(lambda x : x <= D[N // 2 - 1 + i], D)))
  if(cnt == N // 2) :
    ans += D[N // 2] - D[N // 2 - 1]
  elif(cnt > N // 2) :
    break
  else :
    pass
print(ans)
### BUGGY CODE ###

from itertools import permutations

def warshall_floyd(d, n):
    # d[i][j]: iからjへの最短距離
    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])
    return d

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
d = warshall_floyd(d, N)
ans = float('inf')
for perm in permutations(r):
    total = 0
    for i in range(1, len(perm)):
        total += d[perm[i-1]-1][perm[i]-1]
    ans = min(ans, total)
print(ans)


### FIXED CODE ###

from itertools import permutations


def warshall_floyd(d, n):
    # d[i][j]: iからjへの最短距離
    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])
    return d


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[float('inf')] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c

d = warshall_floyd(d, N)

ans = float('inf')
for p in permutations(r):
    total = 0
    for i in range(1, len(p)):
        total += d[p[i-1]-1][p[i]-1]
    ans = min(ans, total)
print(ans)
### BUGGY CODE ###

import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [ri() for _ in range(N)]
B = np.array(sorted(A))
C = [np.where(B == a)[0][0] for a in A]
answer = sum([i%2==1 and x%2!=1 for i, x in enumerate(C)])
print(answer)
# 41


### FIXED CODE ###

import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [ri() for _ in range(N)]
B = sorted(A)
B = set(B[1::2])
C = [i%2==1 and a not in B for i, a in enumerate(A)]
print(sum(C))
### BUGGY CODE ###

def dfs(start):
    global visit
    visiting = [start]
    while visiting:
        v = visiting.pop()
        visit[v] = True
        for v2 in g.get(v,()):
            if v2 in visit or v2 in visiting:
                continue
            visiting.append(v2)

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

visit = {}
g = {}
for v in range(1,N+1):
    g[v] = []

for _ in range(M):
    x,y,z = map(int, input().split())
    g[x].append(y)
    g[y].append(x)

count = 0
for v in range(1,N+1):
    if v in visit:
        continue
    dfs(v)
    count += 1

print(count)


### FIXED CODE ###

N, M = map(int, input().split())
graph = [[] for i in range(N)]
for i in range(M):
    x, y, z = map(int, input().split())
    x, y = x-1, y-1
    graph[x].append(y)
    graph[y].append(x)
visited = [False for i in range(N)]
def dfs(v):
    Q = []
    visited[v] = True
    Q.append(v)
    while len(Q) > 0:
        v = Q.pop()
        for u in graph[v]:
            if not visited[u]:
                visited[u] = True
                Q.append(u)

count = 0
for i in range(N):
    if not visited[i]:
        dfs(i)
        count += 1
print(count)
### BUGGY CODE ###

from collections import deque
n, m, p = map(int, input().split())
graph = [[] for _ in range(n+1)]
edge = []
for _ in range(m):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))
    edge.append((a, b, -c+p))

q = deque([])
coins = [0] * (n+1)
ban = [False] * (n+1)

for i in range(1, n+1):
    q.append(i)
    time = [-1] * (n + 1)
    time[i] = 0
    while q:
        now = q.pop()
        for node, coin in graph[now]:
            if time[node] != -1:
                continue
            time[node] = time[now] + 1
            q.append(node)
    if i != 1:
        if time[n] == -1:
            ban[i] = True
    else:
        for j in range(2, n+1):
            if time[j] == -1:
                ban[j] = True


def bellman_ford(v, e_list, start, end):
    inf = 10**9
    dist = [inf] * (v+1)
    dist[start] = 0
    for j in range(v):
        for e in e_list:
            if ban[e[1]]:
                continue
            if dist[e[1]] > e[2] + dist[e[0]]:
                dist[e[1]] = e[2] + dist[e[0]]
                if j == v-1:
                    return -1, 0
    return dist[end], 1


ans, st = bellman_ford(n, edge, 1, n)
if st:
    print(max(-ans, 0))
else:
    print(-1)


### FIXED CODE ###

from collections import deque
n, m, p = map(int, input().split())
graph = [[] for _ in range(n+1)]
edge = []
for _ in range(m):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))
    edge.append((a, b, -c+p))

q = deque([])
coins = [0] * (n+1)
ban = [False] * (n+1)

for i in range(1, n+1):
    q.append(i)
    time = [-1] * (n + 1)
    time[i] = 0
    while q:
        now = q.pop()
        for node, coin in graph[now]:
            if time[node] != -1:
                continue
            time[node] = time[now] + 1
            q.append(node)
    if i != 1:
        if time[n] == -1:
            ban[i] = True
    else:
        for j in range(2, n+1):
            if time[j] == -1:
                ban[j] = True


def bellman_ford(v, e_list, start, end):
    inf = 10**9
    dist = [inf] * (v+1)
    dist[start] = 0
    for j in range(v):
        for e in e_list:
            if ban[e[1]]:
                continue
            if dist[e[1]] > e[2] + dist[e[0]]:
                dist[e[1]] = e[2] + dist[e[0]]
                if j == v-1:
                    return -1, 0
    return dist[end], 1


ans, st = bellman_ford(n, edge, 1, n)
if st:
    print(max(-ans, 0))
else:
    print(-1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
n,m = map(int,input().split())
if abs(n-m) >= 2:
    num_dm = 0
elif abs(n-m) == 1:
    num_dm = 1
else:
    num_dm = 2
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
d_comb_num = factorial(n)
m_comb_num = factorial(m)
ans = num_dm * d_comb_num * m_comb_num
print(ans)

### FIXED CODE ###

import math
mod = 1000000007

n,m = map(int,input().split())
if abs(n-m) >= 2:
    num_dm = 0
elif abs(n-m) == 1:
    num_dm = 1
else:
    num_dm = 2
d_comb_num = math.factorial(n) % mod
m_comb_num = math.factorial(m) % mod
ans = num_dm * d_comb_num * m_comb_num
ans %= mod
print(ans)
### BUGGY CODE ###

n = int(input())
arr = map(int,raw_input().split())
arr.sort()
cnt = 0

for i in range(1,n):
	if sum(arr[:i])*2 < arr[i]:
		cnt = i

print n-cnt


### FIXED CODE ###

import numpy as np
n = int(input())

arr = map(int,raw_input().split())
arr.sort()
cs = np.cumsum(arr)

ans = 1

i = n-2
while i > -1 and cs[i] * 2 >= arr[i+1]:
	ans += 1
	i -= 1

print ans
### BUGGY CODE ###

N = int(input())
nums = [int(i) for i in input().split()]
from fractions import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
gcds = list(set(gcds))
print(gcds[-1])

### FIXED CODE ###

N = int(input())
nums = [int(i) for i in input().split()]
nums_sorted = sorted(list((set(nums))), reverse=True)
def compute_divs(n):
    divs = []
    if n == 1: return [1]
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs
ans = 1
if len(nums_sorted) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums_sorted[0])
    divs2 = compute_divs(nums_sorted[1])
    divs = sorted(list(set(divs1+divs2)))
    for i in reversed(divs):
        c= 0
        for j in nums:
            if j % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
num = int(input())
line = list(map(int,input().split()))
for i in range(1,num+1):
    number = line.count(i)
    print(number)

### FIXED CODE ###

# coding: utf-8
# Your code here!
import collections
num = int(input())
line = list(map(int,input().split()))
clist = collections.Counter(line)
for i in range (1,num+1):
    print(clist[i])
### BUGGY CODE ###

n = int(input())
s = list(map(int,input().split()))

ans = 0

for k in range(1,n):
  for c in range(1,n):
    a = (n-1) - c*k
    if a <= c:
      break
      #書き足す
    if a%c == 0 and a//c <= k:
      continue
    p = sum(s[a:a+k*c+1:c]) + sum(s[c:k*c+1:c])
    # print(a,c,k,p, sum(s[a:a+k*c+1:c]) , sum(s[c:k*c+1:c]) )
    ans = max(p,ans)
print(ans)

### FIXED CODE ###

n = int(input())
s = list(map(int,input().split()))

ans = 0

for c in range(1,n-1):
  if (n-1)%c == 0:
    p = ((n-1)//c-1)//2 
  else:
    p = (n-1)//c-1
    if p <= 0:
      break
  if p <= 0:
    continue
  m = 0
  k = 0
  for i in range(1,p+1):
    k += s[c*i] + s[n-1-c*i]
    m = max(m,k)
  ans = max(ans,m)
    
    
print(ans)
### BUGGY CODE ###

n = int(input())
x = int(input(),2)

def popcount(n):
    return bin(n).count("1")

x_pop = popcount(x)
for i in reversed(range(0,n)):
    try:
        if x&(1<<i):
            tmp_pop = x_pop - 1
        else:
            tmp_pop = x_pop + 1
        tmp = (x^(1<<i)) % tmp_pop
        if tmp <= 0:
            print(1)
            continue
        cnt = 2
        tmp2 = tmp % popcount(tmp)
        while tmp2 > 0:
            tmp = tmp2
            cnt += 1
            tmp2 %= popcount(tmp2)
        print(cnt)
    except:
        print(0)

### FIXED CODE ###

n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
### BUGGY CODE ###

def main():
    from collections import namedtuple

    Q = namedtuple('Q', 'char drc')

    def binary_search(ng, ok):
        def is_ok(mid):
            """落下するならTrue"""
            for q_ in qs:
                if s[mid] == q_.char:
                    mid += q_.drc
                    if mid < 0 or mid >= n:
                        return True
            return False

        while abs(ng - ok) > 1:
            mid = (ng + ok) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    n, q = map(int, input().split())
    s = input()

    qs = []
    for _ in range(q):
        t, d = input().split()
        d = -1 if (d == 'L') else 1
        qs.append(Q(char=t, drc=d))
        # char:指定マス文字,英大文字
        # drc:方向,L=-1,R=1

    mid = n // 2
    left = binary_search(ng=mid + 1, ok=-1)  # okを返すので、最大mid
    right = binary_search(ng=mid, ok=n)  # okを返すので、最小mid+1
    # ok=落下する境目（落下側）
    # oolxxxroo -> r-1-l=6-1-2=3=xの個数
    # 012345678

    print(right - 1 - left)


if __name__ == '__main__':
    main()


### FIXED CODE ###

"""https://atcoder.jp/contests/exawizards2019/submissions/4769434
左右どちらから消滅するか確認が必要だと気づかされた"""


def get_pos(index):
    """初期位置indexのロボットのクエリ後の配置を返す
    is_whick_sideの返り値として返す"""
    iws = -1 if index == -1 else 1 if index == N else 0
    if iws != 0:
        return iws
    for t, d in e:
        if t == s[index]:
            if d == 'R':
                index += 1
            else:
                index -= 1
        iws = -1 if index == -1 else 1 if index == N else 0
        if iws != 0:
            return iws
    return 0


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

e = [input().split() for _ in range(Q)]
# t: 文字 <- siと比較
# d: 'L', 'R'

# right
left = -1
right = N
while right - left > 1:
    mid = (left + right) // 2
    if get_pos(mid) == 1:
        # 右消滅
        right = mid
    else:
        left = mid
ar = right
# 右消滅開始位置

# left
left = -1
right = N
while right - left > 1:
    mid = (left + right) // 2
    if get_pos(mid) == -1:
        left = mid
    else:
        right = mid
al = left
# 左消滅開始位置
# (al, ar) = 残存区間

print((ar - 1) - (al + 1) + 1)