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

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
a=[]
for i in range(0,n):
  a.append(int(input()))
a.sort()

b = [a[0]]
a=a[1:]

f=True
while len(a)>0:
  ln = abs(b[0]-a[0])
  lx = abs(b[0]-a[len(a)-1])
  rn = abs(b[len(b)-1]-a[0])
  rx = abs(b[len(b)-1]-a[len(a)-1])

  x = max(ln, max(lx, max(rn, rx)))
  
  if x == ln:
    b.insert(0,a[0])
    a=a[1:]
  elif x == lx:
    b.insert(0,a.pop())
  elif x == rn:
    b.append(a[0])
    a=a[1:]
  else:
    b.append(a.pop())

res=0
for i in range(0,len(b)-1):
  res=res+abs(b[i]-b[i+1])
print(res)


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
a=[]
for i in range(0,n):
  a.append(int(input()))
a.sort()

l = a[0]
r = a[0]

li=1
ri=len(a)-1

res = 0

while ri>=li:
  ln = abs(l-a[li])
  lx = abs(l-a[ri])
  rn = abs(r-a[li])
  rx = abs(r-a[ri])

  x = max(ln, max(lx, max(rn, rx)))
  
  if x == ln:
    res = res + ln
    l=a[li]
    li=li+1
  elif x == lx:
    res = res + lx
    l=a[ri]
    ri=ri-1
  elif x == rn:
    res = res + rn
    r=a[li]
    li=li+1
  else:
    res = res + rx
    r=a[ri]
    ri=ri-1

print(res)
### BUGGY CODE ###

N, K, Q = list(map(int, input().split()))
A = [int(input()) for i in range(Q)]
for n in range(N):
    if A.count(n+1)+K-Q > 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

import collections
N, K, Q = list(map(int, input().split()))
A = [int(input()) for i in range(Q)]
cs = collections.Counter(A)
for n in range(N):
    if cs[n+1] > Q-K:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
a = len(lst) - K + 1
n = 0
ret_lst = []
for i in range(a):
    m = sum(lst[i : i + K])
    if n < m:
        n = m
        ret_lst = lst[i : i + K]

ll = [x / 2 * (x + 1) / x for x in ret_lst]
print(sum(ll))


### FIXED CODE ###

N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
tmp = sum(lst[:K])
ret = tmp
for i in range(N - K):
    tmp -= lst[i]
    tmp += lst[i + K]
    ret = max(ret, tmp)
print((ret + K) / 2)
### BUGGY CODE ###

import heapq

N, M, S = map(int, input().strip().split())

graph = [[] for _ in range(N)]
for _ in range(M):
	u, v, A, B = map(int, input().strip().split())
	u -= 1
	v -= 1
	graph[u].append((v, A, B))
	graph[v].append((u, A, B))

exchanges = []
for _ in range(N):
	C, D = map(int, input().strip().split())
	exchanges.append((C, D))

queue = [(0, 0, S)]

state_table = [[None] * (2500 + 1) for i in range(N)]

reached = [False] * N
reached_count = 0

while queue:
#	print(len(queue))
	time, cur, money = heapq.heappop(queue)
	if not reached[cur]:
		reached[cur] = True
		reached_count += 1
		if reached_count >= N:
			break
	count, d_time = exchanges[cur]
	for n, A, B in graph[cur]:
		n_money = money - A
		n_time = time + B
		states = state_table[n]
		max_fare = 2500
		while True:
			if n_money >= 0:
				if n_money > max_fare:
					n_money = max_fare
				if states[n_money] == None or states[n_money] > n_time:
					states[n_money] = n_time
					heapq.heappush(queue, (n_time, n, n_money))
				if n_money >= max_fare:
					break
			n_money += count
			n_time += d_time

#for i in range(N):
#	print(i, state_table[i])

for i in range(1, N):
	states = state_table[i]
	minimum = None
	for t in states:
		if t != None and (minimum == None or minimum > t):
			minimum = t
	print(minimum)


### FIXED CODE ###

import heapq

N, M, S = map(int, input().strip().split())

