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

import re

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

check_list = []

for i in range(0,10):
  for j in range(0,10):
    for k in range(0,10):
      check_list.append(str(i)+'.*'+str(j)+'.*'+str(k))
  
counter = 0  
for c in check_list:
  if re.findall(c, s):
    counter += 1
      
print(counter)

### FIXED CODE ###

from itertools import product

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

X = [[str(a),str(b),str(c)] for a,b,c in product(range(10), repeat=3)]
s_index = {s_i:[] for s_i in s}

for i, s_i in enumerate(s):
  s_index[s_i].append(i)

counter = 0
  
for x in X:
  ind_pos = -1
  check = True
  for x_i in x:
    if x_i not in s_index.keys():
      check = False
      break
    else:
      ind_list = [i for i in s_index[x_i] if i>ind_pos]
      if ind_list:
        ind_pos = min(ind_list)
      else:
        check = False
        break
  if check: counter += 1
    
print(counter)
### BUGGY CODE ###

MOD = 10**9 + 7
class SegTree():
    def segfunc(self, x, y):
        return x + y

    def __init__(self, ide, n, init_val):
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res

def main():
    n, m = map(int, input().split())
    s = list(map(int, input().split()))
    t = list(map(int, input().split()))
    a = [0]*m
    seg = SegTree(0, m, a)
    for i in range(n):
        x = s[i]
        for j in reversed(range(m)):
            if x == t[j]:
                y = seg.query(0, j+1)
                seg.update(j, y+1)
    print((seg.query(0, m) + 1) % MOD)

if __name__ == "__main__":
    main()

### FIXED CODE ###

MOD = 10**9 + 7
def main():
    n, m = map(int, input().split())
    s = list(map(int, input().split()))
    t = list(map(int, input().split()))
    dp = [[0]*(m+1) for _ in range(n+1)]
    for si in range(1, n+1):
        for ti in range(1, m+1):
            if s[si-1] == t[ti-1]:
                dp[si][ti] += 1
                dp[si][ti] += dp[si-1][ti-1]
            dp[si][ti] += dp[si-1][ti] + dp[si][ti-1]
            dp[si][ti] -= dp[si-1][ti-1]
            dp[si][ti] %= MOD
    print(dp[n][m] + 1)
#    for i in range(n+1):
#        print(dp[i])

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

from sys import stdin
A, B, X = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in range(A, B+1):
  if i % X == 0:
    ans += 1
print(ans)

### FIXED CODE ###

