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

N = int(input())
A_LIST = []

for _ in range(N):
    A = int(input())
    A_LIST.append(A)

for i in range(N):
    temp = A_LIST[i]
    A_LIST[i] = 0
    print(max(A_LIST))
    A_LIST[i] = temp


### FIXED CODE ###

N = int(input())
A_LIST = []

for _ in range(N):
    A = int(input())
    A_LIST.append(A)

sorted_A_LIST = sorted(A_LIST)
largest = sorted_A_LIST[-1]
second_largest = sorted_A_LIST[-2]

for i in range(N):
    if A_LIST[i] < largest:
        print(largest)
    else:
        print(second_largest)
### BUGGY CODE ###

import sys, itertools
f = sys.stdin

def take2(iterable):
    i = iter(iterable)
    while True:
        yield next(i), next(i)

n = int(f.readline())
adj =[[(v, c) for v, c in take2(map(int, f.readline().split()[2:]))] for _ in range(n)]
d = [100000 * 100 + 1] * n

d[0] = 0
queue =[0]
while len(queue):
    parent = queue.pop()
    for v, c in adj[parent]:
        if d[v] > d[parent] + c:
            d[v] = d[parent] + c
            queue.append(v)

for i in range(n):
    print(i, d[i])

### FIXED CODE ###

import sys, itertools
f = sys.stdin

def take2(iterable):
    i = iter(iterable)
    while True:
        yield next(i), next(i)

n = int(f.readline())
adj =[[(v, c) for v, c in take2(map(int, f.readline().split()[2:]))] for _ in range(n)]
d = [100000 * 100 + 1] * n

d[0] = 0
queue ={0}
while len(queue):
    parent = queue.pop()
    for v, c in adj[parent]:
        if d[v] > d[parent] + c:
            d[v] = d[parent] + c
            queue.update([v])

for i in range(n):
    print(i, d[i])
### BUGGY CODE ###

[N,L] = [int(x) for x in input().split()]
A = {}
ANS = [10**9+1]*N
count = 0
for i,x in enumerate(input().split()):
    i = int(i)
    x = int(x)
    if x in A : A[x] += [i]
    else : A[x] = [i]

for i in sorted(A) :
    for j in A[i] :
        for k in range(L) :
            try :
                if ANS[j+k] == 10**9+1 : 
                    ANS[j+k] = i
                    count += 1
            except IndexError : continue
    if count == N : break
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 ###

k, s = [int(i) for i in input().split()]

cnt = 0
for x in range(k+1):
	for y in range(k+1):
		for z in range(k+1):
			if x + y + z == s:
				cnt += 1
    
print(cnt)


### FIXED CODE ###

k, s = [int(i) for i in input().split()]

cnt = 0
for x in range(k+1):
	for y in range(k+1):
		z = s - x - y
		if 0 <= z and z <= k:
				cnt += 1
    
print(cnt)
### BUGGY CODE ###

# 2019/09/05

n=int(input())
*a,mx=sorted(map(int,input().split()))

def cmb(n):
    fac=[1,1]
    for i in range(2,n+1):
        fac.append(fac[i-1]*i)
    return fac


fac=cmb(mx)
res=0
ans=[]

for r in a:
    tmp=fac[mx]//(fac[r]*fac[mx-r])
    if tmp>res:
        res=tmp
        ans=[mx,r]
print(*ans)

### FIXED CODE ###

# 2019/09/06

from bisect import bisect_left

n=int(input())
*a,mxv=sorted(list(map(int,input().split())))

mid=mxv//2

r=bisect_left(a,mid) 
if r>=n-1:
    r=0
l=r-1 if r else 0

ans=[mxv]

if abs(mxv/2-a[r])>abs(mxv/2-a[l]):
    ans.append(a[l])
else:
    ans.append(a[r])
print(*ans)
### BUGGY CODE ###

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

ans = [str(A.index(i + 1) + 1) for i in range(N)]

print(' '.join(ans))