graph = [[] for _ in range(N)]
for _ in range(M):
	u, v, A, B = map(int, input().strip().split())
	u -= 1
	v -= 1
	graph[u].append((v, A, B))
	graph[v].append((u, A, B))

exchanges = []
for _ in range(N):
	C, D = map(int, input().strip().split())
	exchanges.append((C, D))

queue = [(0, 0, S)]
max_fare = 2500

state_table = [[None] * (max_fare + 1) for i in range(N)]

reached = [False] * N
reached_count = 0

while queue:
#	print(len(queue))
	time, cur, money = heapq.heappop(queue)
	if not reached[cur]:
		reached[cur] = True
		reached_count += 1
		if reached_count >= N:
			break
	count, d_time = exchanges[cur]
	for n, A, B in graph[cur]:
		n_money = money - A
		n_time = time + B
		if n_money >= 0:
			states = state_table[n]
			if n_money > max_fare:
				n_money = max_fare
			if states[n_money] == None or states[n_money] > n_time:
				states[n_money] = n_time
				heapq.heappush(queue, (n_time, n, n_money))

	states = state_table[cur]
	money += count
	time += d_time
	if money >= 0:
		if money > max_fare:
			money = max_fare
		if states[money] == None or states[money] > time:
			states[money] = time
			heapq.heappush(queue, (time, cur, money))

#for i in range(N):
#	print(i, state_table[i])

for i in range(1, N):
	states = state_table[i]
	minimum = None
	for t in states:
		if t != None and (minimum == None or minimum > t):
			minimum = t
	print(minimum)
### BUGGY CODE ###

def main():
    N, M = (int(i) for i in input().split())
    ABC = []
    c_all_or = 0
    for i in range(M):
        a, b = (int(j) for j in input().split())
        c = {int(j)-1 for j in input().split()}
        c_all_or |= sum(2**j for j in c)
        ABC.append((a,b,c))
    if c_all_or != ((1<<N) - 1):
        print(-1)
        return 0
    r = [10**9] * (1<<N)
    r[0] = 0
    for bit in range(1,1<<N):
        q = r[bit]
        for i in range(M):
            cur = sum(2**j for j in ABC[i][2])
            less = (bit ^ cur) & bit
            q = min(q,r[less] + ABC[i][0])
        r[bit] = q
    
    print(r[(1<<N) - 1])
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    ABC = []
    c_all_or = 0
    where_open = lambda s: sum(2**j for j in s)
    for i in range(M):
        a, b = (int(j) for j in input().split())
        c = {int(j)-1 for j in input().split()}
        wc = where_open(c)
        c_all_or |= wc
        ABC.append((a,b,wc))
    if c_all_or != ((1<<N) - 1):
        print(-1)
        return 0
    r = [10**9] * (1<<N)
    r[0] = 0
    for bit in range(1,1<<N):
        q = r[bit]
        for i in range(M):
            cur = ABC[i][2]
            less = (bit ^ cur) & bit
            q = min(q,r[less] + ABC[i][0])
        r[bit] = q
    
    print(r[(1<<N) - 1])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

input()
l = list(map(int, input().split()))
res = 1
for x in l:
  res *= x
if res > 10**18:
  res = -1
print(res)

### FIXED CODE ###

input()
l = list(map(int, input().split()))
l.sort()
res = 1
for x in l:
  res *= x
  if res > 10**18:
    print(-1)
    exit(0)
print(res)
### BUGGY CODE ###

n, k = map(int, input().split())
mod = 10**9+7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6 +1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if k >= n-1:
    print(cmb(2*n-1, n-1, mod))
    exit()

ans = 0
for i in range(k):
    j = i+1
    for r in range(1, j+1):
        ans += cmb(n, j, mod) * cmb(n-j, r, mod) * cmb(j-1, r-1, mod)
        ans %= mod
    #if j >= 2:
        #ans += 1
        #ans %= mod
print(ans+1)


### FIXED CODE ###


def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n, k = map(int, input().split())
mod = 10**9+7
ans = 0
k_ = min(n-1, k)
for i in range(k_+1):
    ans += cmb1(n, i, mod) * cmb1(n-i-1+i, i, mod)
    ans %= mod
print(ans)
### BUGGY CODE ###

