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


S = input()

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


for query in ql:
    if query == "1":
        S = S[::-1]
    else:
        _, tp, s2 = query.split(" ")
        if tp == "1":
            S = s2 + S
        else:
            S = S + s2
print(S)

### FIXED CODE ###


S = input()

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

rev = False
add_head = ""
add_tail = ""

for query in ql:
    if query == "1":
        rev = not rev
    else:
        _, tp, s2 = query.split(" ")

        if tp == "1":
            if not rev:
                add_head = s2 + add_head
            if rev:
                add_tail = add_tail + s2[::-1]
        else:
            if not rev:
                add_tail = add_tail + s2
            if rev:
                add_head = s2[::-1] + add_head

S = add_head + S + add_tail
if rev:
    S = S[::-1]

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

a,b,c=map(int, input().split())
krps=0
while krps<c:
  if b-a>=0:
    krps+=1
    b-=a
print(krps)

### FIXED CODE ###

a,b,c=map(int, input().split())
krps=0
while krps<c:
  if b-a>=0:
    krps+=1
    b-=a
  if b-a<0:
    break
print(krps)
### BUGGY CODE ###

from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
  q.put(a)
x = q.get()
while not q.empty():
  y=q.get()
  if y == 0:
    continue
  q.put(x % y)
  x = y
print(x)

### FIXED CODE ###

from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(-a)
x = -q.get()
while not q.empty():
    y = -q.get()
    if y == 0:
        break
    q.put(-(x % y))
    x = y
print(x)
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
ans_count=[True]*N
for i in range(1,N):
    if(P[i]>=min(P[:i])):
        ans_count[i]=False
print(ans_count.count(True))


### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
minP = P[0]
ans = 1
for i in P[1:]:
    if(i<=minP):
        minP = i
        ans += 1
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
def main():
    from collections import deque
    from itertools import product

    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    h_indexes = [x for x in range(H)]
    w_indexes = [x for x in range(W)]
    move = ((0, 1), (0, -1), (1, 0), (-1, 0))
    ans = 0
    for sh, gh in product(h_indexes, repeat=2):
        for sw, gw in product(w_indexes, repeat=2):
            if S[sh][sw] == '#' or S[gh][gw] == '#':
                continue
            queue = deque([(sh, sw)])
            distance = [[0] * W for _ in range(H)]
            while queue:
                h, w = queue.popleft()
                if h == gh and w == gw:
                    break
                for dh, dw in move:
                    nh = h + dh
                    nw = w + dw
                    if (1
                            and 0 <= nh < H
                            and 0 <= nw < W
                            and S[nh][nw] == '.'
                            and distance[nh][nw] == 0):
                        distance[nh][nw] = distance[h][w] + 1
                        queue.append((nh, nw))
            if ans < distance[gh][gw]:
                ans = distance[gh][gw]
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    from collections import deque
    import numpy as np

    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    move = ((0, 1), (0, -1), (1, 0), (-1, 0))
    seen = [[False] * W for _ in range(H)]
    ans = 0
    for sh in range(H):
        for sw in range(W):
            if S[sh][sw] == '#' or seen[sh][sw]:
                continue
            seen[sh][sw] = True
            queue = deque([(sh, sw)])
            # distance = np.zeros((H, W), dtype=np.int16)
            distance = np.full((H, W), -1, dtype=np.int16)
            distance[sh, sw] = 0
            while queue:
                h, w = queue.popleft()
                for dh, dw in move:
                    nh = h + dh
                    nw = w + dw
                    if (1
                            and 0 <= nh < H
                            and 0 <= nw < W
                            and S[nh][nw] == '.'
                            and distance[nh][nw] == -1):
                        distance[nh][nw] = distance[h][w] + 1
                        queue.append((nh, nw))
            ans = max(ans, distance.max())
    print(ans)


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

from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

s = input() + "T"
x, y = map(int, input().split())

stepx = []
stepy = []

headx = True
step = 0
for c in s:
    if c == "F":
        step += 1
    else:
        if headx:
            stepx.append(step)
        else:
            stepy.append(step)
        headx = not headx
        step = 0

