Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
A = list(map(int, input().split()))

def dp(n, i):
    if n == 0:
        return 0
    if n < 0:
        return None
    if i == len(CHOICES):
        return None
    
    ret1 = dp(n - CHOICES[i][1], i)
    if ret1 == None:
        ret1 = -1
    elif ret1 == 0:
        ret1 = int(str(CHOICES[i][0]))
    else:
        ret1 = int(str(CHOICES[i][0]) + str(ret1))

    ret2 = dp(n, i+1)
    if ret2 == None:
        ret2 = -1
    else:
        ret2 = ret2
        
    if ret1 == -1 and ret2 == -1:
        return None
    return max(ret1, ret2)



match = [-100,2,5,5,4,5,6,3,7,6]
CHOICES = []
for i in A:
    if (i == 6) and (9 in A):
        continue
    if (i == 3) and (5 in A):
        continue
    if (i == 2) and (3 in A or 5 in A):
        continue
    CHOICES.append([i, match[i]])
CHOICES.sort(reverse=True)
#print(CHOICES)
ans = dp(N,0)
print(ans)
    


### FIXED CODE ###

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

import sys
INT_MIN = sys.maxsize * -1
match = [-100,2,5,5,4,5,6,3,7,6]
CHOICES = []
for i in A:
    if (i == 6) and (9 in A):
        continue
    if (i == 3) and (5 in A):
        continue
    if (i == 2) and (3 in A or 5 in A):
        continue
    CHOICES.append([i, match[i]])
CHOICES.sort(reverse=True)

ans = [0]
#print(CHOICES)
for i in range(1,N+1):
    ans.append(INT_MIN)
    for c in CHOICES:
        #if  i - c[1] == 0:
        #    ans[i] = max(ans[i], int(str(c[0])))
        #elif i - c[1] >= 0 and ans[i - c[1]] != INT_MIN:
        #    ans[i] = max(ans[i], int(str(c[0]) + str(ans[i - c[1]])))

        if i - c[1] >= 0 and ans[i - c[1]] != INT_MIN:
            ans[i] = max(ans[i], c[0] + ans[i - c[1]] * 10)

print(ans[N])
from bisect import bisect_right

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

shop = []
shop_a0 = []

for i in range(n):
    a, b = map(int, input().split())
    if a != 0:
        shop.append([a, b, a/(b+1)])
    else:
        shop_a0.append(b)

shop = sorted(shop, key=lambda x: -x[2])
shop_a0 = sorted(shop_a0)

n = len(shop)

# dp[i][j]:i番目まで見てj個の店を回るのに掛かる所要時間の最小値
dp = [[10**10]*30 for _ in range(n+1)]
dp[0][0] = 0


for j in range(30):
    for i in range(n):
        dp[i+1][j] = min(dp[i][j], dp[i][j-1] + 1 +
                         shop[i][0]*(dp[i][j-1]+1) + shop[i][1])

ss = []
if shop_a0:
    ss.append(1+shop_a0[0])
    for i in range(1, len(shop_a0)):
        ss.append(ss[-1]+1+shop_a0[i])

ans = 0

for i in range(n+1):
    if t - dp[n][i] >= 0:
        ans = max(ans, bisect_right(ss, t-dp[n][i]) + i)

print(ans)


### FIXED CODE ###

from bisect import bisect_right
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


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

shop = []
shop_a0 = []

for i in range(n):
    a, b = map(int, input().split())
    if a != 0:
        shop.append([a, b, a/(b+1)])
    else:
        shop_a0.append(b)

shop = sorted(shop, key=lambda x: -x[2])
shop_a0 = sorted(shop_a0)

n = len(shop)

INF = 10**10
# dp[i][j]:i番目まで見てj個の店を回るのに掛かる所要時間の最小値
dp = [[INF for _ in range(31)] for __ in range(n+1)]
dp[0][0] = 0

m = min(n+1, 30)

