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

import sys
import numpy as np

def binary_search(array, num):
    # numより真に大きいはじめのindex
    if array[-1] <= num:
        return -1
    left = -1
    right = len(array)-1
    while right - left > 1:
        mid = int((left + right)/2)
        if array[mid] <= num:
            left = mid
        else:
            right = mid
    return right

a_index = []
b_index = []

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split(" ")))
A = np.sort(A)
B = list(map(int, sys.stdin.readline().strip().split(" ")))
B = np.sort(B)
C = list(map(int, sys.stdin.readline().strip().split(" ")))
C = np.sort(C)

for a in A:
    a_index.append(binary_search(B, a))
    
for b in B:
    b_index.append(binary_search(C, b))

res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    for b_i in b_index[a_i:]:
        res += (N - b_i)
print(str(res))



### FIXED CODE ###

import sys
import numpy as np

def binary_search(array, num):
    # numより真に大きいはじめのindex
    if array[-1] <= num:
        return -1
    left = -1
    right = N-1
    while right - left > 1:
        mid = int((left + right)/2)
        if array[mid] <= num:
            left = mid
        else:
            right = mid
    return right

a_index = []
b_index = []

N = int(sys.stdin.readline().strip())
A = list(map(int, sys.stdin.readline().strip().split(" ")))
A = np.sort(A)
B = list(map(int, sys.stdin.readline().strip().split(" ")))
B = np.sort(B)
C = list(map(int, sys.stdin.readline().strip().split(" ")))
C = np.sort(C)

for a in A:
    a_index.append(binary_search(B, a))
    
for b in B:
    b_index.append(binary_search(C, b))


b_index = list(map(lambda x: N-x if (x != -1) else 0, b_index))

bb = []
tmp = np.sum(b_index)
for i in range(N):
    bb.append(tmp)
    tmp = tmp - b_index[i]

res = 0
for a_i in a_index:
    if a_i == -1:
        continue
    res += bb[a_i]
print(str(res))
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 08:04:43 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  G = [[] for _ in range(N+1)]
  for i in range(N-1):
    u, v, w = map(int, input().split())
    G[u].append((v, w))
    G[v].append((u, w))

  color = [-1 for _ in range(N+1)]
  color[1] = 0
  S = [1]
  while len(S):
    now = S[-1]
    for next_, w in G[now]:
      if not color[next_] == -1:
        continue
      S.append(next_)
      color[next_] = (w % 2) ^ color[now]
      # if w % 2:
      #   color[next_] = 1 ^ color[now]
      # else:
      #   color[next_] = 0 ^ color[now]
      # # white, odd
      # if color[now]:
      #   color[next_] = 0 if w % 2 else 1
      # # black, even
      # else:
      #   color[next_] = 1 if w % 2 else 0
      break
    else:
      S.pop()

  for i in range(1, N+1):
    print(color[i])


if(__name__ == '__main__'):
  main()


### FIXED CODE ###

import sys
from collections import defaultdict, deque

def main():
    input = sys.stdin.readline
    N = int(input())
    d = defaultdict(list)
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        d[u-1].append((v-1, w))
        d[v-1].append((u-1, w))

    dist = [0] * N
    q = deque()
    q.append((0, 0))
    visited = set()

    while len(q) > 0:
        q_ = deque()
        while len(q) > 0:
            node1, cost1 = q.popleft()

            dist[node1] = cost1
            visited.add(node1)

            for node2, cost2 in d[node1]:
                if node2 in visited:
                    continue

                q_.append((node2, cost1 + cost2))

        q = q_

    for d in dist:
        print(d % 2)


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

N, K = map(int, input().split())
A = [1] + list(map(int, input().split()))

p = 1
points = [p]
for _ in range(N):
    p = A[p]
    if p in points:
        break
    points.append(p)

idx = points.index(p)

if idx > K:
    print(points[K])
    exit()

cycle = points[idx:]

