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

# Typical Stairs

n, m = map(int, input().split())
a = []
MOD = 10**9 + 7
for i in range(m):
    a.append(int(input()))

if n == 1:
    print(1)
    exit()

dp = [0] * (n + 1)
dp[0] = 1
if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n + 1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

print(dp[-1])


### FIXED CODE ###

# Typical Stairs
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    n, m, *a = map(int, read().split())
    MOD = 10**9 + 7

    if n == 1:
        print(1)
        exit()

    dp = [0 for _ in range(n+1)]
    dp[0] = 1
    is_broken = [False] * (n+1)
    for i in a:
        is_broken[i] = True
    if 1 in a:
        dp[1] = 0
    else:
        dp[1] = 1

    for i in range(2, n + 1):
        if is_broken[i]:
            continue
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

    print(dp[-1])

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

k = int(input())
if k%10==0 or k%10==2 or k%10==4 or k%10==5 or k%10==6 or k%10==8:
    print(-1)
else:
    s = 7
    i = 1
    while(True):
        if s%k==0:
            print(i)
            exit()
        else:
            s = s*10+7
            i += 1

### FIXED CODE ###

k = int(input())
a = 0
for i in range(k):
    a = (a*10+7)%k
    if a == 0:
        print(i+1)
        exit()
print(-1)
### BUGGY CODE ###

k=int(input())
ans=0
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
gcdlis=[]
sumlis=[]
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            lis=sorted([a,b,c])
            if lis in sumlis: 
                ans+=gcdlis[sumlis.index(lis)]
                
            else:
                sumlis.append(lis)
                x=gcdlist(lis)
                gcdlis.append(x)
                ans+=x
                
print(ans)

### FIXED CODE ###

k=int(input())
ans=0
import math
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

sumlis={}
for a in range(1,k+1):
    for b in range(1,k+1):
        t=math.gcd(a,b)
        for c in range(1,k+1):
            ans+=math.gcd(t,c)
                
print(ans)
### BUGGY CODE ###

def cal_ans(x):
    ans = (x*(x+1)/2)/x
    return ans
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = list(map(cal_ans,p))

ans_temp = 0
ans_list = []
for i in range(n-k+1):
    ans_list.append(sum(p[i:i+k]))
print(max(ans_list))

### FIXED CODE ###

# import numpy as np

def cal_ans(x):
    ans = (x+1)/2
    return ans
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = list(map(cal_ans,p))

ans_temp = 0
ans_list = []
S = [0]
for i in range(n):
    S.append(S[i]+p[i])
# print(p)
# print(S)
# for i in range(n-k+1):
#     ans_list.append(sum(p[i:i+k]))
t_len = len(S)
ans1 = 0
for i in range(t_len - k):
    if ans1 < S[i+k]-S[i]:
        ans1 = S[i+k]-S[i]
print(ans1)
# ans = 0
# for i in range(k):
#     ans += (ans_list[i]*(ans_list[i]+1)/2)/ans_list[i]
#     # print((ans_list[i]*(ans_list[i]+1)/2))
# print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

s=input().rstrip()
l=len(s)
dp=[[0 for i in range(13)] for i in  range(l)]
#dp[0]=[1 for i in range(13)]
i=0
u=s[0]
if u!="?":
    k=(int(u)*10**(l-1))%13
    dp[0][k]+=1
else:
    for g in range(10):
        k=(g*10**(l-1))%13
        dp[0][k]+=1
#print(dp)
for i in range(l-1):
    u=s[i+1]
    for j in range(13):
        if u!="?":
            k=(j+int(u)*(10**(l-i-2)))%13
            dp[i+1][k]+=(dp[i][j])%mod
        else:
            for g in range(10):
                k=(j+g*10**(l-i-2))%13
                dp[i+1][k]+=dp[i][j]%mod
            
#print(dp)
print(dp[l-1][5]%mod)

### FIXED CODE ###

import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print(dp_[5])

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

N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [0] * N

for i in range(1, N):
  dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(i - K, 0), i))

print(dp[N - 1])


### FIXED CODE ###

def solve():
  N, K = [int(i) for i in input().split()]
  H = [int(i) for i in input().split()]
  dp = [0] * N

  for i in range(1, N):
    dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i - K, 0), i))

  return dp[N - 1]

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


N, Q = map(int, input().split())
S = input()
lrs = [list(map(int, input().split())) for _ in range(Q)]

length = len(lrs)
count = [0] * length
for i in range(len(S) - 1):
    c = S[i] == 'A'
    nc = S[i+1] == 'C'
    if c and nc:
        for j in range(length):
            if lrs[j][0] <= i+1 and i < lrs[j][1] and i+1 != lrs[j][1]:
                count[j] += 1

for c in count:
    print(c)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
lrs = [list(map(int, input().split())) for _ in range(Q)]