import sys
n,m = map(int,sys.stdin.readline().split())
# sys.stdout.write('{} {}'.format(n,m))
vertices = [[] for _ in range(n+1)]
jumpValue = [[-1,-1,-1] for _ in range(n+1)]
visited = set()
queue = []
def bfs(arr,jump):
    temp = []
    for node in arr:
        # print('NODE:',node,jumpValue[node][(jump+1)%3])
        if jumpValue[node][(jump+1)%3]==-1:
            queue.append([node,jump+1])
            # queue.append(node)
        temp = temp+vertices[node]
        # if node==t:
        #     print('YES',jump+1)
        #     jumpValue[node].append(jump+1)
    return temp
for i in range(m):
    a,b = map(int,sys.stdin.readline().split())
    vertices[a].append(b)
s,t = map(int,sys.stdin.readline().split())
visited.add(s)
queue.append([s,0])
# print(vertices)
done =set()
while(len(queue)>0 ):
    next=queue.pop(0)
    if jumpValue[next[0]][next[1]%3] == -1:
        jumpValue[next[0]][next[1]%3] = next[1]
        # print('Next:', next[0])
        # print(jumpValue)
        # print('Queue:', queue)
        # print('NEXT', next, vertices[next[0]])
        run = bfs(vertices[next[0]], next[1])
        run = bfs(run, next[1] + 1)
        bfs(run, next[1] + 2)
        # print('----------------------------------------------')
print(max(jumpValue[t][0]//3,-1))




### FIXED CODE ###

import sys
from collections import deque
n,m = map(int,sys.stdin.readline().split())
vertices = [[] for _ in range(n+1)]
jumpValue = [[-1,-1,-1] for _ in range(n+1)]
queue = []
def bfs(arr,jump):
    for node in arr:
        if jumpValue[node][(jump+1)%3]==-1:
            queue.append([node,jump+1])
for i in range(m):
    a,b = map(int,sys.stdin.readline().split())
    vertices[a].append(b)
s,t = map(int,sys.stdin.readline().split())
queue=deque()
queue.append([s,0])
while(len(queue)>0 ):
    next=queue.popleft()
    if jumpValue[next[0]][next[1]%3] == -1:
        jumpValue[next[0]][next[1]%3] = next[1]
        bfs(vertices[next[0]], next[1])
        if jumpValue[t][0]!=-1:
            break
print(max(jumpValue[t][0]//3,-1))
### BUGGY CODE ###

from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, K = read_int()
p = read_int()

def solve():
    ans = 0
    for h in range(N - K + 1):
        partial = 0
        for i in range(h, h + K):
            partial += (p[i] + 1) / 2
        ans = max(ans, partial)
    return ans

if __name__ == "__main__":
    print(solve())


### FIXED CODE ###

import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, K = read_int()
p = read_int()


memo = [0 for i in range(N - K + 1)]

def solve():
    memo[0] = sum(p[:K])
    for i in range(1, N - K + 1):
        memo[i] = memo[i - 1] + p[i + K - 1] - p[i - 1]
    index = 0
    res = 0
    for i, m in enumerate(memo):
        if res < m:
            res = m
            index = i
    ans = 0
    for i in range(K):
        ans += (p[index + i] + 1) / 2
    return ans
if __name__ == "__main__":
    print(solve())
### BUGGY CODE ###

n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]

#print()
T = 0
A = 0
for i in range(n):
    t, a = p[i]
    if t >= T and a >= A:
        T, A = t, a
    else:
        c = 1
        while  t * c < T or a * c < A:
            c += 1
            # print(t * c, a * c)
        T, A = t * c, a * c
    # print(T, A)

print(T+A)  


### FIXED CODE ###

n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]

#print()
T = 0
A = 0
for i in range(n):
    t, a = p[i]
    if t >= T and a >= A:
        T, A = t, a
    else:
        d1 = T // t
        d2 = A // a
        if T % t != 0: d1 += 1
        if A % a != 0: d2 += 1
        d = max(d1, d2)
        T, A = d * t, d * a
    #print(T, A)

print(T+A)
### BUGGY CODE ###

if __name__=="__main__":
    import sys
    readline = sys.stdin.readline
    X,Y,Z,K = map(int, readline().split())
    a = sorted(list(map(int, readline().split())), reverse=True)
    b = sorted(list(map(int, readline().split())), reverse=True)
    c = sorted(list(map(int, readline().split())), reverse=True)

    sums = []
    lower = a[min(X-1,14)]+b[min(Y-1,14)]+c[min(Z-1,14)]
    b_max,c_max = max(b),max(c)
    for i in range(X):
        if a[i]+b_max+c_max<lower:
            break
        for j in range(Y):
            if a[i]+b[j]+c_max<lower:
                break
            for k in range(Z):
                s = a[i]+b[j]+c[k]
                if s<lower:
                    break
                sums.append(s)
    sums.sort(reverse=True)
    for si in sums[:K]:
        print(si)


### FIXED CODE ###

import sys
readline = sys.stdin.readline
X,Y,Z,K = map(int, readline().split())
a = sorted(list(map(int, readline().split())), reverse=True)
b = sorted(list(map(int, readline().split())), reverse=True)
c = sorted(list(map(int, readline().split())), reverse=True)

ab = []
for ai in a:
    for bj in b:
        ab.append(ai+bj)
ab.sort(reverse=True)
ab = ab[:K]
cond = []
for abi in ab:
    for cj in c:
        cond.append(abi+cj)
cond = sorted(cond, reverse=True)[:K]
for condi in cond:
    print(condi)
### BUGGY CODE ###

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

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])