for i in range(n):
    for j in range(m):
        if (shop[i][0]+1)*(dp[i][j]+1) + shop[i][1] > t:
            dp[i+1][j+1] = dp[i][j+1]
        else:
            dp[i+1][j+1] = min(dp[i][j+1], (shop[i][0]+1)
                               * (dp[i][j]+1) + shop[i][1])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ss = []
if shop_a0:
    ss.append(1+shop_a0[0])
    for i in range(1, len(shop_a0)):
        ss.append(ss[-1]+1+shop_a0[i])

ans = 0

for i in range(m):
    if t - dp[n][i] >= 0:
        ans = max(ans, bisect_right(ss, t-dp[n][i]) + i)

print(ans)
def main(n:int,lst:list)->int:
    b = True
    lst1 = []
    lst2 = []
    for e in lst:
        if b:
            lst1.append(e)
        else:
            lst2.append(e)
        b = not b
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a >= c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a >= c1[0][1]:
        c1[1] = c1[0][1]
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1]:
        c1[1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a >= c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a >= c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1] or(c1[0][1] == c2[0][1] and c2[1] > c1[1]):
            return n - c1[0][1] - c2[1]
        else:
            return n - c2[0][1] - c1[1]
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split())
print(main(n,lst))


### FIXED CODE ###

from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))
import sys

n=int(input())
ans=0
for i in range(n):
    if len(i)%2==1:
        ans+=1
print(ans)

### FIXED CODE ###

import sys

n=int(input())
ans=0
for i in range(1,n+1):
    s=str(i)
    if len(s)%2==1:
        ans+=1
print(ans)
n = input()
b = 1
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    for i in range(n):
        b *= int(a[i])
        if b > 10**18:
            print(-1)
            break
    print(b)    

### FIXED CODE ###

n = int(input())
b = 1
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    for i in range(n):
        b *= a[i]
        if b > 10**18:
            print(-1)
            break
    if b <=10**18:
        print(b)
#AIsing2020 d
 
import sys,math,collections,itertools,copy
input = sys.stdin.readline
 
 
def popcount(n):
    bin_str = bin(n)
    cou1 = bin_str.count('1')
    return cou1
 
def count(nc):
    co = 0
    while nc >0:
        cou1 = popcount(nc)
        nc = nc%cou1
        co +=1
    return co
 
N = int(input())
X = list(input().rstrip())
 
for i in range(N):
    Y = copy.copy(X)
    if Y[i] == '1':
        Y[i] = '0'
    else:
        Y[i] = '1'
    s = '0b'+"".join(Y)
    a =int(s,2)
    co = count(a)
    print(co)

### FIXED CODE ###

#AIsing2020 a

import sys,math,collections,itertools
input = sys.stdin.readline

L,R,d = list(map(int,input().split()))