cs = [0] * N
s = 0
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        s += 1
    cs[i+1] = s 

for l, r in lrs:
    print(cs[r-1] - cs[l-1])
### BUGGY CODE ###

N,Q=[int(s) for s in input().split()]
e_list=[[int(s) for s in input().split()] for i in range(N-1)]
q_list=[[int(s) for s in input().split()] for i in range(Q)]
#まずQを頂点ごとに集計
v_list=[0 for s in range(N+1)]
for q in q_list:
  v_list[q[0]]+=q[1]
#print(v_list)

#########オイラーツアー（部分木の出力）
#########到達可能なもののうち新しく追加されたものを見る
#########訪れた順番を出力
def euler_tour(edge_list):  
  ans_list=[0 for s in range(N+1)]
  reach=[[1,1,0]]
  route=[1]
  val_q=v_list[1] #この値を増減させてans_listにいれる
  ans_list[1]=val_q
  path=[1]
  e_list=[[e[0],e[1],0] for e in edge_list]
  vertex=1
  endflag=0
  depth=1
  while True :
    ###まずvertexから到達可能なものをすべてreachに入れる
    #辺の始点がvertexであるもの
    for e in e_list:
      if (e[0]==vertex and e[2]==0):
        reach.append([e[1],0,depth])
        e[2]=1
      elif (e[1]==vertex and e[2]==0):
        reach.append([e[0],0,depth])
        e[2]=1
    ###起点になっていないもののうち最後にreachに入ったものを、次の起点とする
    for i in range(len(reach)+1):
      if reach[-i][1]==0 :
        vertex=reach[-i][0]
        #####depthが戻ったか？
        if reach[-i][2]<depth:
           ##戻った分だけpathをansに追加
          for j in range(1,depth-reach[-i][2]+1):
            path.remove(path[-1])
          #  route.append(path[-1])
          val_q=ans_list[path[-1]]
        val_q+=v_list[vertex]
        ans_list[vertex]=val_q
      #  route.append(vertex)
        path.append(vertex)
        depth=reach[-i][2]+1
        #####ここでprint(vertex)などを入れる
        reach[-i][1]=1
        break
      if i==len(reach):  ####全ての場所に行っていれば終了
      #  for j in range(len(path)-1):
      #      path.remove(path[-1])
      #      route.append(path[-1])
        return ans_list
        break
print(*euler_tour(e_list)[1:])

### FIXED CODE ###

N,Q=[int(s) for s in input().split()]
#辺でつながれた場所をすべてリストアップ
con_list=[set() for s in range(N+1)]
for i in range(N-1):
  a,b=[int(s) for s in input().split()]
  con_list[a].add(b)
  con_list[b].add(a)

v_list=[0 for s in range(N+1)]
for i in range(Q):
  x,y=[int(s) for s in input().split()]
  v_list[x]+=y

position=1 #現在位置
counter=v_list[1] #カウンター
ans_list=[0 for s in range(N+1)] #答え
ans_list[1]=counter 
vertex_num=1 #訪れた場所の数
oya_list=[-1 for s in range(N+1)] #親に戻るためのリスト

while vertex_num<N:
  #まだ行っていない子があるか？
  if len(con_list[position])>0:
    x=con_list[position].pop()
    con_list[x].remove(position) #xの行先から親を消す
    oya_list[x]=position
    position=x
    counter+=v_list[position] #カウンターの更新
    ans_list[position]=counter
    vertex_num+=1
  else: #行き先がないなら戻る
    position=oya_list[position]
    counter=ans_list[position] #カウンターを戻す
print(*ans_list[1:])
### BUGGY CODE ###

from sys import stdin


def get_result(data):
    A = data[1]
    ans = 1
    for val in A:
        ans = ans * val
    return ans if ans <= 10**18 else -1


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


### FIXED CODE ###

import numpy as np
from sys import stdin


def get_result(data):
    A = sorted(data[1])
    ans = 1
    for val in A:
        ans = ans * val
        if ans > 10**18:
            ans = -1
            break
        elif ans == 0:
            ans = 0
            break
    return ans


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)
### BUGGY CODE ###

r,g,b,n = map(int,input().split())


cnt=0
for i in range(n+1):
    for j in range(n+1):

        hB = n - (r*i) - (j*g)

        if hB >= 0 and hB%b==0:
            cnt+=1

print(cnt)


### FIXED CODE ###

r,g,b,n = map(int,input().split())


cnt=0
for i in range(n+1):
    for j in range(n+1):

        hB = n - (r*i) - (j*g)

        if hB >= 0 and hB%b==0:
            cnt+=1

print(cnt)
### BUGGY CODE ###

import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import coo_matrix

read = sys.stdin.read
readline = sys.stdin.readline