print(cycle[(K - idx) % len(cycle)])

### FIXED CODE ###

N, K = map(int, input().split())
A = [1] + list(map(int, input().split()))

p = 1
points = [p]
visited = set([p])

for _ in range(N):
    p = A[p]
    if p in visited:
        break
    points.append(p)
    visited.add(p)

idx = points.index(p)

if idx > K:
    print(points[K])
    exit()

cycle = points[idx:]

print(cycle[(K - idx) % len(cycle)])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5)
m = 100005
visited = [False]*(m*2)
cnt = [0,0]
def dfs(i):
    global cnt
    if visited[i]:
        return
    visited[i] = True
    cnt[i//m] = cnt[i//m] + 1
    for j in to[i]:
        dfs(j)


n = int(input())
to = [[] for i in range(m*2)]
for i in range(n):
    x,y = map(int,input().split())
    y = y+m
    to[x].append(y)
    to[y].append(x)

ans = 0
for i in range(m*2):
    cnt = [0,0]
    dfs(i)
    ans = ans + cnt[0]*cnt[1]

print(ans-n)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]

m = 100010
uf = UnionFind(m*2)
n = int(input())
for i in range(n):
    x,y = map(int,input().split())
    y = y+m
    uf.Unite(x,y)

lx = {}
ly = {}
ans = 0
for i in range(m):
    rx = uf.Find_Root(i)
    lx[rx] = lx.get(rx,0)+1
    ry = uf.Find_Root(i+m)
    ly[ry] = ly.get(ry,0)+1
for i in range(m*2):
    ans += lx.get(i,0)*ly.get(i,0)

print(ans-n)
### BUGGY CODE ###

s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

ns = s
cnt_r = 0
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                ns = ns + c
            else:
                ns = c + ns
        else:
            if cnt_r % 2 == 1:
                ns = c + ns
            else:
                ns = ns + c

if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)


### FIXED CODE ###

s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

# ns = s
cnt_r = 0
bs, es = '', ''
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                es += c
                # ns = ns + c
            else:
                bs = c + bs
                # ns = c + ns
        else:
            if cnt_r % 2 == 1:
                bs = c + bs
                # ns = c + ns
            else:
                es += c
                # ns = ns + c

ns = bs + s + es
if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)
### BUGGY CODE ###

n=int(input())
mod=998244353
A=[]
for i in range(n):
  A.append(int(input()))
t=sum(A)
DP=[[0]*(t) for _ in range(n+1)]
DP[0][0]=1
for i in range(n):
  a=A[i]
  for j in range(t):
    DP[i+1][j]=(2*DP[i][j]+DP[i][max(0,j-a)])%mod

DP2=[[0]*(t) for _ in range(n+1)]
DP2[0][0]=1
for i in range(n):
  a=A[i]
  for j in range(t):
    if j>=a:
      DP2[i+1][j]=(DP2[i][j]+DP2[i][j-a])%mod
    else:
      DP2[i+1][j]=DP2[i][j]

ans=1
for i in range(n):
  ans=(ans*3)%mod