x -= stepx[0]
stepx = stepx[1:]


class Reachable:
    def __init__(self, steps):
        self.steps = steps

        self.maxs = sum(steps)
        self.r = {
            i: {s: None for s in range(-self.maxs, self.maxs + 1)}
            for i in range(len(steps))
        }

    def __call__(self, i, s):
        if i == -1:
            return s == 0
        elif not -self.maxs <= s <= self.maxs:
            return False
        elif self.r[i][s] is not None:
            return self.r[i][s]
        else:
            step = self.steps[i]
            r = self(i - 1, s - step) or self(i - 1, s + step)
            self.r[i][s] = r
            return r


answer = Reachable(stepx)(len(stepx) - 1, x) and Reachable(stepy)(len(stepy) - 1, y)

if answer:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

s = input() + "T"
x, y = map(int, input().split())

stepx = []
stepy = []

headx = True
step = 0
for c in s:
    if c == "F":
        step += 1
    else:
        if headx:
            stepx.append(step)
        else:
            stepy.append(step)
        headx = not headx
        step = 0

x -= stepx[0]
stepx = stepx[1:]


class Reachable:
    def __init__(self, steps):
        self.steps = steps

        self.maxs = sum(steps)
        self.r = [{} for _ in range(len(steps))]

    def __call__(self, i, s):
        if i == -1:
            return s == 0
        elif not -self.maxs <= s <= self.maxs:
            return False
        elif self.r[i].get(s, None) is not None:
            return self.r[i][s]
        else:
            step = self.steps[i]
            r = self(i - 1, s - step) or self(i - 1, s + step)
            self.r[i][s] = r
            return r


answer = Reachable(stepx)(len(stepx) - 1, x) and Reachable(stepy)(len(stepy) - 1, y)

if answer:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

from collections import deque
H,W = map(int,input().split())
grid = [0] * H
for i in range(H):
    grid[i] = input()
start_points = []
for y in range(H):
    for x in range(W):
        if grid[y][x] == '#':
            start_points.append([y,x])

ans = 0
for sy, sx in start_points:
    q = deque()
    q.append([sy,sx])
    done = [[0]*W for _ in range(H)]
    done[sy][sx] = 1
    while q:
        y,x = q.popleft()
        now = grid[y][x]
        for new_y, new_x in [[y+1,x],[y,x+1],[y-1,x],[y,x-1]]:
            if 0<= new_y < H and 0<= new_x < W and not done[new_y][new_x]:
                if grid[y][x] != grid[new_y][new_x]:
                    # 白ならans++
                    if grid[new_y][new_x] == '.':
                        ans+= 1
                    
                    q.append([new_y,new_x])
                    done[new_y][new_x] = 1
    
print(ans)

### FIXED CODE ###

from collections import deque
H,W = map(int,input().split())
grid = [0] * H
for i in range(H):
    grid[i] = input()

ans = 0

done = [[0]*W for _ in range(H)]
for sy in range(H):
    for sx in range(W):
        if done[sy][sx]:
            continue
        # 初期状態
        q = deque()
        q.append([sy,sx])
        done[sy][sx] = 1
        n_white = 0
        n_black = 0
        if grid[sy][sx] == '.':
            n_white += 1
        else:
            n_black += 1

        while q:
            y,x = q.popleft()
            for new_y, new_x in [[y+1,x],[y,x+1],[y-1,x],[y,x-1]]:
                if 0<= new_y < H and 0<= new_x < W and not done[new_y][new_x]:
                    if grid[y][x] != grid[new_y][new_x]:
                        # 色ごとの数更新
                        if grid[new_y][new_x] == '.':
                            n_white += 1
                        else:
                            n_black += 1
                        
                        done[new_y][new_x] = 1
                        q.append([new_y,new_x])
        ans += n_black*n_white
print(ans)
### BUGGY CODE ###

mod=10**9+7
def num2bi(x, k):
  #10進数xを2進数k桁(string)で出力
  out=format(x, '0'+str(k)+'b')
  return out

N=int(input())
A=list(map(int, input().split()))
ma=max(A)
keta=1
while ma>=2**keta:
  keta+=1
  