n, m, s, t, *uvab = map(int, read().split())
if m == 1:
    from heapq import heappush, heappop

    N, M, S, T = n, m, s, t
    graph = [[] for _ in range(N + 1)]
    for u, v, a, b in zip(*[iter(uvab)] * 4):
        graph[u].append((v, a, b))
        graph[v].append((u, a, b))


    def dijkstra(start, mode):
        INF = 10 ** 15
        dist = [INF] * (N + 1)
        dist[start] = 0
        q = [(0, start)]
        while q:
            d, v = heappop(q)
            if dist[v] < d:
                continue
            for w, *a in graph[v]:
                d1 = d + a[mode]
                if dist[w] > d1:
                    dist[w] = d1
                    heappush(q, (d1, w))
        return dist


    d1 = np.array(dijkstra(S, 0))
    d2 = np.array(dijkstra(T, 1))

    d1 += d2
    answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]
    print('\n'.join(answer.astype(str)))
    exit()

s -= 1
t -= 1
u = np.array(uvab[::4], np.int64) - 1
v = np.array(uvab[1::4], np.int64) - 1
a = np.array(uvab[2::4], np.int64)
b = np.array(uvab[3::4], np.int64)

yen_matrix = coo_matrix((a, (u, v)), shape=(n, n))
snuuk_matrix = coo_matrix((b, (u, v)), shape=(n, n))

yen = dijkstra(yen_matrix, directed=False, indices=s)
snuuk = dijkstra(snuuk_matrix, directed=False, indices=t)

costs = (yen + snuuk).astype(int)
answer = 10 ** 15 - np.minimum.accumulate(costs[::-1])[::-1]
print(*answer.tolist(), sep='\n')


### FIXED CODE ###

import sys
input = sys.stdin.read
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import heappush, heappop

N,M,S,T, *uvab = map(int,input().split())
graph = [[] for _ in range(N+1)]
for u,v,a,b in zip(*[iter(uvab)]*4):
    graph[u].append((v,a,b))
    graph[v].append((u,a,b))

def dijkstra(start, mode):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[start] = 0
    q = [(0,start)]
    while q:
        d,v = heappop(q)
        if dist[v] < d:
            continue
        for w,*a in graph[v]:
            d1 = d + a[mode]
            if dist[w] > d1:
                dist[w] = d1
                heappush(q, (d1,w))
    return dist

d1 = np.array(dijkstra(S,0))
d2 = np.array(dijkstra(T,1))

d1 += d2
answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]
print('\n'.join(map(str, answer.tolist())))
### BUGGY CODE ###

import math
import sys
import itertools
import queue
from fractions import gcd
import time


def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N= int(sys.stdin.readline())
    A = list(map(int,sys.stdin.readlines()))
    m = max(A)
    for i in range(0,len(A)):
        if m == A[i]:
            k=A.pop(i)
            m = max(A)
            A.insert(i,k)
            print(m)
            m=k
        else:
            print(m)

### FIXED CODE ###

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
import time


def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N= int(sys.stdin.readline())
    A = list(map(int,sys.stdin.readlines()))
    l = sorted(A)
    m1 = l[-1]
    m2 = l[-2]
    for i in range(N):
        if A[i] == m1:
            print(m2)
        else:
            print(m1)
### BUGGY CODE ###

def main():
    X, K, D = map(int, input().split())

    val = [0] * 100000000
    val[0] = X
    #val = X
    #val_new = 0
    if K % 2 == 0 :
        limit = 10
    else :
        limit = 11
    i = 0
    if abs(X) > K * D :
        if X > 0 :
            print(X - K * D)
        else :
            print(abs(X + K * D))
    elif abs(X) == K * D :
        print("0")
    elif D == 0 :
        print(abs(X))
    else :
        for j in val :
            #print(i)
            if abs(val[i] - D) < abs(val[i] + D) :
                val[i+1] = val[i] - D
            else :
                val[i+1] = val[i] + D
            if (abs(val[i+1]) == abs(val[i-1])) and i > limit :
                print(abs(val[i + 1]))
                break
            i += 1
            if i == K :
                print(abs(val[i]))
                break


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    X, K, D = map(int, input().split())

    val = [0] * 100000000
    val[0] = X
    #val = X
    #val_new = 0
    if K % 2 == 0 :
        limit = 4
    else :
        limit = 5
    i = 0
    if abs(X) > K * D :
        if X > 0 :
            print(X - K * D)
        else :
            print(abs(X + K * D))
    elif abs(X) == K * D :
        print("0")
    elif X == 0 :
        if limit == 4 :
            print('0')
        else :
            print(abs(D))
    else :
        syo = abs(X) // D
        #print(syo)
        if syo > 3 :
            if X > 0 :
                val[0] = X - (syo-2) * D
            else :
                val[0] = X + (syo - 2) * D
            #print(val[0])
            K = K -(syo-2)
            if K % 2 == 0:
                limit = 2
            else:
                limit = 3
        for j in val :
            #print(i)
            if abs(val[i] - D) < abs(val[i] + D) :
                val[i+1] = val[i] - D
            else :
                val[i+1] = val[i] + D
            #print(val[i+1])
            if (abs(val[i+1]) == abs(val[i-1])) and i > limit :
                #print("a")
                print(abs(val[i + 1]))
                break
            i += 1
            if i == K :
                #print("b")
                print(abs(val[i]))
                break


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

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

