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

import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    sys.setrecursionlimit(int(pow(10,6)))
    sys.stdin = open("input.txt", "r")
    # sys.stdout = open("../output.txt", "w")
except:
    pass


s=input()
t=input()
global ans
ans=""
@lru_cache(None)
def rec(i,j,x):
    global ans
    if len(x)>len(ans):
        ans=x
    if len(x)+min(abs(i-len(s)),abs(j-len(t)))<len(ans):
        return
    if i>=len(s) or j>=len(t):
        return
    if s[i]==t[j]:
        rec(i+1,j+1,x+s[i])
        return
    rec(i+1,j,x)
    rec(i,j+1,x)
rec(0,0,"")
print("".join(ans))


endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")



### FIXED CODE ###

from subprocess import*
call(('pypy3','-c',"""
s=input()
t=input()
a=len(s)
b=len(t)
dp=[[0]*(b+1) for i in range(a+1)]
for i in range(a):
  for j in range(b):
    if s[i]==t[j]:
      dp[i+1][j+1]=dp[i][j]+1
    else:
      dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
res=''
while a!=0 and b!=0:
  if dp[a][b]==dp[a-1][b]:
    a-=1
  elif dp[a][b]==dp[a][b-1]:
    b-=1
  else:
    a-=1
    b-=1
    res=s[a]+res
print(res)
"""))
"""
from subprocess import*
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    # sys.setrecursionlimit(int(pow(10,6)))
    # sys.stdin = open("input.txt", "r")
    # sys.stdout = open("../output.txt", "w")
except:
    pass

"""
### BUGGY CODE ###

N = int(input())

ans = 0
for i in range(1,N) :
    ans += i
print(ans)



### FIXED CODE ###

N = int(input())

ans = (N-1)*N//2
print(ans)
### BUGGY CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def bfs(k):
    c = [[0]*n for i in range(n)]
    dist = [-1]*n
    que = deque([0])
    dist[0] = 0
    v_prev = 0
    while que:
        v = que.popleft()
        d = dist[v]
        color = set(range(1, k+1))
        used = []
        for w in g[v]:
            if dist[w] > -1:
                used.append(c[v][w])
        color.difference_update(used)
        color = deque(color)
        for w in g[v]:
            if dist[w] > -1:
                continue
            c[v][w] = c[w][v] = color.popleft()
            dist[w] = d + 1            
            que.append(w)
    return c

n = INT()
a = [0]*(n-1)
b = [0]*(n-1)
g = [[] for i in range(n)]
for i in range(n-1):
    a[i], b[i] = MAP()
    a[i] -= 1
    b[i] -= 1
    g[a[i]].append(b[i])
    g[b[i]].append(a[i])
k = 0
for x in g:
    k = max(k, len(x))
print(k)
c = bfs(k)
for i in range(n-1):
    print(c[a[i]][b[i]])

### FIXED CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())

def solve():
    n = INT()
    Q = [tuple(MAP1()) for _ in range(n-1)]

    deg = [0]*n
    adj = [[] for _ in range(n)]
    color = dict()

    for a, b in Q:
        deg[a] += 1
        deg[b] += 1
        adj[a].append(b)
        adj[b].append(a)

    def dfs(s, p):
        nouse = -1
        if p > -1:
            nouse = color[(min(s,p),max(s,p))]
        c = 1
        for t in adj[s]:
            if t == p:
                continue
            if c == nouse:
                c += 1
            color[(min(s,t),max(s,t))] = c
            dfs(t,s)
            c += 1
    
    dfs(1,-1)
    
    print(max(deg))
    for a, b in Q:
        print(color[(a, b)])

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

N, T = map(int, input().split())
table = [[0] * (N + 1) for _ in range(T + 1)]
dish = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda t: t[0])
for t in range(T + 1):
    for n in range(N):
        minutes_to_take, deliciousness = dish[n]
        now = table[t][n]
        if t < T:
            table[min(T, t + minutes_to_take)][n + 1] = max(table[min(T, t + minutes_to_take)][n + 1], now + deliciousness)
        if n < N:
            table[t][n + 1] = max(table[t][n + 1], now)
print(max(table[t][N] for t in range(T + 1)))

### FIXED CODE ###

N, T = map(int, input().split())
table = [[0] * (N + 1) for _ in range(T + 1)]
dish = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda t: t[0])
for t in range(T + 1):
    for n in range(N):
        minutes_to_take, deliciousness = dish[n]
        now = table[t][n]
        if t < T:
            table[min(T, t + minutes_to_take)][n + 1] = max(table[min(T, t + minutes_to_take)][n + 1], now + deliciousness)
        if n < N:
            table[t][n + 1] = max(table[t][n + 1], now)