onekazu=[0 for i in range(keta)]
k=str(keta)
for i in range(N):
  temp=format(A[i], '0'+str(k)+'b')
  for j in range(keta):
    onekazu[-1-j]+=int(temp[-1-j])
    
out=0
for i in range(keta):
  temp=onekazu[i]*(N-onekazu[i])
  temp%=mod
  temp*=(2**(keta-1-i))
  temp%=mod
  out+=temp
  out%=mod
  
print(out)

### FIXED CODE ###

mod=10**9+7
def num2bi(x, k):
  #10進数xを2進数k桁(string)で出力
  out=format(x, '0'+str(k)+'b')
  return out

N=int(input())
A=list(map(int, input().split()))
ma=max(A)
keta=1
while ma>=2**keta:
  keta+=1
  
onekazu=[0 for i in range(keta)]
k=str(keta)
for i in range(N):
  temp=format(A[i], '0'+str(k)+'b')
  onekazu=[onekazu[j]+1 if temp[j]=='1' else onekazu[j] for j in range(keta)]
    
out=0
out=sum([(onekazu[i]*(N-onekazu[i])%mod)*(2**(keta-1-i))%mod for i in range(keta)])
out%=mod  
print(out)
### BUGGY CODE ###

from collections import deque
h,w=map(int, input().split())
a=[[i for i in input()] for j in range(h)]
q=[]
ans=-1
for i in range(h):
    for j in range(w):
        if(a[i][j]=="#"):
            q.append([i,j])
while len(q)>0:
    tl=deque(q)
    q.clear()
    for i in tl:
        y=i[0]
        x=i[1]
        if(y>0):
            if(a[y-1][x]=="."):
                a[y-1][x]="#"
                q.append([y-1,x])
        if(x>0):
            if(a[y][x-1]=="."):
                a[y][x-1]="#"
                q.append([y,x-1])
        if(y<h-1):
            if(a[y+1][x]=="."):
                a[y+1][x]="#"
                q.append([y+1,x])
        if(x<w-1):
            if(a[y][x+1]=="."):
                a[y][x+1]="#"
                q.append([y,x+1])
    ans+=1
print(ans)

### FIXED CODE ###

h,w=map(int, input().split())
a=[[i for i in input()] for j in range(h)]
q=[]
ans=-1
for i in range(h):
    for j in range(w):
        if(a[i][j]=="#"):
            q.append([i,j])
while len(q)>0:
    tl=q
    q=[]
    for i in tl:
        y=i[0]
        x=i[1]
        if(y>0):
            if(a[y-1][x]=="."):
                a[y-1][x]="#"
                q.append([y-1,x])
        if(x>0):
            if(a[y][x-1]=="."):
                a[y][x-1]="#"
                q.append([y,x-1])
        if(y<h-1):
            if(a[y+1][x]=="."):
                a[y+1][x]="#"
                q.append([y+1,x])
        if(x<w-1):
            if(a[y][x+1]=="."):
                a[y][x+1]="#"
                q.append([y,x+1])
    ans+=1
print(ans)
### BUGGY CODE ###

h,w = map(int,input().split())
li = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    s = input()
    count = 0
    for j in range(w):
        if j != w-1:
            if s[j] == '.':
                count += 1
            else:
                li[i][j] = 0
                for k in range(count):
                    li[i][j-k-1] = count
                count = 0
        else:
            if s[j] == '.':
                count += 1
                for k in range(count):
                    li[i][j-k] = count
            else:
                li[i][j] = 0
                for k in range(count):
                    li[i][j-k-1] = count

for i in range(w):
    count = 0
    for j in range(h):
        if j != h-1:
            if li[j][i] > 0:
                count += 1
            else:
                for k in range(count):
                    li[j-k-1][i] += count
                count = 0
        else:
            if li[j][i] > 0:
                count += 1
                for k in range(count):
                    li[j-k][i] += count
            else:
                for k in range(count):
                    li[j-k-1][i] += count

ans = 0

for i in range(h):
    ans = max(ans,max(li[i]))

print(ans-1)


### FIXED CODE ###