num = 0
for i in range(N+1):
    for j in range(M+1):
        if A_sum[i]+B_sum[j] <= K:
            if num < i+j:
                num = i+j

print(num)


### FIXED CODE ###

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

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])

num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in reversed(range(J+1)):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

print(num)
### BUGGY CODE ###

import numpy as np

# Calculate intensity
N, K = [int(v) for v in input().split(" ")]
A_arr = np.array([int(v) for v in input().split(" ")])
step = np.arange(len(A_arr))
if K > N//2+11:
  print(" ".join([str(N)]*N))
  exit()

def Luminate(A_arr, i):
  isLuminated = np.abs(step - i) < A_arr
  return isLuminated

def get_Intensity(A_arr):
  return np.array([np.sum(Luminate(A_arr, i)) for i in range(len(A_arr))])
Intensity = A_arr
for i in range(K):
  Intensity = get_Intensity(Intensity+1)
  if np.all(Intensity == N):
    break
print(" ".join([str(v) for v in Intensity]))


### FIXED CODE ###

import numpy as np
 
N, K = map(int, input().split(' '))
A = tuple(map(int, input().split(' ')))
indexes = np.arange(0, N)
 
dp = np.zeros(shape=N + 1, dtype=np.int64)
 
for k in range(K):
    np.add.at(dp, np.maximum(0, indexes - A), 1)
    np.add.at(dp, np.minimum(N, indexes + A + 1), -1)
    A = dp.cumsum()[:-1]
    if np.all(A == N):
        break
    dp *= 0
 
print(' '.join(map(str, A)))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
total = 1
for i in range(n):
  total*=a[i]
if 0 in a:
  print(0)
elif total > 10**18:
  print(-1)
else:
  print(total)
  

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
total = 1
if 0 in a:
  print("0")
  exit()

for i in range(n):
  total*=a[i]
  if total > 10**18:
    print("-1")
    exit()

print(total)
### BUGGY CODE ###

import numpy as np
N,K = map(int, input().split())

A_list = [0]+list(map(int, input().split()))
A_np=np.array(A_list)
#print(A_np)

for j in range(K):
  new_A_np=np.array([0]*(N+1))
  for i in range(1,N+1):
    tmp_np=np.array([0]*(N+1))
    #print(A_np)
    mi=i-A_np[i]
    ma=i+A_np[i]
    if mi<0:
      mi=0
    if ma>N:
      ma=N
    #print(mi,ma)
    tmp_np[mi:ma+1]=1
    #print(tmp_np)
    new_A_np+=tmp_np
  #print(new_A_np)
  A_np=new_A_np
  if sum(A_np)==N*N:
    break