from sys import stdin
A, B, X = [int(_) for _ in stdin.readline().rstrip().split()]
print(B//X - (A-1)//X)
### BUGGY CODE ###

H,W = map(int,input().split())
S = [0]*H
for i in range(H):
    S[i] = list(input())

Hor = [0]*H
y = 0
while y != H:
    Hor[y] = []
    i = 0
    while i != W:
        if S[y][i] == ".":
            n = 0
            while i < W and S[y][i] == '.':
                i += 1
                n += 1
            Hor[y] += [n] * n
        else:
            Hor[y] += [0]
            i += 1
    y += 1

Ver = [0]*W
x = 0
while x != W:
    Ver[x] = []
    i = 0
    while i != H:
        if S[i][x] == ".":
            n = 0
            while i < H and S[i][x] == '.':
                i += 1
                n += 1
            Ver[x] += [n] * n
        else:
            Ver[x] += [0]
            i += 1
    x += 1

ans = 1
x = 0
while x != W:
    y = 0
    while y != H:
        h = Hor[y][x]
        if h:
            v = Ver[x][y]
            ans = max(ans,h+v-1)
        y += 1
    x += 1

print(ans)

### FIXED CODE ###

H,W = map(int,input().split())
S = [0]*H
for i in range(H):
    S[i] = list(input())

def aaa(s):
    i = 0
    l = len(s)
    o = []
    while True:
        if i == l:
            break
        if s[i] == ".":
            n = 0
            while i < l and s[i] == '.':
                i += 1
                n += 1
            o += [n] * n
        else:
            o += [0]
            i += 1
    return o

Hor = [0]*H
y = 0
while y != H:
    Hor[y] = aaa(S[y])
    y += 1

Ver = [0]*W
x = 0
while x != W:
    _ = 0
    s = [0] * H
    while _ != H:
        s[_] = S[_][x]
        _ += 1
    Ver[x] = aaa(s)
    x += 1

ans = 1
x = 0
while x != W:
    y = 0
    while y != H:
        h = Hor[y][x]
        if h:
            v = Ver[x][y]
            ans = max(ans,h+v-1)
        y += 1
    x += 1

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

from collections import Counter

def main():
    N = int(input())
    a = Counter(map(int, input().split()))
    a1, a2, a3 = a.get(1, 0), a.get(2, 0), a.get(3, 0)
    a123 = a1 + a2 + a3 + 1
    u = [[0.0] * (a123 - c2) for c2 in range(a123)]
    v = [[0.0] * (a123 - c2) for c2 in range(a123)]
    t1 = 0.0
    v2 = v[0]
    for c1 in range(1, a123):
        v2[c1] = t1 = N / c1 + t1
    for c2 in range(1, a123):
        v2 = v[c2]
        for c1, t2 in zip(range(301 - c2), v[c2 - 1][1:]):
            v2[c1] = t1 = (N + c1 * t1 + c2 * t2) / (c1 + c2)

    for c3 in range(1, a3 + 1):
        u, v = v, u
        v2 = v[0]
        for c1, t3 in zip(range(a123 - c3), u[1]):
            v2[c1] = t1 = (N + c1 * t1 + c3 * t3) / (c1 + c3)
        for c2 in range(1, a123 - c3):
            v2 = v[c2]
            c23 = c2 + c3
            for c1, t2, t3 in zip(range(a123 - c3 - c2), v[c2 - 1][1:], u[c2 + 1]):
                v2[c1] = t1 = (N + c1 * t1 + c2 * t2 + c3 * t3) / (c1 + c23)

    print(v[a2][a1])
main()


### FIXED CODE ###

from collections import Counter

def main():
    N = int(input())
    a = Counter(map(int, input().split()))
    a1, a2, a3 = a.get(1, 0), a.get(2, 0), a.get(3, 0)
    a123 = a1 + a2 + a3 + 1
    u = [[0.0] * (a123 - c2) for c2 in range(a123)]
    v = [[0.0] * (a123 - c2) for c2 in range(a123)]
    t1 = 0.0
    v2 = v[0]
    for c1 in range(1, a123):
        v2[c1] = t1 = N / c1 + t1
    for c2 in range(1, a123):
        v2 = v[c2]
        for c1, t2 in zip(range(301 - c2), v[c2 - 1][1:]):
            v2[c1] = t1 = (N + c1 * t1 + c2 * t2) / (c1 + c2)

    for c3 in range(1, a3 + 1):
        u, v = v, u
        v2 = v[0]
        for c1, t3 in zip(range(a123 - c3), u[1]):
            v2[c1] = t1 = (N + c1 * t1 + c3 * t3) / (c1 + c3)
        for c2 in range(1, a123 - c3):
            v2 = v[c2]
            c23 = c2 + c3
            for c1, t2, t3 in zip(range(a123 - c3 - c2), v[c2 - 1][1:], u[c2 + 1]):
                v2[c1] = t1 = (N + c1 * t1 + c2 * t2 + c3 * t3) / (c1 + c23)

    print(v[a2][a1])
main()
### BUGGY CODE ###

# coding: utf-8
# Your code here!

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

# print(n)
# print(a)

l = [0] * (n + 1)
ll  = [0] * (n + 1)
for i in range(n):
    l[a[i]] += 1
    ll[a[i]] = int((l[a[i]] * (l[a[i]] - 1)) / 2)
    
# print(l)
# print(ll)
    
for i in range(n):
    v = l[a[i]]
    vv = ll[a[i]]
    vvv = int(((v - 1) * (v - 2)) / 2)
    # print(vvv)
    print(sum(ll) - (vv - vvv))

### FIXED CODE ###

# coding: utf-8
# Your code here!

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

import collections
c = collections.Counter(a)

# print(n)
# print(a)

# l = [0] * (n + 1)
# ll  = [0] * (n + 1)

l = {}
ll = {}

# for i in range(n):
#     l[a[i]] += 1
#     ll[a[i]] = int((l[a[i]] * (l[a[i]] - 1)) / 2)
    
# print(c)
    
for key, value in c.items():
    l[key] = value
    ll[key] = int((value * (value - 1)) / 2)
    
# print(l)
# print(ll)
    
# print(l)
# print(ll)

c_sum = sum(ll.values())
for i in range(n):
    v = l[a[i]]
    vv = ll[a[i]]
    vvv = int(((v - 1) * (v - 2)) / 2)
    # print(vvv)
    print(c_sum - (vv - vvv))
### BUGGY CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				if mini < 1000000001:
					print(mini)
				else:
					print(-1)
			else:
				mini = min(kouho)
				if mini < 1000000001:
					print(mini)
				else:
					print(-1)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			cont = False
	for t in [None]*(Q-q):
		print(-1)
main()

### FIXED CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()
### BUGGY CODE ###

H, W = map(int, input().split())
s = set()
for i in range(H):
    for j, c in enumerate(input()):
        if c == '#':
            s.add((i, j))

cnt = 0
while len(s) < H * W:
    ns = set()
    for i, j in s:
        ns.add((i, j))
        if i > 0:
            ns.add((i - 1, j))
        if j > 0:
            ns.add((i, j - 1))
        if i < H - 1:
            ns.add((i + 1, j))
        if j < W - 1:
            ns.add((i, j + 1))
    s = ns
    cnt += 1
print(cnt)



### FIXED CODE ###

import sys
sys.setrecursionlimit(300000)
from collections import deque

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


H, W = MI()
grid = [list(input()) for _ in range(H)]

seen = set()
q = deque()
for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            q.append((i, j, 0))
            seen.add(i * W + j)
while len(q) > 0:
    h, w, d = q.popleft()
    for dh, dw in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
        if 0 <= h + dh < H and 0 <= w + dw < W and (h + dh) * W + w + dw not in seen:
            q.append((h + dh, w + dw, d + 1))
            seen.add((h + dh) * W + w + dw)
print(d)
### BUGGY CODE ###

n, m = map(int, input().split())

res = 0
for i in range(n):
    if m-2 > 0:
        m -= 2
        res += 1
    else:
        break

print(res+m//4)

### FIXED CODE ###

n, m = map(int, input().split())

res = 0
pair_m = m//2
if pair_m >= n:
    print(n + (m-n*2)//4)
else:
    print(pair_m)
### BUGGY CODE ###

#(方針)「whiteから最も近いblackまでの距離」の最大値を求める
import queue
import copy
#sys.stdin.readline()
import sys
input = sys.stdin.readline

H,W = map(int,input().split())
white_index = []
Map = []
Map.append(['@']*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '.'): white_index.append([i+1,j])
Map.append(['@']*(W+2))


#幅優先探索
def bfs(sy,sx,Map):
  Map_[sy][sx] = 0
  qy,qx = queue.Queue(),queue.Queue()
  qy.put(sy),qx.put(sx)
  
  count = 0
  while(1):
   if(qx.empty() == True): return ans
    
   #座標の取り出し
   y,x = qy.get(),qx.get()
   if(Map_[y][x] == '#'): #ゴールなら終了
    return count

   #if((sy == 4)and(sx == 6)):
    #for i in range(H+2): print(Map_[i])
    #print('_____________')
    
   #次に進むところ
   vec_y = [0,0,1,-1]
   vec_x = [1,-1,0,0]
   for i in range(4):
     if(Map_[y+vec_y[i]][x+vec_x[i]] == '.'):
      Map_[y+vec_y[i]][x+vec_x[i]] = Map_[y][x] + 1
      qy.put(y+vec_y[i]),qx.put(x+vec_x[i])
     elif(Map_[y+vec_y[i]][x+vec_x[i]] == '#'): #ゴールなら終了
      count = Map_[y][x] + 1
      return count      
     

ans = 0
for i in range(len(white_index)):
 sy,sx = white_index[i][0],white_index[i][1]
 Map_ = copy.deepcopy(Map) #二次元リストのコピー
 ans = max(ans,bfs(sy,sx,Map_))  
print(ans)

### FIXED CODE ###

from collections import deque

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

by,bx= deque(),deque()
Map = []
Map.append('@'*(W+2))
for i in range(H):
  c = list('@'+input()+'@')
  Map.append(c)
  for j in range(W+2):
    if(c[j] == '#'):
      Map[i+1][j] = 0
      by.append(i+1),bx.append(j)
Map.append('@'*(W+2))      

cnt = 0
while(1):
  if(len(by) == 0):
    break
   
  ny,nx = by.popleft(),bx.popleft()
  vec_y,vec_x = [1,-1,0,0],[0,0,1,-1]
  for i in range(4):
      if(Map[ny+vec_y[i]][nx+vec_x[i]] == '.'):
         Map[ny+vec_y[i]][nx+vec_x[i]] = Map[ny][nx] + 1
         cnt = max(cnt, Map[ny][nx] + 1) 
         by.append(ny+vec_y[i]),bx.append(nx+vec_x[i])
  
print(cnt)
### BUGGY CODE ###

n,a,b=map(int,input().split())
mod=10**9+7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**7
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

A=cmb(n,a,mod)
B=cmb(n,b,mod)
C=1

for i in range(n):
    C*=2%mod

r=C-1-A-B
print(r)

### FIXED CODE ###

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

a=min(a,n-a)
b=min(b,n-b)

mod=10**9+7

def modinv(n):
    return pow(n,mod-2,mod)

ra=1
for i in range(a):
    ra*=(n-i)
    ra*=modinv(i+1)
    ra%=mod

rb=1
for i in range(b):
    rb*=(n-i)
    rb*=modinv(i+1)
    rb%=mod
    
r=((2**n-1)%mod-ra-rb)%mod

print(r)
### BUGGY CODE ###

from collections import deque
import numpy as np
H,W = map(int,input().split())
Maze=[list(input()) for i in range(H)]
for hi in range(0,H):
    for wi in range(0,W):
        if Maze[hi][wi]=="#":
            continue
        maze1=[[0]*W for _ in range(H)]
        stack=deque([[hi,wi]])
        while stack:
            h,w=stack.popleft()
            for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
                new_h,new_w=h+i,w+j
                if new_h <0 or new_w <0 or new_h >=H or new_w >=W:
                    continue
                elif Maze[new_h][new_w]!="#" and maze1[new_h][new_w]==0:
                    maze1[new_h][new_w]+=maze1[h][w]
                    stack.append([new_h,new_w])
        
        maze1[hi][wi]=0
        ans=max(ans,np.max(maze1))
print(ans)

### FIXED CODE ###

from collections import deque
import numpy as np
H,W = map(int,input().split())
Maze=[list(input()) for i in range(H)]
ans=0
for hi in range(0,H):
    for wi in range(0,W):
        if Maze[hi][wi]=="#":
            continue
        maze1=[[0]*W for _ in range(H)]
        stack=deque([[hi,wi]])
        while stack:
            h,w=stack.popleft()
            for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
                new_h,new_w=h+i,w+j
                if new_h <0 or new_w <0 or new_h >=H or new_w >=W:
                    continue
                elif Maze[new_h][new_w]!="#" and maze1[new_h][new_w]==0:
                    maze1[new_h][new_w]=maze1[h][w]+1
                    stack.append([new_h,new_w])
        
        maze1[hi][wi]=0
        ans=max(ans,np.max(maze1))
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
ls = list(map(int,input().split()))
inf = float("inf")
dp = [inf] *n
dp[0] = 0
dp[1] = abs(ls[1]-ls[0])
p = inf
for i in range(2,n):
    for j in range(i-k,i):
        if (dp[j] >= p) or (abs(ls[j] - ls[i]) >= p):
            pass
        else:
            a = dp[j] + abs(ls[j] - ls[i])
            if a < p:
                p = a
                a = 0
            else:
                a = 0
    dp[i] = p
    p = inf
print(dp[n-1])

### FIXED CODE ###

n,k = map(int,input().split())
ls = list(map(int,input().split()))
dp = [10000000000] *n
dp[0] = 0
dp[1] = abs(ls[1]-ls[0])
p = 10000000000
for i in range(2,n):
    for j in range(i-k,i):
        if (dp[j] >= p) or (abs(ls[j] - ls[i]) >= p):
            pass
        else:
            a = dp[j] + abs(ls[j] - ls[i])
            if a < p:
                p = a
                a = 0
            else:
                a = 0
    dp[i] = p
    p = 10000000000
print(dp[n-1])
### BUGGY CODE ###

A, B, M = map(int,input().split())
val_m = [[0] * 3 for i in range(M)]

val_a = list(map(int, input().split()))
val_b = list(map(int, input().split()))

for i in range(M):
  val_m[i][0], val_m[i][1], val_m[i][2] = map(int, input().split())

sum_val = []
for i in range(A):
  for j in range(B):
    sum_val.append(val_a[i] + val_b[j])
    
dis_val = []
for i in range(M):
  dis_val.append(val_a[val_m[i][0]-1] + val_b[val_m[i][1]-1] - val_m[i][2])

sum_val.extend(dis_val)
sum_val.sort()
print(sum_val[0])

### FIXED CODE ###

A, B, M = map(int,input().split())
val_m = [[0] * 3 for i in range(M)]

val_a = list(map(int, input().split()))
val_b = list(map(int, input().split()))

for i in range(M):
  val_m[i][0], val_m[i][1], val_m[i][2] = map(int, input().split())

dis_val = []
for i in range(M):
  dis_val.append(val_a[val_m[i][0]-1] + val_b[val_m[i][1]-1] - val_m[i][2])

val_a = list(set(val_a))
val_b = list(set(val_b))

val_a.sort()
val_b.sort()
dis_val.sort()

sum_val = val_a[0] + val_b[0]
if(sum_val <= dis_val[0]):
  print(sum_val)
else:
  print(dis_val[0])
### BUGGY CODE ###

import sys 
import collections
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,P = map(int,readline().split())
S = list(map(int,readline().rstrip().decode()))

def solve_2(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 2 == 0)
    return cnt
def solve_5(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 5 == 0)
    return cnt
def solve(S):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    mod_cnt = [0]*(len(S))
    S = S[::-1]
    for i in range(len(S)):
        mod_cnt[i] = (mod_cnt[i-1] + S[i] * 10**i) % P
    c = collections.Counter(mod_cnt)
    ans = 0
    ans += mod_cnt.count(0)
    ans += sum( n*(n-1)//2 for n in c.values())
    return ans

print(solve(S))

### FIXED CODE ###

import sys 
import collections
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,P = map(int,readline().split())
S = list(map(int,readline().rstrip().decode()))

def solve_2(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 2 == 0)
    return cnt
def solve_5(S):
    cnt = sum(i for i,x in enumerate(S,1) if x % 5 == 0)
    return cnt
def solve(S):
    if P == 2:
        return solve_2(S)
    if P == 5:
        return solve_5(S)
    mod_cnt = [0]*(len(S))
    power = 1
    S = S[::-1]
    for i in range(len(S)):
        power *= 10
        power %= P
        mod_cnt[i] = (mod_cnt[i-1] + S[i] * power) % P
    c = collections.Counter(mod_cnt)
    cnt = sum( n*(n-1)//2 for n in c.values()) + c[0]
    return cnt

print(solve(S))
### BUGGY CODE ###

def main():
    s = input()
    q = int(input())

    for _ in range(q):
        query = list(input())
        if query[0] == "1":
            s = s[::-1]
        elif query[0] == "2":
            if query[2] == "1":
                s = query[4] + s
            elif query[2] == "2":
                s = s + query[4]

    print(s)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    s = input()
    q = int(input())
    d = deque(s)
    is_reversed = False

    for _ in range(q):
        query = list(input().split())

        if query[0] == "1":
            if is_reversed:
                is_reversed = False
            else:
                is_reversed = True

        elif query[0] == "2":
            if query[1] == "1":
                if is_reversed:
                    d.append(query[2])
                else:
                    d.appendleft(query[2])
            elif query[1] == "2":
                if is_reversed:
                    d.appendleft(query[2])
                else:
                    d.append(query[2])

    if is_reversed:
        print(*(list(d)[::-1]), sep="")
    else:
        print(*list(d), sep="")


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

N = int(input())
a = list(map(int, input().split()))
cnt = 0
ans = 0
for x in range(min(a),max(a)+1):
    cnt = 0
    for i in a:
        if abs(i-x) == 0 or abs(i-x) == 1:
            cnt += 1
    ans = max(cnt, ans)
print(ans)

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
cnt = [0]*(10**7)
for i in a:
    cnt[i-1] += 1
    cnt[i] += 1
    cnt[i+1] += 1
print(max(cnt))
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
L = []
x=0
for a in A:
    x ^= a
    L.append(x)
R = []
x=0
for a in reversed(A):
    x ^= a
    R.insert(0, x)
for i in range(n):
    x = 0
    if i>0:
        x^=L[i-1]
    if i<n-1:
        x^=R[i+1]
    print(x, end="")
    if i==n-1:
        print("")
    else:
        print(" ",end="")

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
L = []
x=0
for a in A:
    x ^= a
    L.append(x)
R = []
x=0
for a in reversed(A):
    x ^= a
    R.append(x)
for i in range(n):
    x = 0
    if i>0:
        x^=L[i-1]
    if i<n-1:
        x^=R[n-1-(i+1)]
    print(x, end="")
    if i==n-1:
        print("")
    else:
        print(" ",end="")
### BUGGY CODE ###

N,M=map(int,input().split())
LR=list(range(N+1))
for i in range(M):
    L,R=map(int,input().split())
    LR=list(set(list(range(L,R+1))) & set(LR))
print(len(LR))

### FIXED CODE ###

N,M=map(int,input().split())
LR=set(range(N+1))
l=[]
r=[]
for i in range(M):
    L,R=map(int,input().split())
    l.append(L)
    r.append(R)
ans=min(r)-max(l)+1
if ans<0:
    ans=0
print(ans)
### BUGGY CODE ###

import collections

n, k, q = map(int,input().split())
b = list()
for i in range(q):
    a = int(input())
    b.append(a)
if k > q:
    for i in range(n):
        print('Yes')
else:
    for j in range(1,n+1):
        c = b.count(j)
        if c < q-k+1:
            print('No')
        else:
            print('Yes')

### FIXED CODE ###

n, k, q = map(int,input().split())
a = []
for i in range(q):
    b = int(input())
    a.append(b)
pnt = [0] * n
for x in a:
    pnt[x-1] += 1
for j in range(n):
    if pnt[j] > q-k:
        print('Yes')
    else:
        print('No')