### FIXED CODE ###

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

ans = [0] * N
for i, a in enumerate(A):
    ans[a - 1] = (i + 1) 

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

S = list(input())
Q = int(input())
rev = False

for i in range(Q):
    X = list(input().split(" "))
    if X[0] == "1" and rev is False:
        rev = True
    elif X[0] == "1" and rev is True:
        rev = False
    elif X[0] == "2" and X[1] == "1" and rev is False:
        S.insert(0, X[2])
    elif X[0] == "2" and X[1] == "1" and rev is True:
        S.append(X[2])
    elif X[0] == "2" and X[1] == "2" and rev is False:
        S.append(X[2])
    elif X[0] == "2" and X[1] == "2" and rev is True:
        S.insert(0, X[2])

if rev is True:
    S.reverse()

print(*S, sep="")


### FIXED CODE ###

S = list(input())
Q = int(input())
rev = False
F = []

for i in range(Q):
    X = list(input().split(" "))

    if X[0] == "1" and rev is False:
        rev = True
    elif X[0] == "1" and rev is True:
        rev = False
    elif X[0] == "2" and X[1] == "1" and rev is False:
        F.append(X[2])
    elif X[0] == "2" and X[1] == "1" and rev is True:
        S.append(X[2])
    elif X[0] == "2" and X[1] == "2" and rev is False:
        S.append(X[2])
    elif X[0] == "2" and X[1] == "2" and rev is True:
        F.append(X[2])

F.reverse()
F.extend(S)

if rev is True:
    F.reverse()

print(*F, sep="")
### BUGGY CODE ###

import math
import sys
sys.setrecursionlimit(1000000)

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

memo = {}
def sub_max(n, m):
    if((n, m) in memo):
        return memo[(n, m)]
    
    if(m == 1 and n >= 1):
        memo[(n, m)] = max(A[-n:])
        return memo[(n, m)]

    if(m >= n):
        memo[(n, m)] = -float('inf')
        return -float('inf')
    
    res = -float('inf')
    for i in range(3):
        res = max(res, A[-n + i] + sub_max(n - i - 2, m - 1))
    memo[(n, m)] = res
    return res