for i in range(1,N+1):
  print(A_np[i],end=" ")

### FIXED CODE ###

import numpy as np
from numba import njit

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

A_list = np.array([0]+list(map(int, input().split())))

@njit
def update(A_list):

  for j in range(min(K,46)):
    new_A=np.zeros(N+2,dtype=np.int64)
    for i in range(1,N+1):
      #print(new_A)
      mi=i-A_list[i]
      ma=i+A_list[i]
      if mi<0:
        mi=0
      if ma>N:
        ma=N
      #new_A[mi:ma+1]+=1
      new_A[mi]+=1
      new_A[ma+1]-=1

    A_list=np.cumsum(new_A)
    #if sum(A_list[1:N+1])==N*N:
    #  return(A_list)    
    #  break
      
  return(A_list)

A_list=update(A_list)
for i in range(1,N+1):
  print(A_list[i],end=" ")
### BUGGY CODE ###

from math import sqrt
n=int(input())
ns=int(sqrt(n)//1)

for i in range(ns,n+1):
    a=n/i
    if a%1==0:
        s=i
        break
s=str(s)
print(len(s))

### FIXED CODE ###

from math import sqrt
n=int(input())
sn=int(sqrt(n)//1)

for i in range(sn,0,-1):
    if n%i==0:
        s=n//i
        break
    
print(len(str(s)))
### BUGGY CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


def bellman_ford(edges, N, start):
    dist = [float("inf") for _ in range(N)]
    dist[start] = 0
    # 辺の情報を見ることを1ループとすると
    # 1回のループで,最低でも1つの頂点について，スタートからの最短距離が求まる
    # つまり,スタートからの全ての頂点への距離は，
    # スタートを除いた頂点の数である,(N-1)回のループで求まる．
    for i in range(2 * N):
        for fro, to, cost in edges:
            if dist[to] > dist[fro] - cost:
                dist[to] = dist[fro] - cost
                # N回目に頂点の更新があると，負の経路がある
                if i == N - 1:
                    dist[to] = -float("inf")

    return dist


def main():
    N, M, P = map(int, input().split())
    edge = []
    for _ in range(M):
        A, B, C = map(int, input().split())
        edge.append((A - 1, B - 1, C - P))
    dist = bellman_ford(edge, N, 0)

    if dist[-1] == -float("inf"):
        print(-1)
    else:
        if dist[-1] > 0:
            print(0)
        else:
            print(-1 * dist[-1])


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


def bellman_ford(edges, N, start):
    dist = [float("inf") for _ in range(N)]
    dist[start] = 0
    # 辺の情報を見ることを1ループとすると
    # 1回のループで,最低でも1つの頂点について，スタートからの最短距離が求まる
    # つまり,スタートからの全ての頂点への距離は，
    # スタートを除いた頂点の数である,(N-1)回のループで求まる．
    for i in range(2 * N):
        for fro, to, cost in edges:
            if dist[to] > dist[fro] - cost:
                dist[to] = dist[fro] - cost
                # N回目に頂点の更新があると，負の経路がある
                if i == N - 1:
                    dist[to] = -float("inf")

    return dist


def main():
    N, M, P = map(int, input().split())
    edge = []
    for _ in range(M):
        A, B, C = map(int, input().split())
        edge.append((A - 1, B - 1, C - P))
    dist = bellman_ford(edge, N, 0)

    if dist[-1] == -float("inf"):
        print(-1)
    else:
        if dist[-1] > 0:
            print(0)
        else:
            print(-1 * dist[-1])


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

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

ml = len(format(A[-1], 'b'))
bA = [list(map(int, list(format(val, '061b')))) for val in A]
bAT = list(zip(*bA))
bAT = bAT[::-1]

cnt = 0
for i, bat in enu(bAT):
    o = sum(bat)
    cnt += (N-o)*o*(2**(i))
    cnt %= MOD

print(cnt)



### FIXED CODE ###

import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
A = np.array(input().split(), np.int)
#print(A)

cnt = 0
for i in range(61):
    B = (A>>i)&1
    z = np.count_nonzero(B)
    cnt += z*(N-z)*(2**(i))
    cnt %= MOD

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

from collections import deque
s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)

for t in ls:
    if t[0] == '1':
        ans.reverse()
    elif t[0] == '2':
        if t[1] == '1':
            ans.appendleft(t[2])
        elif t[1] == '2':
            ans.append(t[2])

print("".join(ans))

### FIXED CODE ###

from collections import deque

s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)
cnt = 0