print(max(table[t][N] for t in range(T + 1)))
### BUGGY CODE ###

N, M, Q = map(int, input().split())
trains = {}
answers = {}
results = []
def make_range(L, R):
    return (pow(2, (R-L+1))-1)<<L-1

for i in range(M):
    a, b = map(int, input().split())
    train = make_range(a, b)
    if train in trains:
        trains[train] += 1
    else:
        trains[train] = 1
    
for i in range(Q):
    a, b = map(int, input().split())
    question = make_range(a, b)
    if question in answers:
        results.append(answers[question])
    else:
        res = 0
        for train in trains:
            if question | train == question:
                res += trains[train]
        answers[question] = res
        results.append(res)

for result in results:
    print(result)

### FIXED CODE ###

N, M, Q = map(int, input().split())

dp = [[0 for col in range(N)] for row in range(N)]

for i in range(M):
    l, r = map(int, input().split())
    dp[l-1][r-1]+=1

for i in range(N):
    for j in range(N)[:-1]:
        dp[i][j+1] += dp[i][j]
        
for i in range(N)[:0:-1]:
    for j in range(N):
        dp[i-1][j] += dp[i][j]

results = []

for i in range(Q):
    l, r = map(int, input().split())
    results.append(dp[l-1][r-1])

for result in results:
    print(result)
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
S = S[0:len(S)-1]
ac = []
for _ in range(N-1):
    if S[_:_+2] == 'AC':
        ac.append(1)
    else:
        ac.append(0)
ac.append(0)
for q in range(Q):
    r,l = map(int,input().split())
    print(sum(ac[r-1:l-1]))

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])
### BUGGY CODE ###

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

# 一度たずねた場所はループが判明しているのでそのままにする(何度移動させるかに関係なくtree構造がつながっているかを調べたい)
ans = -10 ** 18
for i in range(N):
    x = i
    loop = []
    total = 0
    while True:
        x = P[x] - 1
        loop.append(C[x])
        total += C[x]
        if x == i:
            break

    T = len(loop)
    tmp = 0
    for j in range(T):
        tmp += loop[j]
        if K < j + 1:
            break
        now = tmp
        # 一周のループが正の時のみ何度も回す価値がある。それ以外のときはそれまでの最大をとる
        if total > 0:
            loop_times = (K - (j + 1)) // T
            now += total * loop_times

        ans = max(ans, now)
print(ans)


### FIXED CODE ###

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

# 一度たずねた場所はループが判明しているのでそのままにする(何度移動させるかに関係なくtree構造がつながっているかを調べたい)
ans = -10 ** 18
for i in range(N):
    x = i
    loop = []
    total = 0
    while True:
        x = P[x] - 1
        loop.append(C[x])
        total += C[x]
        if x == i:
            break

    T = len(loop)
    tmp = 0
    for j in range(T):
        tmp += loop[j]
        if K < j + 1:
            break
        now = tmp
        # 一周のループが正の時のみ何度も回す価値がある。それ以外のときはそれまでの最大をとる
        if total > 0:
            loop_times = (K - (j + 1)) // T
            now += total * loop_times

        ans = max(ans, now)
print(ans)
### BUGGY CODE ###

def main():
  n=int(input())
  a = tuple(map(int,input().split()))
  ans=a[0]
  for s in range(1,n):
    ans *=a[s]
  if ans > 10**18:
    print(-1)
  else:
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

n=int(input())
a = list(map(int,input().split()))
ans=a[0]
if 0 in a:
  print(0)
  exit()
for s in range(1,n):
  ans *=a[s]
  if ans > 10**18:
    print(-1)
    exit()

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

# -*- coding: utf-8 -*-
import heapq

n,m,s,t = map(int, input().split())
e = [[] for _ in range(n+1)]
for _ in range(m):
    v,u,a,b = map(int, input().split())
    e[v].append((u,(a,b)))
    e[u].append((v,(a,b)))


inf = 10**18
def dijkstra(s,cu):
    d = [inf]*(n+1)
    d[s] = 0
    q = [s]
    heapq.heapify([q])

    while len(q)>0:
        v = heapq.heappop(q)
        for u,ud in e[v]:
            if d[v]+ud[cu]>=d[u]:
                continue
            d[u] = d[v] + ud[cu]
            heapq.heappush(q, u)
    return d