print(sub_max(N, N//2))

### FIXED CODE ###

import math
import sys
sys.setrecursionlimit(1000000)

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

memo = {}
def sub_max(n, m):
    if((n, m) in memo):
        return memo[(n, m)]
    
    if(m == 1 and n >= 1):
        memo[(n, m)] = max(A[-n:])
        return memo[(n, m)]

    if(m > math.ceil(n/2)):
        memo[(n, m)] = -float('inf')
        return -float('inf')
    
    res = -float('inf')
    for i in range(3):
        res = max(res, A[-n + i] + sub_max(n - i - 2, m - 1))
    memo[(n, m)] = res
    return res

print(sub_max(N, N//2))
# print(memo)
### BUGGY CODE ###

def main():
  import itertools
  N = int(input())
  S = input()
  S = list(S)
  L = set()
  for i, j, k in itertools.combinations(S,3):
    L.add(i + j + k)
  print(len(L))
main()

### FIXED CODE ###

def main():
  N = int(input())
  S = list(map(int,input()))
  ans = 0
  for i in range(10):
    for j in range(10):
      for k in range(10):
        flg = False
        flg2 = False
        for x in range(N):
          if flg2:
            break
          if not flg:
            if S[x] == i:
              flg = True
          else:
            if S[x] == j:
              flg2 = True
              if k in S[x+1:]:
                ans +=1
  print(ans)
main()
### BUGGY CODE ###

def abc075_d():
    n, k = map(int, input().split())
    P = []
    xarr = []
    yarr = []
    for _ in range(n):
        x, y = (int(x) for x in input().split())
        P.append((x, y))
        xarr.append(x)
        yarr.append(y)
    xarr.sort()
    yarr.sort()

    def count_inside(xi, xj, yi, yj)->int:
        res = 0
        for x, y in P:
            if xi <= x and x <= xj and yi <= y and y <= yj:
                res += 1
        return res

    ans = 5*10**18
    for s, xi in enumerate(xarr):
        for xj in xarr[s+1:]:
            for t, yi in enumerate(yarr):
                for yj in yarr[t+1:]:
                    if count_inside(xi, xj, yi, yj) >= k:
                        area = (xj - xi) * (yj - yi)
                        ans = min(ans, area)
    print(ans)

if __name__ == '__main__':
    abc075_d()

### FIXED CODE ###

def abc075_d():
    n, k = map(int, input().split())
    P = []
    xarr = []
    yarr = []
    for _ in range(n):
        x, y = (int(x) for x in input().split())
        P.append((x, y))
        xarr.append(x)
        yarr.append(y)
    xarr.sort()
    yarr.sort()

    def count_inside(xi, xj, yi, yj)->int:
        res = 0
        for x, y in P:
            if xarr[xi] <= x and x <= xarr[xj] and yarr[yi] <= y and y <= yarr[yj]:
                res += 1
        return res

    ans = 5*10**18
    for xi in range(n-1):
        for xj in range(xi+1, n):
            for yi in range(n-1):
                for yj in range(yi+1, n):
                    if count_inside(xi, xj, yi, yj) >= k:
                        area = (xarr[xj] - xarr[xi]) * (yarr[yj] - yarr[yi])
                        ans = min(ans, area)
    print(ans)

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

from collections import defaultdict 
import sys
import heapq

sys.setrecursionlimit(10**8)

#N:頂点数   M:辺数
N,M,s,t = map(int,input().split())


#root[n] -> nからいけるlist
roots = defaultdict(set)

#weight[a] = start -> a のコスト 未探索->-1
weight_yen = [-1 for i in range(N+1)]
weight_snu = [-1 for i in range(N+1)]
weight_yen[s] = 0
weight_snu[t] = 0


for i in range(M):
	u,v,a,b = list(map(int,input().split())) #

	roots[u].add((v,a,b))
	roots[v].add((u,a,b))
		
	
def search_yen (n,w_0): #nから更新 w_0:確定コスト
	global weight_yen
		
	for root in list(roots[n]):
		i = root[0]
		w = w_0 + root[1]
		if weight_yen[i] == -1 or weight_yen[i] > w: #未探索orより小さい
			heapq.heappush(q, [w,i])
			weight_yen[i] = w
			
def search_snu (n,w_0): #nから更新 w_0:確定コスト
	global weight_snu
		
	for root in list(roots[n]):
		i = root[0]
		w = w_0 + root[2]
		if weight_snu[i] == -1 or weight_snu[i] > w: #未探索orより小さい
			heapq.heappush(q, [w,i])
			weight_snu[i] = w

#q = 次に探索する(確定する)もの q[0]=[w,n]
q = [[0,s]]
heapq.heapify(q)
			
while q:
	w,n = heapq.heappop(q)
	search_yen(n,w)
	
heapq.heappush(q, [0,t])
	
while q:
	w,n = heapq.heappop(q)
	search_snu(n,w)
	

finalans = float('inf')
ans_li = []

for i in range(0,N):
	ans = weight_yen[N-i] + weight_snu[N-i]
	finalans = min(finalans, ans)
	ans_li.append(finalans)
	
for i in range(N):
	print(10**15 - ans_li[N-i-1])


### FIXED CODE ###

from collections import defaultdict 
import sys
import heapq

sys.setrecursionlimit(10**8)

#N:頂点数   M:辺数
N,M,s,t = map(int,input().split())


#root[n] -> nからいけるlist
roots = defaultdict(set)

#weight[a] = start -> a のコスト 未探索->-1
weight_yen = [-1 for i in range(N+1)]
weight_snu = [-1 for i in range(N+1)]
weight_yen[s] = 0
weight_snu[t] = 0


for i in range(M):
	u,v,a,b = list(map(int,input().split())) #

	roots[u].add((v,a,b))
	roots[v].add((u,a,b))
		
	
def search_yen (n,w_0): #nから更新 w_0:確定コスト
	global weight_yen
		
	for root in list(roots[n]):
		i = root[0]
		w = w_0 + root[1]
		if weight_yen[i] == -1 or weight_yen[i] > w: #未探索orより小さい
			heapq.heappush(q, [w,i])
			weight_yen[i] = w
			
def search_snu (n,w_0): #nから更新 w_0:確定コスト
	global weight_snu
		
	for root in list(roots[n]):
		i = root[0]
		w = w_0 + root[2]
		if weight_snu[i] == -1 or weight_snu[i] > w: #未探索orより小さい
			heapq.heappush(q, [w,i])
			weight_snu[i] = w

#q = 次に探索する(確定する)もの q[0]=[w,n]
q = [[0,s]]
heapq.heapify(q)
			
while q:
	w,n = heapq.heappop(q)
	search_yen(n,w)
	
heapq.heappush(q, [0,t])
	
while q:
	w,n = heapq.heappop(q)
	search_snu(n,w)
	

finalans = float('inf')
ans_li = []

for i in range(0,N):
	ans = weight_yen[N-i] + weight_snu[N-i]
	finalans = min(finalans, ans)
	ans_li.append(finalans)
	
for i in range(N):
	print(10**15 - ans_li[N-i-1])
### BUGGY CODE ###

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

total = 0


for i in range(N):
    if P_i[i] <= min(P_i[0:i + 1]) :
        total += 1


print(total)


### FIXED CODE ###

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

total = 0

equi = P_i[0]

for i in range(N):
    if equi >= P_i[i]:
        total += 1
        equi = P_i[i]

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

import sys
import numpy as np

sys.setrecursionlimit(5000)
input=sys.stdin.readline

N, T = [int(a) for a in input().split()]
time = np.full(N + 1, -1, dtype = np.int32)
value = np.full(N + 1, -1, dtype = np.int32)
for i in range(1, N + 1):
    time[i], value[i] = [int(a) for a in input().split()]

# Sort the array in the increasing order of value
time = time[np.argsort(value)]
value.sort()

# table for knapsack problem
# maximum possible time is T-1
dp_table = {}

def knapsack(n, t):
    '''
    Input: n ... the number of elements to choose from
                 n means items 1, 2, ..., n can be chosen
           t ... time limit
    Output: total value
    '''
    if n <= 0 or t <= 0:
        return 0
    elif (n, t) in dp_table:
        return dp_table[(n, t)]
    elif time[n] > t:
        ans = knapsack(n-1, t)
    else:
        ans = max(knapsack(n-1, t), value[n] + knapsack(n-1, t - time[n]))

    dp_table[(n, t)] = ans
    return ans

def all_you_can_eat(n, t):
    if n <= 0 or t <= 0:
        return 0
    else:
        # Eat the most delicious food at the beginning
        tmp1 = value[n] + all_you_can_eat(n - 1, t - time[n])
        # Eat the most delicious food at the end
        tmp2 = value[n] + knapsack(n - 1, t - 1)
        return max(tmp1, tmp2)

print(all_you_can_eat(N, T))


### FIXED CODE ###

import sys
from operator import itemgetter

sys.setrecursionlimit(5000)
input = sys.stdin.readline


TIME = 0
VAL = 1

N, T = [int(a) for a in input().split()]
time_value = [None] * (N + 1)
time_value[0] = (-1, -1)
for i in range(1, N + 1):
    time_value[i] = tuple(int(a) for a in input().split())

# Sort the array in the increasing order of value
time_value.sort(key = itemgetter(VAL))


# T by (N + 1) table for knapsack problem
# maximum possible time is T-1
dp_table = [[-1] * T for _ in range(N + 1)]

# Fill in dp_table i.e. solve knapsack problem
for t in range(0, T):
    dp_table[0][t] = 0

for n in range(1, N + 1):
    dp_table[n][0] = 0
    for t in range(1, T):
        if time_value[n][TIME] > t:
            dp_table[n][t] = dp_table[n - 1][t]
        else:
            dp_table[n][t] = max(dp_table[n - 1][t],
                             time_value[n][VAL] + dp_table[n - 1][t - time_value[n][TIME]])


val_acum = time_value[N][VAL]
t = T - 1
max_val = val_acum + dp_table[N - 1][t]

for n in range(N - 1, 0, -1):  # food to eat at the end
    val_acum += time_value[n][VAL] # value[N] + value[N-1] + ... + value[n]
    t -= time_value[n + 1][TIME] # T - 1 - (time[N] + time[N-1] + ... + time[n + 1])
    if t < 0: break
    tmp = val_acum + dp_table[n - 1][t]
    max_val = max(max_val, tmp)

print(max_val)
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join(
            '{}: {}'.format(r, self.members(r)) for r in self.roots())

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

uf = UnionFind(N)

for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)

max_num = 0
for val in uf.all_group_members().values():
    max_num = max(max_num, len(val))
print(max_num)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join(
            '{}: {}'.format(r, self.members(r)) for r in self.roots())

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

uf = UnionFind(N)

for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)

# print(uf.roots())

max_num = 0
for root in uf.roots():
    max_num = max(max_num, uf.size(root))
print(max_num)
### BUGGY CODE ###

def e_bomber():
    from collections import defaultdict
    H, W, M = [int(i) for i in input().split()]
    Bomb = [[int(i) - 1 for i in input().split()] for j in range(M)]

    bomb_row = [0] * H
    bomb_col = [0] * W
    bomb_pos = defaultdict(int)
    for r, c in Bomb:
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos[(r, c)] += 1

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    # 破壊できる数が最大になるような行と列の組を全探索する。
    # (行, 列) が破壊対象の上になってしまわないような組があれば、そこに置けばいい。
    # そのような組がまったくなければ、破壊対象の上に置かざるを得ない (-1 される)。
    flag = False
    for row in [r for r in range(H) if bomb_row_max == bomb_row[r]]:
        for col in [c for c in range(W) if bomb_col_max == bomb_col[c]]:
            if bomb_pos[(row, col)] == 0:
                return bomb_row_max + bomb_col_max
    return bomb_row_max + bomb_col_max - 1

print(e_bomber())


### FIXED CODE ###

def e_bomber():
    import sys
    input = sys.stdin.readline

    H, W, M = [int(i) for i in input().split()]

    bomb_row = [0] * H
    bomb_col = [0] * W
    bomb_pos = set()
    for _ in range(M):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos.add((r, c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)
    row_index_list = [r for r, v in enumerate(bomb_row) if v == bomb_row_max]
    col_index_list = [c for c, v in enumerate(bomb_col) if v == bomb_col_max]

    # 破壊できる数が最大になるような行と列の組を全探索する。
    # (行, 列) が破壊対象の上になってしまわないような組があれば、そこに置けばいい。
    # そのような組がまったくなければ、破壊対象の上に置かざるを得ない (-1 される)。
    for row in row_index_list:
        for col in col_index_list:
            if (row, col) not in bomb_pos:
                return bomb_row_max + bomb_col_max
    return bomb_row_max + bomb_col_max - 1

print(e_bomber())
### BUGGY CODE ###

H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
C = {(i,j):[0,0] for i in range(H) for j in range(W)}
for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j]=="#":
            cnt = 0
        else:
            C[(i,j)][0] = cnt+1
            cnt += 1
    for i in range(H-2,-1,-1):
        C[(i,j)][0] = max(C[(i,j)][0],C[(i+1,j)][0])
for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j]=="#":
            cnt = 0
        else:
            C[(i,j)][1] = cnt+1
            cnt += 1
    for j in range(W-2,-1,-1):
        C[(i,j)][1] = max(C[(i,j)][1],C[(i,j+1)][1])
cmax = 0
for i in range(H):
    for j in range(W):
        cmax = max(cmax,sum(C[(i,j)]))
print(cmax-1)

### FIXED CODE ###

H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if j==0 and S[i][j]==".":
            L[i][j] = 1
        elif j>0 and S[i][j]==".":
            L[i][j] = L[i][j-1]+1
        if i==0 and S[i][j]==".":
            U[i][j] = 1
        elif i>0 and S[i][j]==".":
            U[i][j] = U[i-1][j]+1
for i in range(H-1,-1,-1):
    for j in range(W-1,-1,-1):
        if j==W-1 and S[i][j]==".":
            R[i][j] = 1
        elif j<W-1 and S[i][j]==".":
            R[i][j] = R[i][j+1]+1
        if i==H-1 and S[i][j]==".":
            D[i][j] = 1
        elif i>0 and S[i][j]==".":
            D[i][j] = D[i+1][j]+1
cmax = 0
for i in range(H):
    for j in range(W):
        cmax = max(cmax,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(cmax)
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
indices = {}
for i in range(n):
    indices.setdefault(s[i], [])
    indices[s[i]].append(i)
g = [1 for _ in range(n)]
tds = []
for _ in range(q):
    tds.append(tuple(input().split()))
for t, d in tds:
    for i in indices.get(t, []):
        if d == 'L':
            if i != 0:
                g[i-1] += g[i]
        else:
            if i != n-1:
                g[i+1] += g[i]
        g[i] = 0
print(sum(g))

### FIXED CODE ###

import sys
def vanish_on_left(i, n, s, tds):
    for t, d in tds:
        if s[i] != t:
            continue
        if d == 'L':
            if i == 0:
                return True
            i -= 1
        else:
            if i == n-1:
                return False
            i += 1
    return False

def vanish_on_right(i, n, s, tds):
    for t, d in tds:
        if s[i] != t:
            continue
        if d == 'L':
            if i == 0:
                return False 
            i -= 1
        else:
            if i == n-1:
                return True
            i += 1
    return False


n, q = map(int, input().split())
s = input()
tds = []
for _ in range(q):
    tds.append(tuple(input().split()))
if vanish_on_left(0, n, s, tds):
    if vanish_on_left(n-1, n, s, tds):
        print(0)
        sys.exit()
    l0, r0 = 1, n-1
    while l0 < r0:
        k = (l0 + r0) // 2
        if vanish_on_left(k, n, s, tds):
            l0 = k+1
        else:
            r0 = k
else:
    l0 = 0
if vanish_on_right(n-1, n, s, tds):
    if vanish_on_right(l0, n, s, tds):
        print(0)
        sys.exit()
    l1, r1 = l0, n-2
    while l1 < r1:
        k = (l1 + r1 + 1) // 2
        if vanish_on_right(k, n, s, tds):
            r1 = k-1
        else:
            l1 = k
else:
    l1 = n-1
print(l1 - l0 + 1)
### BUGGY CODE ###

s = input()
dp = [0] * 13
dp[0] = 1
for c in s:
    old = dp.copy()
    for i in range(13):
        dp[i] = 0
    if c == '?':
        for n in range(10):
            for i in range(13):
                dp[(i * 10 + n) % 13] += old[i]
    else:
        n = int(c)
        for i in range(13):
            dp[(i * 10 + n) % 13] += old[i]
    for i in range(13):
        dp[i] %= 10 ** 9 + 7
print(dp[5])

### FIXED CODE ###

s = input()
dp = [0] * 13
dp[0] = 1
for c in s:
    new = [0] * 13
    if c == '?':
        for n in range(10):
            for i in range(13):
                new[(i * 10 + n) % 13] += dp[i]
    else:
        n = int(c)
        for i in range(13):
            new[(i * 10 + n) % 13] += dp[i]
    for i in range(13):
        new[i] %= 10 ** 9 + 7
    dp = new
print(dp[5])