h,w = map(int,input().split())
s = [input() for _ in range(h)]

l = [[0] * w for _ in range(h)]
r = [[0] * w for _ in range(h)]
u = [[0] * w for _ in range(h)]
d = [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i][j] = 0
        else:
            if j == 0:
                l[i][j] = 1
            else:
                l[i][j] = l[i][j-1] + 1

for i in range(h):
    for j in range(w-1, -1, -1):
        if s[i][j] == '#':
            r[i][j] = 0
        else:
            if j == w-1:
                r[i][j] = 1
            else:
                r[i][j] = r[i][j+1] + 1

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            u[i][j] = 0
        else:
            if i == 0:
                u[i][j] = 1
            else:
                u[i][j] = u[i-1][j] + 1

for i in range(h-1, -1 ,-1):
    for j in range(w):
        if s[i][j] == '#':
            d[i][j] = 0
        else:
            if i == h-1:
                d[i][j] = 1
            else:
                d[i][j] = d[i+1][j] + 1

ans = 0

for i in range(h):
    for j in range(w):
        ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3)

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

# coding: utf-8
from functools import lru_cache
import sys


def solve(*args: str) -> str:
    n, m = map(int, args[0].split())

    keys = list(zip(
        list(map(lambda _: int(_.split()[0]), args[1::2])),
        map(
            lambda _: set2bin(
                set(map(int, _.split())),
                n, start=1
            ), args[2::2])
    ))
    dp = DP(keys, n, 12*10**5)
    sys.setrecursionlimit(2**31-1)
    ret = dp.search_min_cost(0, 0)

    return str(-1 if 12*10**5 < ret else ret)


class DP:
    def __init__(self, keys: list, n: int, max: int):
        self._keys = keys
        self._mask = int('1'*n, 2)
        self._max = 1+max

    @lru_cache(maxsize=None)
    def search_min_cost(self, index: int, unlocked: int) -> int:
        ret = 0

        if len(self._keys) == index:
            if unlocked != self._mask:
                ret = self._max

        else:
            a, C = self._keys[index]
            ret = min(
                a+self.search_min_cost(index+1, C | unlocked),
                self.search_min_cost(index+1, unlocked)
            )

        return ret


def set2bin(S: set, n: int, start: int = 0) -> int:
    ret = 0
    for s in S:
        ret += 2**(s-start)
    return ret


def bin2int(B: list) -> int:
    ret = 0
    for n in range(len(B)):
        if B[n]:
            ret += 2**n

    return ret


if __name__ == "__main__":
    nm = input()
    _, m = map(int, nm.split())
    print(solve(*([nm]+[input() for _ in range(2*m)])))


### FIXED CODE ###

# coding: utf-8
from functools import reduce


def solve(*args: str) -> str:
    a_max = 1+12*10**5
    n, m = map(int, args[0].split())
    cache = {}

    for i in range(1, 1+2*m, 2):
        a, _ = map(int, args[i].split())
        c = reduce(
            lambda x, y: x | 1 << y-1,
            [0] + list(map(int, args[i+1].split()))
        )
        cache[c] = min(cache.get(c, a_max), a)

    for C in tuple(cache.items()):
        unlocked, cost = C
        for E in tuple(cache.items()):
            c, a = E
            cache[unlocked | c] = min(
                cache.get(unlocked | c, a_max),
                a + cost
            )

    return str(cache.get(2**n-1, -1))


if __name__ == "__main__":
    nm = input()
    _, m = map(int, nm.split())
    print(solve(*([nm]+[input() for _ in range(2*m)])))
### BUGGY CODE ###

K, S = map(int, input().split())
cnt=0
for X in range(K+1):
  for Y in range(K+1):
    for Z in range(K+1):
      if X+Y+Z==S:
        cnt += 1
print(cnt)

### FIXED CODE ###

K, S = map(int, input().split())
cnt=0
for X in range(K+1):
  for Y in range(K+1):
    if K>=S-(X+Y) and X+Y<=S:
      cnt=cnt+1
print(cnt)
### BUGGY CODE ###

def sum1(n):
    ans=0
    for i in range(1,n):
        ans=ans+i

    return ans