da = dijkstra(s,0)
db = dijkstra(t,1)
res = [0]*n
res[n-1] = da[n]+db[n]
for i in range(n-2,-1,-1):
    res[i] = min(res[i+1], da[i+1]+db[i+1])

for r in res:
    print(10**15 - r)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import heapq
n,m,s,t = map(int, input().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    u,v,a,b = map(int, input().split())
    g[u].append((v,(a,b)))
    g[v].append((u,(a,b)))

inf = 10**18
def dijkstra(s, currency):
    d = [inf]*(n+1)
    d[s] = 0

    que = [(d[s],s)]
    heapq.heapify([que])
    while len(que)>0:
        _,v = heapq.heappop(que)
        for u,c in g[v]:
            if d[v]+c[currency]>=d[u]:
                continue
            d[u] = d[v]+c[currency]
            heapq.heappush(que, (d[u], u))
    return d

yen_c = dijkstra(s,0)
snuuk_c = dijkstra(t,1)

res = [0]*n
res[n-1] = yen_c[n] + snuuk_c[n]
for i in range(n-2,-1,-1):
    res[i] = min(res[i+1], yen_c[i+1]+snuuk_c[i+1])

for r in res:
    print(10**15-r)
### BUGGY CODE ###

def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = (a + 2**(N-i-1) % (cnt + 1))%(cnt+1)
  else:
    if cnt == 1:
      print(0)
      continue
    k = (b - 2**(N-i-1) % (cnt - 1))%(cnt-1)
  print(f(k)+1)

### FIXED CODE ###

def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = a
    k += pow(2,N-i-1,cnt+1)
    k %= cnt+1
  else:
    if cnt == 1:
      print(0)
      continue
    k = b
    k -= pow(2,N-i-1,cnt-1) 
    k %= cnt-1  
  print(f(k)+1)
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(1, n):
    ans += i
print(ans)


### FIXED CODE ###

n = int(input())
n = n - 1
if n % 2 == 1:
    ans = ((n+1)//2) * n
else:
    ans = n + (n//2) * (n-1)
print(ans)
### BUGGY CODE ###

#https://atcoder.jp/contests/agc033/tasks/agc033_a

HW = [int(i) for i in input().split()]
A = []
for i in range(HW[0]):
    A.append(list(str(input())))

B = []
for i in range(len(A)):
    B.append([])
    for j in range(len(A[i])):
        B[i].append(A[i][j])

count = 0
count2 = 0
flag = False
tmp = ['.'] * len(A[0])
while True:
    for i in range(len(A)):
        if i > 0:
            tmp = A[i-1]
        for j in range(len(A[i])):
            if A[i][j] == '.':
                if flag == True:
                    B[i][j] = '#'
                    flag = False
                else:
                    if tmp[j] == '#':
                        B[i][j] = '#'
                    if i < len(A) - 1 and A[i+1][j] == '#':
                        B[i][j] = '#'
                    elif j < len(A[i]) - 1 and A[i][j+1] == '#':
                        B[i][j] = '#'
            else:
                count += 1
                flag = True
    
    for i in range(len(A)):
        for j in range(len(A[i])):
            A[i][j] = B[i][j]
    if count == HW[0] * HW[1]:
        break
    else:
        count = 0
        count2 += 1

print(count2)

### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

h, w = MAP()
a = [STR() for _ in range(h)]
b = [[inf for _ in range(w)] for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = 0
        else:
            for k in range(4):
                ny = i + dy[k]
                nx = j + dx[k]
                if 0 <= ny < h and 0 <= nx < w:
                    b[i][j] = min(b[ny][nx] + 1, b[i][j])
for i in reversed(range(h)):
    for j in reversed(range(w)):
        if a[i][j] == '#':
            b[i][j] = 0
        else:
            for k in range(4):
                ny = i + dy[k]
                nx = j + dx[k]
                if 0 <= ny < h and 0 <= nx < w:
                    b[i][j] = min(b[ny][nx] + 1, b[i][j])
ans = 0
for i in range(h):
    ans = max(ans, max(b[i]))
print(ans)
### BUGGY CODE ###

def main():
    import numpy as np

    N, W = map(int, input().split())
    wv = np.array([list(map(int, input().split())) for i in range(0, N)])

    # DPテーブル
    dp = np.zeros((N+1, W+1), dtype=int)

    def solve():
        for n in range(N - 1, -1, -1):
            for w in range(0, W + 1):
                if w < wv[n, 0]:
                    dp[n, w] = dp[n + 1, w]
                else:
                    dp[n, w] = max(
                        dp[n+1, w], dp[n+1, w - wv[n, 0]] + wv[n, 1])
        print(dp[0, W])

    solve()


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


### FIXED CODE ###

def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))
### BUGGY CODE ###

def main():
    N, H = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    cnt = 0
    sort_B = sorted(B, reverse=True)
    for b in sort_B:
        if b > max(A):
            cnt += 1
            H -= b
        else:
            break
    
    cnt += H // max(A) if H % max(A) == 0 else H // max(A) + 1
    print(cnt)



if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N, H = map(int, input().split())

    A = [0] * N
    B = [0] * N

    num_list = []
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b

    sort_B = sorted(B, reverse=True)
    max_A = max(A)
    ans = 0
    for b in sort_B:
        if b > max_A:
            ans += 1
            H -= b
        else:
            break
        
        if H <= 0:
            break
    
    if H > 0:
        ans += -(-H // max_A)

    print(ans)

main()
### BUGGY CODE ###

N = int(input())
line = input().split()

MAX = 1000000000000000000

ans = 1

for l in line:
    ans = int(l) * ans

if ans <= MAX:
    print(ans)
else:
    print(-1)


### FIXED CODE ###

N = int(input())
line = input().split()

MAX = 1000000000000000000

ans = 1

if not '0' in line:
    for l in line:
        if l == 0:
            ans = 0
            break
        if not ans > MAX:
            ans = int(l) * ans

else:
    ans = 0


if ans <= MAX:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

import numpy as np

# 入力
N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for j in range(N)]

# DPテーブル
dp = np.zeros((N+1)*(W+1), dtype=int).reshape((N+1), (W+1))

# DPループ
for i in range(N):    # i番目の荷物について検討する
    for sum_w in range(W+1):    # 遷移の行き先の総重量
        # i番目の荷物を選ぶ場合
        if sum_w - wv[i][0] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-wv[i][0]]+wv[i][1])
        
        # i番目の荷物を選ばない場合
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
        