if t%2==1:
  print((ans-3*DP[n][t//2+1])%mod)
else:
  print((ans-3*DP[n][t//2]+3*DP2[n][t//2])%mod)



### FIXED CODE ###

n=int(input())
mod=998244353
A=[]
for i in range(n):
  A.append(int(input()))
t=sum(A)
DP=[[0]*(t) for _ in range(n+1)]
DP[0][0]=1
for i in range(n):
  a=A[i]
  for j in range(t):
    DP[i+1][j]=(2*DP[i][j]+DP[i][max(0,j-a)])%mod

DP2=[[0]*(t) for _ in range(n+1)]
DP2[0][0]=1
for i in range(n):
  a=A[i]
  for j in range(t):
    if j>=a:
      DP2[i+1][j]=(DP2[i][j]+DP2[i][j-a])%mod
    else:
      DP2[i+1][j]=DP2[i][j]

ans=1
for i in range(n):
  ans=(ans*3)%mod
if t%2==1:
  print((ans-3*DP[n][t//2+1])%mod)
else:
  print((ans-3*DP[n][t//2]+3*DP2[n][t//2])%mod)
### BUGGY CODE ###

from collections import defaultdict

H, W, M = map(int, input().split())
dh, dw = defaultdict(int), defaultdict(int)
used = set()

for _ in range(M):
    h, w = map(int, input().split())
    dh[h] += 1
    dw[w] += 1
    used.add((h, w))

ih = sorted(dh.items(), key=lambda x:-x[1])
iw = sorted(dw.items(), key=lambda x:-x[1])

h, counth = ih[0]
w, countw = iw[0]
ans = counth + countw - ((h, w) in used)

for h, counth in ih:
    for w, countw in iw:
        b = counth + countw - ((h, w) in used)
        if abs(b-ans)>1:
            break
        ans = max(ans, b)
print(ans)


### FIXED CODE ###

from collections import Counter


def solve():
    H, W, M = map(int, input().split())
    dh, dw = Counter(), Counter()
    used = set()

    for _ in range(M):
        h, w = map(int, input().split())
        dh[h] += 1
        dw[w] += 1
        used.add((h, w))

    ih = dh.most_common()
    iw = dw.most_common()

    h, counth = ih[0]
    w, countw = iw[0]

    s = counth + countw
    ans = counth + countw - ((h, w) in used)

    for h, counth in ih:
        for w, countw in iw:
            if counth+countw < s or ans == s:
                break
            b = counth + countw - ((h, w) in used)
            ans = max(ans, b)
    print(ans)


solve()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# E
# 文字列比較をローリングハッシュを用いると高速

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
s = input()[:-1]
# s = list(map(ord, list(input()[:-1])))
# print(s)

lb = 0
ub = n//2 + 1


def check(len):
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False


mod = 10**9+7
base = 1234
power = [1]*(n+1)
for i in range(1, n+1):
    power[i] = power[i-1]*base%mod


def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    # defaultdictが早い
    # dic = defaultdict(int)
    # dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False


def check3(m):
    dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False


while ub > lb+1:
    x = (lb + ub)//2
    if check(x):
        lb = x
    else:
        ub = x
    # print(lb, ub)


'''
print(3, check(3))
print(4, check(4))
print(5, check(5))
'''

print(lb)

### FIXED CODE ###

# -*- coding: utf-8 -*-
# E
# 文字列比較をローリングハッシュを用いると高速

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
s = input()[:-1]
# s = list(map(ord, list(input()[:-1])))
# print(s)

lb = 0
ub = n//2 + 1


def check(len):
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False


mod = 10**9+7
base = 1234
power = [1]*(n+1)
for i in range(1, n+1):
    power[i] = power[i-1]*base%mod


def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    # defaultdictが早い
    # dic = defaultdict(int)
    # dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False


def check3(m):
    dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False


while ub > lb+1:
    x = (lb + ub)//2
    if check3(x):
        lb = x
    else:
        ub = x
    # print(lb, ub)


'''
print(3, check(3))
print(4, check(4))
print(5, check(5))
'''

print(lb)
### BUGGY CODE ###

import numpy as np
import copy

def main():
    data0 = np.array(list(input()))
    data1 = np.array(list(input()))

    flag = True
    data_tmp = data0
    count = 0
    len_data = len(data0)
    while(count <= len_data):
        if not list(data0):
            break
        count += 1
        c0 = data0[0]
        c1 = data1[0]
        if np.allclose(data0 == c0, data1 == c1):
            data0 = data0[data0 != c0]
            data1 = data1[data1 != c1]
        else:
            flag = False

    if flag:
        print('Yes')
    else:
        print('No')



def swap(data, c0, c1):
    data_tmp = copy.copy(data)
    data_tmp[data == c0] = c1
    data_tmp[data == c1] = c0
    return data_tmp

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    data0 = input()
    data1 = input()

    flag = True
    data_tmp = data0
    count = 0
    len_data = len(data0)
    while True:
        if data0 == "":
            break

        data0 = data0.replace(data0[0], "")
        data1 = data1.replace(data1[0], "")

        if len(data0) != len(data1):
            print('No')
            exit()

    print('Yes')

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

n,c = map(int,input().split())
d = [list(map(int,input().split())) for i in range(c)]
g = [list(map(int,input().split())) for i in range(n)]
# mod=0,1,2について、色iに変えた時のコストをまとめておく
cost = [[0]*c for i in range(3)]
for i in range(3):
    for j in range(c):
        for a in range(n):
            for b in range(n):
                if (a+b)%3==i:
                    cost[i][j]+=d[g[a][b]-1][j]
# mod=0,1,2について、どの色で塗るか全探索
ret=10**10
for i in range(c):
    for j in range(c):
        for k in range(c):
            if i==j or j==k or k==i:
                continue
            ret=min(ret, cost[0][i]+cost[1][j]+cost[2][k])
print(ret)

### FIXED CODE ###

n,c = map(int,input().split())
d = [list(map(int,input().split())) for i in range(c)]
g = [list(map(int,input().split())) for i in range(n)]
# mod=0,1,2について、色iに変えた時のコストをまとめておく
cost = [[0]*c for i in range(3)]
for i in range(3):
    for j in range(c):
        for a in range(n):
            for b in range(n):
                if (a+b)%3==i:
                    cost[i][j]+=d[g[a][b]-1][j]
# mod=0,1,2について、どの色で塗るか全探索
ret=10**10
for i in range(c):
    for j in range(c):
        for k in range(c):
            if i==j or j==k or k==i:
                continue
            ret=min(ret, cost[0][i]+cost[1][j]+cost[2][k])
print(ret)
### BUGGY CODE ###

N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = [i + 1 for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    if a in kouho or b in kouho:
        if H[a] > H[b] and b in kouho:
            kouho.remove(b)
        elif H[a] < H[b] and a in kouho:
            kouho.remove(a)
        elif H[a] == H[b]:
            if a in kouho:
                kouho.remove(a)
            if b in kouho:
                kouho.remove(b)
print(len(kouho))


### FIXED CODE ###

N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
kouho = set([i + 1 for i in range(N)])
hazure = set()
for i in range(M):
    a, b = map(int, input().split())
    Ha = H[a]
    Hb = H[b]
    if Ha >= Hb:
        hazure.add(b)
    if Ha <= Hb:
        hazure.add(a)
ans = kouho - hazure
print(len(ans))
### BUGGY CODE ###

S = input()

T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13

c = {}
for i in range(len(S)):
    if S[len(S) - i - 1] != "?":
        continue
    tc = {i: 0 for i in range(13)}
    for j in range(0, 10):
        t = j * 10 ** i
        tc[t % 13] += 1
    c[i] = tc

dp = []
tdp = {i: 0 for i in range(13)}
tdp[SS] += 1
dp.append(tdp)
for k, v in c.items():
    tdp = {i: 0 for i in range(13)}
    for r, c in v.items():
        for _r, _v in dp[-1].items():
            tdp[(_r + r) % 13] += _v * c
    dp.append(tdp)

ans = dp[-1][5]
print(ans % (10**9 + 7))

### FIXED CODE ###

S = input()
con = 10**9 + 7

T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13

def get_mod(S):
    c = {}
    iii = 1
    for i in range(len(S)):
        if S[len(S) - i - 1] != "?":
            iii *= 10
            iii %= 13
            continue
        c[i] = {(j * iii) % 13: 1 for j in range(0, 10)}
        iii *= 10
        iii %= 13
    return c
c = get_mod(S)

def get_tdp(pdp):
    tdp = {i: 0 for i in range(13)}
    for r in v.keys():
        for _r, _v in pdp.items():
            tdp[(_r + r) % 13] += _v
    for i in range(13):
        tdp[i] %= con
    return tdp

pdp = {i: 0 for i in range(13)}
pdp[SS] += 1
for k, v in c.items():
    pdp = get_tdp(pdp)

ans = pdp[5]
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

from collections import deque

COMMAND = ("insert", "delete", "deleteFirst", "deleteLast")

if __name__ == "__main__":
    n = int(input())
    com = []
    for i in range(n):
        com.append(input().split())
    ans = deque()
    for i in com:
        if i[0] == COMMAND[0]:
            ans.appendleft(i[1])
        elif i[0] == COMMAND[1]:
            if i[1] in ans:
                ans.remove(i[1])
        elif i[0] == COMMAND[2]:
            ans.popleft()
        elif i[0] == COMMAND[3]:
            ans.pop()
    print(" ".join(ans))

### FIXED CODE ###

# -*- coding: utf-8 -*-

from collections import deque
import sys

COMMAND = ("insert", "delete", "deleteFirst", "deleteLast")

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    ans = deque()
    inp = sys.stdin.readlines()
    for i in range(n):
        com = inp[i].split()
        if com[0] == COMMAND[0]:
            ans.appendleft(com[1])
        elif com[0] == COMMAND[1]:
            if com[1] in ans:
                ans.remove(com[1])
        elif com[0] == COMMAND[2]:
            ans.popleft()
        elif com[0] == COMMAND[3]:
            ans.pop()
    print(" ".join(ans))
### BUGGY CODE ###

N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W+1):
        if j-w[i]>=0:
            dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])

### FIXED CODE ###

N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(N):
    for j in range(W+1):
        if j-w[i]>=0:
            dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
        dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])
### BUGGY CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

# 双方向グラフで幅優先探索

from collections import deque

n, m = map(int, input().split())
g = [set([]) for _ in range(n)]
#隣接リストの作成
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].add(b)

graph = [set([]) for _ in range(n)]
for i in range(n):
    g1 = set([])
    g2 = set([])
    g3 = set([])
    g1 = g1 | g[i]
    for x in g1:
        g2 = g2 | g[x]
    for x in g2:
        g3 = g3 | g[x]
    graph[i] = g3

s, t = map(int, input().split())
s, t = s-1, t-1

#幅優先探索
q = deque()
seen = [False]*n
level = [-1]*n
parent = [-1]*n
q.append(s)
seen[s] = True
level[s] = 0
parent[s] = 0
while len(q)>0:
    cur = q.popleft()
    lvl = level[cur]
    for i in graph[cur]:
        if seen[i]==False:
            seen[i] = True
            #階層
            level[i] = lvl + 1
            #親
            parent[i] = cur
            q.append(i)
print(level[t])


### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

# 双方向グラフで幅優先探索

from collections import deque

n, m = map(int, input().split())
g = [set([]) for _ in range(n)]
#隣接リストの作成
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].add(b)

s, t = map(int, input().split())
s, t = s-1, t-1

#幅優先探索
q = deque()
level = [[-1]*n for i in range(3)]
q.append((s, 0))
level[0][s] = 0
while len(q)>0:
    cur, hp = q.popleft()
    lvl = level[hp][cur]
    for i in g[cur]:
        if level[(hp+1)%3][i]==-1:
            #階層
            level[(hp+1)%3][i] = lvl + 1
            q.append((i, (hp+1)%3))
print(level[0][t]//3)
### BUGGY CODE ###

#!/usr/bin/env python3 ## -*- python -*-

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

    for i in range(q):
        d = input()
        if d[0] == "1":
            s = s[::-1]
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                s = c + s
            else: # f == 2
                s = s + c

    print(s)

main()

### FIXED CODE ###

#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()