if L%d ==0:
    print(R//d-L//d+1)
else:
    print(R//d-L//d)
N, i = map(int, input().split(" "))
return N - i + 1

### FIXED CODE ###

N, i = map(int, input().split(" "))
print(N - i + 1)
sum = 0
for i in range(N):
    if i == 0:
        sum += list_B[i]
#         print('i == 0')
#         print('i=', i, 'sum=', sum)
    elif i == N-1:
        sum += list_B[i-1]
        print('i == N-1')
#         print(list_B[i-1])
#         print('i=', i, 'sum=', sum)
    else:
        if (list_B[i] >= list_B[i-1]):
            sum += list_B[i-1]
        else:
            sum += list_B[i]
#         print('i=', i, 'sum=', sum)
print(sum)

### FIXED CODE ###

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

sum = 0
for i in range(N):
    if i == 0:
        sum += list_B[i]
#         print('i == 0')
#         print('i=', i, 'sum=', sum)
    elif i == N-1:
        sum += list_B[i-1]
#         print('i == N-1')
#         print(list_B[i-1])
#         print('i=', i, 'sum=', sum)
    else:
        if (list_B[i] >= list_B[i-1]):
            sum += list_B[i-1]
        else:
            sum += list_B[i]
#         print('i=', i, 'sum=', sum)
print(sum)
N, K = input().split()
P = list(map(int,input().split()))

# N=5
# K=2
# P=[10, 20, 40, 2, 6]

P.sort()
 
total=0

for i in range(int(K)+1):
  total=total+P[i]
 
print(total)

### FIXED CODE ###

N, K = input().split()
P = list(map(int,input().split()))

P.sort()
 
total=0

for i in range(int(K)):
    total=total+P[i]
 
print(total)
N = int(input())
S = []
for i in range(N):
    S.append(input())

def check(S, A, B):
    for i in range(N):
        for j in range(i+1, N):
            if S[i][j+B-N] != S[j][i+B-N]:
                return 0
    return 1

cnt = 0
for i in range(N):
    cnt += check(S[i:] + s[:i], 0, i)
print(cnt * N)

### FIXED CODE ###

N = int(input())
S = []
for i in range(N):
    S.append(input())

def check(S, A, B):
    for i in range(N):
        for j in range(i+1, N):
            if S[i][j] != S[j][i]:
                return 0
    return 1

cnt = 0
for i in range(N):
    cnt += check(S[i:] + S[:i], 0, i)
print(cnt * N)
a = int(input())
4000
s = input()
yes
if a >= 3200:
  print(s)
  else a < 3200:
    print("red")
    

### FIXED CODE ###

a = int(input())

s = input()

if a >= 3200:
    print(s)
else:
    print("red")
even, odd = map(int,input().split())
print((even*~-even // 2) + (odd*=~-odd // 2))

### FIXED CODE ###

n, m = map(int, input().split())
print((n * ~-n // 2) + (m* ~-m // 2))#n * ~-n == n*(n-1)
def GCD(a, b):
	if b > a:
		tmp = a
		a = b
		b = tmp
	if a % b == 0:
		return b
	return GCD(b, a % b)

def LCM(a, b):
	return a * b / GCD(a, b)

def judge():
	N, M = map(int, raw_input().split())
	S = raw_input()
	T =raw_input()
	L = LCM(N, M)
	good_str = ["*"] * L
	for i in range(N):
		idx = i * L/N
		good_str[idx] = S[i]
	for i in range(M):
		idx = i * L/M
		if good_str[idx] == "*" or good_str[idx] == T[i]:
			pass
		else:
			return -1
	return L

print judge()


### FIXED CODE ###

def GCD(a, b):
	if b > a:
		tmp = a
		a = b
		b = tmp
	if a % b == 0:
		return b
	return GCD(b, a % b)

def LCM(a, b):
	return a * b / GCD(a, b)

def judge():
	N, M = map(int, raw_input().split())
	S = raw_input()
	T =raw_input()
	L = LCM(N, M)
	S_pos = [0] * N
	T_pos = [0] * M
	for i in range(N):
		S_pos[i] = i * L/N
	for i in range(M):
		T_pos[i] = i * L/M
	i = 0
	j = 0
	while i < N and j < M:
		if S_pos[i] == T_pos[j]:
			if S[i] != T[j]:
				return -1
			i += 1
			j += 1
		elif S_pos[i] < T_pos[j]:
			i += 1
		else:
			j += 1
	return L

print judge()
import math
N=int(input())
print(math.factorial(N)%(10**9+7)

### FIXED CODE ###

import math
N=int(input())
print(math.factorial(N)%(10**9+7))
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i+1)
def d(x,i):a(x,3,x)
	for t in r(30):b(p:=i+t+30);a(q:=p+1,n,q);[*map(b,r(q,v:=i+60))];a(v,x,i+t,1);b(p);a(q,i+t,q)
p(3934)
a(0,1,3)
a(2,3,3,1)
a(1,3,1)
d(0,9)
d(1,50)
for t in r(60):a(2,2,2);[t-31<s<30!=(a(8+t-s,50+s,5),a(3,5,6,1),a(2,6,2))for s in r(t)]

### FIXED CODE ###

n=97
r=range
L='<'
P='+'
l=[3933,P,0,1,n,L,2,n,n,P,0,n,3,P,1,n,4]
a=lambda i,j:[P,i,j,i]
b=lambda i:[P,i,i,i+1]
def d(x,i,j):
	return sum([sum([b(j+t-1),a(j+t,n),*(b(s)for s in r(j+t,j+29)),[L,j+29,x,i+t],b(j+t-1),a(j+t,i+t)],[])for t in r(30)],[])
l+=d(3,5,36)
l+=d(4,36,67)
for t in r(59):
	l+=a(2,2)
	for s in r(t+1):
		if t-30<s<30:l+=[P,5+t-s,36+s,98];l+=[L,n,98,99];l+=a(2,99)
print(*l)
A = int(input())
B = int(input())
C = int(input())
D = int(input())
while True:
	C = C - B
	if C <= 0 : 
		print("Yse")
		break
	A = A - D
	if A <= 0 : 
		print("No")
		break

### FIXED CODE ###

A,B,C,D=map(int,input().split())
 
while True:
    C=C-B
    if C<=0:
        break
    A=A-D
    if A<=0:
        break
 
if C<=0:
    print('Yes')
else:
    print('No')
import numpy as np
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
import collections

N, M = map(int, input().split())
edge = np.array([input().split() for _ in range(M)], dtype=np.int8).T

if M == 0:
    print(1)
else:

    tmp = np.ones(M, dtype=np.int8).T
    graph = csr_matrix((tmp, (edge[:] - 1)), (N, N))

    n, labels = connected_components(graph)

    c = collections.Counter(labels)

    print(max(c.values()))

### FIXED CODE ###

d,t,s= map(int,input().split())

if (d/s) <= t:
    print("Yes")
else:
    print("No")
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
s = []
l = []
for x in range(n):
  s += [x+1]*a[x+1]
for i in range(h):
  l.append(s[w*i:w*(i+1)])
  if i%2:
    l[i] = l[i][::-1]
for x in l:
  print(" ".join(map(str,x)))

### FIXED CODE ###

h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
s = []
l = []
for x in range(n):
  s += [x+1]*a[x]
for i in range(h):
  l.append(s[w*i:w*(i+1)])
  if i%2:
    l[i] = l[i][::-1]
for x in l:
  print(" ".join(map(str,x)))
#ITP1_7_B
a=int(0)
m=int(0)
while True:
  n,x=map(int,input().split())
  if n ==0 and x==0:
    break
  for i in range(n):
    j=i+1
    for j in range(n):
      h=i+2
      for h in range(n):
        if i+k+h==x:
          k=k+1
  print(k)
        
    


### FIXED CODE ###

#ITP1_7_B
m=int(0)
while True:
  m=0
  n,x=map(int,input().split())
  if n ==0 and x==0:
    break
  for a in range(1,n-1):
    for b in range(a+1,n):
      for c in range(b+1,n+1):
        if a+b+c==x:
          m=m+1
  print(m)
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

from math import gcd
import math
acc = a[0]
LIMIT=max(a)
minPrime = [0]*(LIMIT+1)
#minPrime[1] = 1
count = 0
for i in range(2,LIMIT+1):
    if minPrime[i] == 0:
        count += 1
        j = i
        while j <= LIMIT:
            if minPrime[j] == 0:
                minPrime[j] = i
            j += i
#print(minPrime)
def factrial(N):
    ret = []
    while minPrime[N] != N:
        ret.append(minPrime[N])
        N = N//minPrime[N]
    if N != 1:
        ret.append(N)
    return ret

for i in range(N):
    acc = gcd(acc,a[i])
if acc != 1:
    print("not coprime")
    exit()

pairwise = True
# facts = [set(factrial(e)) for e in a]
p = set() #all prime
#s = set(factrial(a[0])) # pair prime
for e in a:
    if not pairwise:
        break
    f = set(factrial(e))
    # s = s & f
    if p & f != set():
        pairwise = False
    p = p | f
#print(p,s,pairwise)

if pairwise:
    print("pairwise coprime")
else:
    print("setwise coprime")
# for s:
#     acc = math.gcd(acc,a[i])
# if acc != 1:
#     print("not coprime")
#     exit()
# print("pairwise coprime")
# for i in range(N):
#     for j in range(i+1,N):
#         b = gcd(a[i],a[j])
#         if b != 1:
#             print("setwise coprime")
#             exit()
# if pairwise == True:
#     print("pairwise coprime")
# else:
#     print("not coprime")


### FIXED CODE ###

import math
from collections import defaultdict
pc = True
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)
class Sieve_of_Eratosthenes:
    def __init__(self, N):
        self.sieve = [-1] * (N+1)
 
        for i in range(2,N+1):
            if self.sieve[i] == -1:
                for j in range(1,1+N//i):
                    self.sieve[i*j] = i
 
    def isprime(self, num):
        if num <= 1:
            return False
        else:
            return self.sieve[num] == num
 
    def factorization(self, num):
        ret = set([])
        while num != 1:
            div = self.sieve[num]
            ret.add(div)
            num //= div
        return ret
 
sofe = Sieve_of_Eratosthenes(M)
ddic = defaultdict()
judge = set([])
 
for i in a:
    if not pc:
        break
    asf = sofe.factorization(i)
    
    if judge & asf != set():
        pc = False
    judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")
N = int(input())
A = [input() for i in range(N)]
P=round(sum(A)/N)
B=0
for i in range(N):
  B=B+(A[i]-P)**2
print(B)


### FIXED CODE ###

N,R=map(int, input().split()) 
if N>=10:
    print(R)
if 0<=N<10:
    print(R+100*(10-N))
n = int(input())
a = list(map(int, input().split()))
s = 1
for i in a:
  s *= i
  if s => 10 ** 8:
    s = -1
    break
if 0 in a:
  s = 0
print(s)
 

### FIXED CODE ###

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

ans = 1
for i in a :
  ans *= i
  if ans > 10**18 :
    ans = -1
    break
if 0 in a :
  ans = 0

print(ans)
N,A,B=map(int,input().split())
c='b'*A+'a'*B
for i in range(N):
    d=i*c
print(d.count('b',0,N))

### FIXED CODE ###

N,A,B=map(int,input().split())
if N == (N//(A+B))*(A+B):
    print(N-(N//(A+B))*(B))
elif (N//(A+B))*(A+B)<N <= (N//(A+B))*(A+B)+A:
    print(N-(N//(A+B))*(B))
else:
    print((N//(A+B)+1)*(A))
N,M= map(int,input().split())
AB=[[int(j) for j in input().split()] for i in range(M)]
result=dict()

for i in range(M):
    ind =AB[i][0]
    ind2 =AB[i][1]
    #print(i,ind,ind2)
    if result.get(str(ind)) is None:
        result[str(ind)] =1
    else:
        result[str(ind)] =result[str(ind)]+1
    
    if result.get(str(ind2)) is None:
        result[str(ind2)] =1
    else:
        result[str(ind2)] =result[str(ind2)]+1
    #print(result)
    
for i in range(1,N+1):    
    print(result[str(i)])

### FIXED CODE ###

N,M= map(int,input().split())
f = [0] * (N + 2)
for i in range(M):
    x,y = map(int,input().split())
    f[x]+=1
    f[y]+=1
for i in range(1,N+1):
    print(f[i])
n = int(input())

a=math.ceil(n/2)

print(a/n)

### FIXED CODE ###

K = int(input())

if K%2==0:
  a=K/2
else:
  a=(K//2)+1

     
print(a/K)
n, p = map(int, raw_input().split())
fac = {}
primes = [1]*(10**6 + 200)
i = 2
prim = []
while i <= 10**6 + 100:
    if primes[i]:
        prim.append(i)
        j = i*2
        while j <= 10**6:
            primes[j] = 0
            j += i 
    i += 1 
for i in prim:
    while p%i == 0:
        p /= i 
        fac[i] = fac[i] + 1 if i in fac else 1
ans = 1
for i in fac:
    if fac[i] >= n:
        ans *= i**(fac[i]/n)
print ans

### FIXED CODE ###

print raw_input().count('2')
( a, b, c) = [int(i) for i in input().split()]

count = 0
for i in range( a, b):
    if c % n == 0:
        count += 1
print( count)

### FIXED CODE ###

( a, b, c) = [int(i) for i in input().split()]

count = 0

for i in range( a, b+1):
    if c % i == 0:
        count += 1
print( count)
x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(len(arrayR)):
    if arrayAns[0] <= int(arrayR[i]):
        arrayAns[0] = int(arrayR[i])
        arrayAns.sort()
    else:
        break
print(sum(arrayAns))


### FIXED CODE ###

x, y, a, b, c = map(int, input().split())
arrayP = list(map(int, input().split()))
arrayQ = list(map(int, input().split()))
arrayR = list(map(int, input().split()))
arrayP.sort(reverse=True)
arrayQ.sort(reverse=True)
arrayR.sort(reverse=True)
arrayAns = []
for i in range(x):
    arrayAns.append(int(arrayP[i]))
for i in range(y):
    arrayAns.append(int(arrayQ[i]))
arrayAns.sort()
for i in range(min(len(arrayR), len(arrayAns))):
    if arrayAns[i] <= int(arrayR[i]):
        arrayAns[i] = int(arrayR[i])
    else:
        break
print(sum(arrayAns))
s = input()
q = int(input())
ss = []

for i in range(q):
  t = input().split()
  if t[0] == '1':
    ss = ss[::-1]
  else:
    if t[1] == '2':
      ss.append(t[2])
    else:
      ss.insert(0,t[2]

print("".join(ss))



### FIXED CODE ###

s = input()
q = int(input())

from collections import deque

ss = deque(s)
flg = True

for i in range(q):
  t = input().split()
  if t[0] == '1':
    flg = not flg
  else:
    if t[1] == '2':
        ss.append(t[2]) if flg else ss.appendleft(t[2])
    else:
        ss.append(t[2]) if not flg else ss.appendleft(t[2])

ss = list(ss)

print("".join(ss)) if flg else print("".join(ss[::-1]))
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

s = ns()
k = ni()
i = 0
while True:
    if s[i] == '1':
        i += 1
    else:
        break

if k <= i:
    ans = 1
else:
    ans = int(s[i])

print(ans)

### FIXED CODE ###

import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

s = ns()
k = ni()
i = 0
while i < len(s):
    if s[i] == '1':
        i += 1
    else:
        ans = int(s[i])
        break

if k <= i:
    ans = 1

print(ans)
s = input()
if s.count("7") == 2 and s.count("5") == 1:
  print("YES")
else:
  print("NO)

### FIXED CODE ###

s = input()
if s.count("7") == 1 and s.count("5") == 2:
  print("YES")
else:
  print("NO")
import math


def solve():
    print(math.factorial(int(input())) % MOD)
    
 
solve()

### FIXED CODE ###

import math
MOD = 10**9 + 7

N = int(input())
print(math.factorial(N) % MOD)
n = input()
A = [input() for i in range(n)]
q = input()
m = [input() for i in range(q)]
i = 0
j = 0

def solve(i,m):
  if m == 0:
    return True
  if i >= n:
    return False
  res = solve(i+1,m) | solve(i+1, m - A[i])
  return res

while(i < q):
  while(j < n):
    if solve(n, m[q]):
      print 'yes'
    else:
      print 'no'
    n = n+1
  m = m+1

### FIXED CODE ###

n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

min = min(A)
sum = sum(A)

def solve(i,m):
  if sum < m:
    return False
  if m == 0:
    return True
  if i >= n:
    return False
  res = solve(i+1,m) or solve(i+1, m - A[i])
  return res
 
for m in M:
    if solve(0, m):
      print 'yes'
    else:
      print 'no'
a = int(input())
b = int(input())
result = a * b

if result%2 == 0:
	print("Even")
else:
	print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
result = a * b

if result%2 == 0:
	print("Even")
else:
	print("Odd")
n, a, b, c, d, e = map(int, input().split())
x = min(a, b, c, d, e)
print((n + x - 1) // x + 4)

### FIXED CODE ###

n = int(input())
A = []
for _ in range(5):
  A.append(int(input()))
x = min(A)
print((n + x - 1) // x + 4)