# 二次元リストの一番右下が最適解
print(dp[N][W])

### FIXED CODE ###

import numpy as np

# 入力
N, W = map(int, input().split())
wv = np.array([[int(i) for i in input().split()] for j in range(N)])

# DPテーブル
dp = np.zeros((N+1)*(W+1), dtype=int).reshape((N+1), (W+1))

# DPループ
for i in range(N):    # i番目の荷物について検討する
    dp[i+1][:wv[i-1][0]] = dp[i][:wv[i-1][0]]
    dp[i+1][wv[i-1][0]:] = np.maximum(dp[i][wv[i-1][0]:], dp[i][:(W+1)-wv[i-1][0]] + wv[i-1][1])
        
# 二次元リストの一番右下が最適解
print(dp[N][W])
### BUGGY CODE ###

N = int(input())

S = []
counter = 0
for i in range(N):
    temp = input()
    if not temp in S:
        counter += 1
    S.append(temp)

print(counter)


### FIXED CODE ###

N = int(input())

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

S = sorted(S)
for i in range(N-1):
    if S[i] == S[i+1]:
        counter += 1
print(N - counter)
### BUGGY CODE ###

from collections import deque
S=input()
N=int(input())
Q=[input() for i in range(N)]
T=deque(S)
cnt=0
for i in range(N):
    if Q[i][0]=="1":
        cnt+=1
    if cnt%2==0:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.appendleft(Q[i][4])
                S=list(T)
            if Q[i][2]=="2":
                T.append(Q[i][4])
                S=list(T)
    if cnt%2==1:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.append(Q[i][4])
                S=list(T)
            if Q[i][2]=="2":
                T.appendleft(Q[i][4])
                S=list(T)
if cnt%2==1:
    S=S[::-1]
print(''.join(S))

### FIXED CODE ###

from collections import deque
S=input()
N=int(input())
Q=[input() for i in range(N)]
T=deque(S)
cnt=0
for i in range(N):
    if Q[i][0]=="1":
        cnt+=1
    if cnt%2==0:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.appendleft(Q[i][4])
            if Q[i][2]=="2":
                T.append(Q[i][4])
    if cnt%2==1:
        if Q[i][0]=="2":
            if Q[i][2]=="1":
                T.append(Q[i][4])
            if Q[i][2]=="2":
                T.appendleft(Q[i][4])
if cnt%2==1:
    T.reverse()
print(''.join(T))