A_count = [0 for i in range(max(A))]
for i in A:
    A_count[i-1] += 1

ans = 0
for count in A_count:
    if count % 2 == 1:
        ans += 1

print(ans)

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
sorted_A = sorted(A)

pre = sorted_A[0]
ans = 0
if len(sorted_A) == 1:
    print(1)
else:
    count = 1
    for i in range(1, len(sorted_A)):
        if sorted_A[i] == pre:
            count += 1
            if i == len(sorted_A)-1:
                if count % 2 == 1:
                    ans += 1
        else:
            if i == len(sorted_A)-1:
                ans += 1
            if count % 2 == 1:
                ans += 1
            pre = sorted_A[i]
            count = 1
    print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

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

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
S = input()

if N < 3:
    print(0)
    exit()
count = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] == S[j]:
            continue

        for k in range(j + 1, N):
            if S[j] == S[k] or S[i] == S[k] or j - i == k - j:
                continue
            else:
                count += 1
print(count)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

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

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
S = input()

if N < 3:
    print(0)
    exit()
rs = []
gs = []
bs = []
for i in range(len(S)):
    if S[i] == 'R':
        rs.append(i)
    elif S[i] == 'G':
        gs.append(i)
    else:
        bs.append(i)
count = len(rs) * len(gs) * len(bs)
# for r in rs:
#     for g in gs:
#         for b in bs:
#             rgb = [r, g, b]
#             rgb.sort()
#             if rgb[1]-rgb[0] != rgb[2]-rgb[1]:
#                 count += 1

for skip in range(1, N // 2 + 1):
    for i in range(N - 2):
        if i + 2 * skip > N - 1:
            break
        elif S[i] == S[i + skip] or S[i + skip] == S[i + 2 * skip] or S[i] == S[i + 2 * skip]:
            continue
        else:
            count -= 1

print(count)
### BUGGY CODE ###

K, S = map(int, input().split())
count = 0
for x in range(K+1):
  for y in range(K+1):
    for z in range(K+1):
      if x+y+z == S:
        count += 1

print(count)

### FIXED CODE ###

K, S = map(int, input().split())
count = 0
for x in range(K+1):
  for y in range(K+1):
    z = S - x - y
    if z >= 0 and z <= K:
      count += 1

print(count)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]

t = [s_i[0] for s_i in s if s_i[0] in "MARCH"]
count = 0
for t_i in t:
	for t_j in t:
		for t_k in t:
			if len(set((t_i, t_j, t_k))) == 3:
				count += 1

print(count//6)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]

t = [[s_i[0] for s_i in s].count(c) for c in "MARCH"]

sum_num = 0
for i in range(5):
	t_dummy_i = list(tuple(t))
	i_num = t_dummy_i.pop(i)
	for j in range(4):
		t_dummy_j = list(tuple(t_dummy_i))
		j_num = t_dummy_j.pop(j)
		for k in range(3):
			sum_num += i_num * j_num * t_dummy_j[k]

print(sum_num//6)
### BUGGY CODE ###

s = input()
n = int(input())
a = []
b = []
reverse_flag = False

for i in range(n):
    command = input()
    # reverse
    if len(command) == 1:
        reverse_flag = not reverse_flag
    
    else:
        _, t, f = command.split(' ')
        if t == '1':
            if reverse_flag:
                b.append(f)
            else:
                a.insert(0, f)
        else:
            if reverse_flag:
                
                a.insert(0, f)
            else:
                b.append(f)

if reverse_flag:
    print(''.join(b[::-1]) + s[::-1] + ''.join(a[::-1]))
else:
    print(''.join(a) + s + ''.join(b))

### FIXED CODE ###

from collections import deque

s = input()
n = int(input())
a = deque()
b = deque()
reverse_flag = False

for i in range(n):
    command = input()
    # reverse
    if len(command) == 1:
        reverse_flag = not reverse_flag
    
    else:
        _, t, f = command.split(' ')
        if t == '1':
            if reverse_flag:
                b.append(f)
            else:
                a.appendleft(f)
        else:
            if reverse_flag:
                
                a.appendleft(f)
            else:
                b.append(f)

a = list(a)
b = list(b)
if reverse_flag:
    print(''.join(b[::-1]) + s[::-1] + ''.join(a[::-1]))
else:
    print(''.join(a) + s + ''.join(b))