for t in ls:
    if t[0] == '1':
        cnt += 1
    elif t[0] == '2':
        if cnt % 2 == 0:
            if t[1] == '1':
                ans.appendleft(t[2])
            elif t[1] == '2':
                ans.append(t[2])
        elif cnt % 2 == 1:
            if t[1] == '1':
                ans.append(t[2])
            elif t[1] == '2':
                ans.appendleft(t[2])

if cnt % 2 == 0:
    print("".join(ans))
elif cnt % 2 == 1:
    ans.reverse()
    print("".join(ans))
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read

N, K, *h = map(int, read().split())
# print(N, K, h)

def chmin(l, i, v):
  if l[i] > v:
    l[i] = v
    return True
  return False

def chmax(l, i, v):
  if l[i] < v:
    l[i] = v
    return True
  return False

# コスト無限大で初期化
INF = float("inf")
dp = [ INF ] * N
dp[0] = 0

for i in range(1, N):
  # i番目の梯子までの最小移動コストは、
  # 「i-1番目までの移動コスト」+「i-1番目からi番目への移動コスト」
  # もしくは、
  # 「i-2番目までの移動コスト」+「i-2番目からi番目への移動コスト」
  # ...
  # もしくは、
  # 「i-K番目までの移動コスト」+「i-K番目からi番目への移動コスト」
  # のうち、最も小さいものが、最小移動コストになる
  
  # jをi-Kからi-1まで変化させながら、最小の組み合わせを探す
  # ただし、jが負の値にならないよう注意
  for j in range(max(0, i-K), i):
    chmin(dp, i, dp[j] + abs(h[i] - h[j]))
  # print(dp)

print(dp[N-1])

### FIXED CODE ###

import numpy as np
import sys
N, K = map(int,input().split())
h = np.fromstring(input(), dtype=np.int64, sep=' ')

# コスト無限大で初期化
INF = 10**10
dp = np.array([INF]*N)
dp[0] = 0
for i in range(1, N):
  # i番目の梯子までの最小移動コストは、
  # 「i-1番目までの移動コスト」+「i-1番目からi番目への移動コスト」
  # もしくは、
  # 「i-2番目までの移動コスト」+「i-2番目からi番目への移動コスト」
  # ...
  # もしくは、
  # 「i-K番目までの移動コスト」+「i-K番目からi番目への移動コスト」
  # のうち、最も小さいものが、最小移動コストになる
  
  # jをi-Kからi-1まで変化させながら、最小の組み合わせを探す
  # ただし、jが負の値にならないよう注意
  j_min = max(0, i-K)
  dp[i] = np.min(dp[j_min: i] + np.abs(h[i] - h[j_min: i]))

print(dp[N-1])
### BUGGY CODE ###

import numpy as np

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

memo = np.array([0]*N)

for i in range(N):
    if S[i] == "E":
        memo[:i] -= 1
    else:
        memo[i+1:] -= 1

print(max(memo) * (-1))


### FIXED CODE ###

import numpy as np

N = int(input())
S = input()
left_W = 0
right_E = S.count("E")
ans = N

for i in range(N):
    if S[i] == "W":
        ans = min(ans, left_W+right_E)
        left_W += 1
    else:
        right_E -= 1
        ans = min(ans, left_W+right_E)

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

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

maxsum = -1
for i in range(0, N-K+1):
    tmp = sum([(j+1)/2 for j in P[i:i+K]])
    if tmp > maxsum:
        maxsum = tmp

print(maxsum)

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
Pe = [(i+1)/2 for i in P]

maxsum = -1
cur = sum(Pe[0:K])
maxsum = cur
for i in range(1, N-K+1):
    cur = cur - Pe[i-1] + Pe[i+K-1]
    if cur > maxsum:
        maxsum = cur

print(maxsum)