n=int(input())
print(sum1(n))

### FIXED CODE ###

##################
n = int(input())
print((n*(n-1))//2)
### BUGGY CODE ###

S=input()
modn=10**9+7
qnum=S.count('?')
lenS=len(S)

dpa=[0]*13
dpb=[1]+[0]*12


for i in range(lenS):
    dpa=[0]*13
    if S[i]!='?':
        num=int(S[i]) 
        for j in range(13):
            dpa[((j*10)+num)%13]=dpb[j]
            dpa[((j*10)+num)%13]%=modn
    else:
        for k in range(10):
            for j in range(13):
                dpa[((j*10)+k)%13]+=dpb[j]
                dpa[((j*10)+k)%13]%=modn
    dpb=dpa
print(dpa[5])

### FIXED CODE ###

M=10**9+7
r=[[(j-k)*9%13 for j in range(10)]for k in range(13)]
d=[1]+[0]*12
for c in input():
    d = [sum(d[j]for j in k)%M for k in r] if c>'9' else [d[(int(c)-k)*9%13]for k in range(13)]
print(d[5])
### BUGGY CODE ###

n = int(input())
a = ['']*n
for i in range(n):
    a[i] = int(input())

for i in range(n):
    tmp = a[i]
    a[i] = 0
    print(max(a))
    a[i] = tmp

### FIXED CODE ###

n = int(input())
a = ['']*n
for i in range(n):
    a[i] = int(input())
_a = sorted(a, reverse=1)
a_max = _a[0]
a_second = _a[1]
ans = [a_max] * n

for i in range(n):
    if a[i] == a_max:
        ans[i] = a_second
    else:
        pass

print(*ans, sep='\n')
### BUGGY CODE ###

from collections import deque
N, M, K = map(int, input().split())
A = [set() for i in range(N)]
B = [set() for i in range(N)]
for i in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  A[a].add(b)
  A[b].add(a)
for i in range(K):
  a, b = map(lambda x:int(x)-1, input().split())
  B[a].add(b)
  B[b].add(a)
P = [-1 for i in range(N)]
Q = []
k = -1
for i in range(N):
  if P[i] == -1:
    q = {i}
    k += 1
    P[i] = k
    d = deque([i])
    while len(d):
      s = d.pop()
      for t in A[s]:
        if P[t] == -1:
          P[t] = k
          q.add(t)
          d.append(t)
    Q.append(q)
for i in range(N):
  print(len(Q[P[i]] - A[i] - B[i]) - 1)

### FIXED CODE ###

from collections import deque
N, M, K = map(int, input().split())
A = [[] for i in range(N)]
B = [[] for i in range(N)]
for i in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  A[a].append(b)
  A[b].append(a)
for i in range(K):
  a, b = map(lambda x:int(x)-1, input().split())
  B[a].append(b)
  B[b].append(a)
P = [-1 for i in range(N)]
Q = []
k = -1
for i in range(N):
  if P[i] == -1:
    q = 1
    k += 1
    P[i] = k
    d = deque([i])
    while len(d):
      s = d.pop()
      for t in A[s]:
        if P[t] == -1:
          P[t] = k
          q += 1
          d.append(t)
    Q.append(q)
for i in range(N):
  ans = Q[P[i]] - len(A[i]) - 1
  for j in B[i]:
    if P[i] == P[j]:
      ans -= 1
  print(ans)
### BUGGY CODE ###

import sys
from collections import deque
N, M = map(int, input().split())
Edge = [[] for _ in range(N+1)]
comp = set()
mod = 10**9+7
for _ in range(M):
    p, q, c = map(int, input().split())
    Edge[p].append(mod*q+c)
    Edge[q].append(mod*p+c)
    comp.add(c)
dist = {mod: 0}
Q = deque()
Q.append(mod)
visited = set()
while Q:
    vn, cp = divmod(Q.pop(), mod)
    if mod*vn+cp in visited:
        continue
    if vn == N:
        break
    visited.add(mod*vn+cp)
    for t in Edge[vn]:
        vf, cf = divmod(t, mod)
        if mod*vf+cp in visited:
            continue
        if cp == cf:
            dist[mod*vf+cf] = min(dist.get(mod*vf+cf, 10**9), dist.get(mod*vn+cp, 10**9))
            Q.append(mod*vf+cf)
        else:
            dist[mod*vf+cf] = min(dist.get(mod*vf+cf, 10**9), 1 + dist.get(mod*vn+cp, 10**9))
            Q.appendleft(mod*vf+cf)
L = [dist.get(N*mod+c, 10**9) for c in comp]
if not L or min(L) == 10**9:
    print(-1)
else:
    print(min(L))


### FIXED CODE ###

import sys
readline = sys.stdin.readline

from heapq import heappop as hpp, heappush as hp
inf = 10**9+7
def dijkstra(N, s, Edge):    
    dist = [inf] * N
    dist[s] = 0
    Q = [(0, s)]
    while Q:
        dn, vn = hpp(Q)
        if dn > dist[vn]:
            continue
        for df, vf in Edge[vn]:
            if dn + df < dist[vf]:
                dist[vf] = dn + df
                hp(Q, (dn + df,vf))
    return dist

def compress(L):
    L2 = list(set(L))
    L2.sort()
    C = {v : k for k, v in enumerate(L2)}
    return L2, C


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

Edge = []
VS = set(range(N))
geta = 20
Edge = [tuple(map(int, readline().split())) for _ in range(M)]
for a, b, c in Edge:
    a -= 1
    b -= 1
    VS |= {(c<<geta) | a, (c<<geta) | b}
   
_, Cv = compress(list(VS))

Vnum = len(Cv)

nEdge = [[] for _ in range(Vnum)]

for a, b, c in Edge:
    a -= 1
    b -= 1
    ca = Cv[(c<<geta) | a]
    cb = Cv[(c<<geta) | b]
    nEdge[ca].append((0, cb))
    nEdge[cb].append((0, ca))
    nEdge[a].append((1, ca))
    nEdge[ca].append((0, a))
    nEdge[b].append((1, cb))
    nEdge[cb].append((0, b))

dist = dijkstra(Vnum, 0, nEdge)
if dist[N-1] >= inf:
    dist[N-1] = -1
print(dist[N-1])
### BUGGY CODE ###

import itertools

N = int(input())
S = input()




num_list = ['1','2','3','4','5','6','7','8','9','0']

ans = 0
for nums in itertools.product(num_list,num_list,num_list):
	j = 0
	for i in range(N):
		if S[i] == nums[j]:
			j+=1
		if j == 3:
			ans += 1
			break

print(ans)

### FIXED CODE ###

N = int(input())
S = input()
t = []
for i in range(10):
	if str(i) not in S:
		t.append(i)
cnt = 0
flg1 = [0] * 10
ind1 = 0
for i in t:
	flg1[i] = 1
while True:
	if flg1[int(S[ind1])] == 1:
		ind1 += 1
	else:
		flg2 = [0] * 10
		for i in t:
			flg2[i] = 1
		ind2 = ind1 + 1
		while True:
			if flg2[int(S[ind2])] == 1:
				ind2 += 1
			else:
				flg3 = [0] * 10
				for i in t:
					flg3[i] = 1
				ind3 = ind2 + 1
				while True:
					if flg3[int(S[ind3])] == 1:
						ind3 += 1
					else:
						flg3[int(S[ind3])] = 1
						cnt += 1
						ind3 += 1

					if flg3.count(0) == 0:
						break
					if ind3 == N:
						break
				flg2[int(S[ind2])] = 1
				ind2 += 1
			if flg2.count(0) == 0:
				break
			if ind2 == N-1:
				break
		flg1[int(S[ind1])] = 1
		ind1 += 1
	if flg1.count(0) == 0:
		break
	if ind1 == N-2:
		break

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

n = int(input())
s = list(map(int,input().split()))
p = []

for i in range(n):
    j = s.index(i + 1) + 1
    p.append(str(j))

print(' '.join(p))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
t = ['0'] * n

for i in range(n):
    t[a[i] - 1] = str(i + 1)

print(' '.join(t))