Harryxun/stf_run huggingface dataset:
N =int(input())
A_n =list(map(int,input().split()))
ans =1
i = 0

while ans <= 10**18 and i < N:
  ans *= A_n[i]
  i +=1
if ans > 10**18:
  elif 0 in A_n is False:
    print(-1)
  else:
    print(0)
else:
  print(ans)

### FIXED CODE ###

N =int(input())
A_n =list(map(int,input().split()))
ans =1
i = 0

while ans <= 10**18 and i < N:
  ans *= A_n[i]
  i +=1
if ans > 10**18:
  if 0 in A_n:
    print(0)
  else:
    print(-1)
else:
  print(ans)
[[0 for _ in range(9)] for _ in range(9)]

for i in range(1,n+1):
  x=int(str(i)[0])
  y=int(str(i)[-1])
  if x!=0 and y!=0:
    a[x-1][y-1]+=1
  
ans=0
  
for i in range(9):
  for j in range(9):
    if i!=j:
      
      ans+=a[i][j]*a[j][i]
      
    else:
      ans+=(a[i][i]*a[i][i])
      
print(ans)

### FIXED CODE ###

n=int(input())
a=[[0 for _ in range(9)] for _ in range(9)]

for i in range(1,n+1):
  x=int(str(i)[0])
  y=int(str(i)[-1])
  if x!=0 and y!=0:
    a[x-1][y-1]+=1
  
ans=0
  
for i in range(9):
  for j in range(9):
    if i!=j:
      
      ans+=a[i][j]*a[j][i]
      
    else:
      ans+=(a[i][i]*a[i][i])
      
print(ans)
from math import ceil
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())
bs = list(sorted(b,reverse=True))
ma = max(a)
ret = 0
while ret < n:
    if bs[0] => ma:
        h -= bs[0]
        bs.pop(0)
        ret += 1
        if h <= 0 : break
    else:
        break

if h > 0: ret += ceil(h/ma)
print(ret)


### FIXED CODE ###

from math import ceil
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())
bs = list(sorted(b,reverse=True))
ma = max(a)
ret = 0
while ret < n:
    if bs[0] > ma:
        h -= bs[0]
        bs.pop(0)
        ret += 1
        if h <= 0 : break
    else:
        break

if h > 0: ret += ceil(h/ma)
print(ret)
import math

R=input()
Z=R*2*math.pi
print(Z)

### FIXED CODE ###

import math

r=float(input())
z=r*float(2)*math.pi

print(z)
n=int(input())
a=[int(input()) for i in range(n)]
b=set(a)
for i in a:
  if i==b[-1]:
    print(b[-2])
  else:
    print(b[-1])

### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
b=list(set(a))
if len(b)==1:
  for i in range(n):
    print(b[0])
elif a.count(b[-1])>=2:
  for i in a:
    print(b[-1])
else:
  for i in a:
    if i==b[-1]:
      print(b[-2])
    else:
      print(b[-1])
N = input()
for i in N:
  if i == '7':
    print('yes')
    return 0
print('no')

    

### FIXED CODE ###

N = input()
flag = 0
for i in N:
    if i == '7':
        flag = 1
        print('Yes')
        break
if flag == 0:
    print('No')
x,y,z,k = map(int,input().split())
a = list(map(int,input().split())).sort()
b = list(map(int,input().split())).sort()
c = list(map(int,input().split())).sort()

ab_list = []
for a_i in range(x):
    for b_i in range(y):
        ab_list.append(a[a_i]+b[b_i])
ab_list.sort()
sum_list = []
for ab_i in range(k):
    for c_i in range(z):
        sum_list.append(ab_list[ab_i]+c[c_i])
sum_list.sort()
#sum_list = []
#for a_i in range(x):
#    for b_i in range(y):
#        for c_i in range(z):
#            sum_list.append(a[a_i]+b[b_i]+c[c_i])
#sum_list.sort()
for i in range(k):
    print(sum_list[i])

### FIXED CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
sum_list = []
for a_i in range(x):
    for b_i in range(y):
        if a_i*b_i > k:
            break
        for c_i in range(z):
            if a_i*b_i*c_i > k:
                break
            sum_list.append(a[a_i]+b[b_i]+c[c_i])
sum_list.sort(reverse=True)
for i in range(k):
    print(sum_list[i])
import sys
w = list(input())

for i in w.count(i):
  if i%2==1:
    print("No")
    sys.exit()
print("Yes")

### FIXED CODE ###

import sys
w = list(input())
for i in w:
  if w.count(i) %2 == 1:
    print("No")
    sys.exit()
print("Yes")
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
count = 0
for i in range(n):
  if a[i] >= b[i]:
    count += b[i]
  else:
    count += min(b[i], a[i]+a[i+1])
    a[i+1] = max(0, a[i+1]-(b[i]-a[i]))
print(count)


### FIXED CODE ###

A, B = map(int, input().split())

if (A+B)%2 == 0:
    result = str((A + B) // 2)
else:
    result =  'IMPOSSIBLE'

print(result)
N,K = (int(i) for i in input().split())
S = list(input())

cnt = 0
x = 1
tmp = S[0]
while cnt < K and x <= N-1:
    if S[x] != tmp:
        S[x] = tmp
        x += 1
        while S[x] != tmp and x <= N-1:
            S[x] = tmp
            x += 1
            if x > N-1:
                break
        cnt += 1

    else:
        x += 1

    if x > N-1:
        break

ans = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += 1

print(ans)


### FIXED CODE ###

N,K = (int(i) for i in input().split())
S = list(input())

cnt = 0
x = 1
tmp = S[0]
while cnt < K and x <= N-1:
    if S[x] != tmp:
        S[x] = tmp
        x += 1
        if x > N-1:
            break
        while S[x] != tmp and x <= N-1:
            S[x] = tmp
            x += 1
            if x > N-1:
                break
        cnt += 1
        if x > N-1:
            break

    else:
        x += 1


ans = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += 1

print(ans)
# coding: utf-8
from math import gcd

def getPrime(x):
    num_list=[i for i in range(2,x+1)]
    prime_list=[]
    D=[x+1 for i in range(x+1)]
    
    while num_list[0]<x**(1/2):
        p=num_list.pop(0)
        prime_list.append(p)
        for i in range(len(num_list)):
            if num_list[i]%p==0:
                if D[num_list[i]]>p:
                    D[num_list[i]]=p
        num_list = [e for e in num_list if e % p != 0]
    
    prime_list = prime_list + num_list
    for i in range(len(prime_list)):
        D[prime_list[i]] = prime_list[i]
    D[0]=1
    D[1]=1
    return D

N = int(input())
A = list(map(int,input().split()))
D = getPrime(max(A))

pc_flg = True

x = A[0]
for i in range(N):
    x = gcd(x,A[i])

prime_flg=[False for i in range(10**6+1)]

for i in range(N):
    num = A[i]
    primes = []
    while True:
        p = D[num]
        num = num//p
        primes.append(p)
        if num == 1:
            break
    for j in set(primes):
        if not(prime_flg[j]):
            prime_flg[j] = True
        else:
            pc_flg = False

if pc_flg:
    print("pairwise coprime")
elif x==1:
    print("setwise coprime")
else:
    print("not coprime")

### FIXED CODE ###

# coding: utf-8
from math import gcd

def getPrime(x):
    num_list=[i for i in range(2,x+1)]
    prime_list=[]
    D=[x+1 for i in range(x+1)]
    
    while num_list[0]<x**(1/2):
        p=num_list.pop(0)
        prime_list.append(p)
        for i in range(len(num_list)):
            if num_list[i]%p==0:
                if D[num_list[i]]>p:
                    D[num_list[i]]=p
        num_list = [e for e in num_list if e % p != 0]
    
    prime_list = prime_list + num_list
    for i in range(len(prime_list)):
        D[prime_list[i]] = prime_list[i]
    D[0]=1
    D[1]=1
    return D

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

if max(A) == 1:
    print("pairwise coprime")
    exit()

D = getPrime(max(A))

pc_flg = True

x = A[0]
for i in range(N):
    x = gcd(x,A[i])

prime_flg=[False for i in range(10**6+1)]

for i in range(N):
    num = A[i]
    primes = []
    while True:
        p = D[num]
        num = num//p
        primes.append(p)
        if num == 1:
            break
    for j in set(primes):
        if not(prime_flg[j]):
            prime_flg[j] = True
        else:
            if j != 1:
                pc_flg = False


if pc_flg:
    print("pairwise coprime")
elif x==1:
    print("setwise coprime")
else:
    print("not coprime")
l = [list(input()) for range(3)]
print(l[0][0]+l[1][1]+l[2][2])

### FIXED CODE ###

l = [list(input()) for i in range(3)]
print(l[0][0]+l[1][1]+l[2][2])
A,B,K = map(int,input().split())
l=[]
for i in range(1,max(A,B)):
    if (A%i + B%i) == 0:
        l.append(i)
    else:
        pass
if A == 1 & B == 1:
    print(1)
else:
    print(l[-K])

### FIXED CODE ###

A,B,K = map(int,input().split())
l=[]
for i in range(1,min(A,B)+1):
    if (A%i + B%i) == 0:
        l.append(i)
    else:
        pass
print(l[-K])
import collections
N=int(input())
L=list(map(int,input().split()))
E=[i for i in L[::2]]
O=[i for i in L[1::2]]
e = collections.Counter(E).most_common()
o = collections.Counter(O).most_common()
if e[0][0] != o[0][0]:
    print(N - e[0][1] - o[0][1])
else:
    if len(e) == 1 or len(o) == 1:
        print(N // 2)
    else:
        a = n - e[1][1] - o[0][1]
        b = n - e[0][1] - o[1][1]
        print(min(a, b))

### FIXED CODE ###

import collections
N=int(input())
L=list(map(int,input().split()))
E=[i for i in L[::2]]
O=[i for i in L[1::2]]
e = collections.Counter(E).most_common()
o = collections.Counter(O).most_common()
if e[0][0] != o[0][0]:
    print(N - e[0][1] - o[0][1])
else:
    if len(e) == 1 or len(o) == 1:
        print(N // 2)
    else:
        a = N - e[1][1] - o[0][1]
        b = N - e[0][1] - o[1][1]
        print(min(a, b))
s = list(input())
t = list(input())
a = 0

s.sort()
t.sort()
t = t[::-1]

if len(s) < len(t):
    for i in range(len(s)):
        if s[i] < t[i]:
            print("Yes")
            break
        elif s[i] == t[i]:
            a += 1
            continue
        else:
            print("No")
            break
    if a == len(s):
        print("Yes")

else:
    for i in range(len(s)):
        if s[i] < t[i]:
            print("Yes")
            break
        elif s[i] == t[i]:
            a += 1
            continue
        else:
            print("No")
            break
    if a == len(s):
        print("No")


### FIXED CODE ###

s = list(input())
t = list(input())
a = 0

s.sort()
t.sort()
t = t[::-1]

if len(s) < len(t):
    for i in range(len(s)):
        if s[i] < t[i]:
            print("Yes")
            break
        elif s[i] == t[i]:
            a += 1
            continue
        else:
            print("No")
            break
    if a == len(s):
        print("Yes")

else:
    for i in range(len(t)):
        if s[i] < t[i]:
            print("Yes")
            break
        elif s[i] == t[i]:
            a += 1
            continue
        else:
            print("No")
            break
    if a == len(t):
        print("No")
L,R=map(int,input().split())
l=L//2019
ll=L%2019
r=R//2019
if l<r or ll==0:
  print(0)
else:
  print(ll*(ll+1))


### FIXED CODE ###

N,A,B=map(int,input().split())
print(min(N*A,B))
import heapq
n, m = map(int, input().split())

a = list(map(lambda x: -int(x), input().split()))
heapq.heapqify(a)

for i in range(m):
    heapq.heappush(a, int(heapq.heappop(a)/2))

print(-sum(a))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())

a = list(map(lambda x: -int(x), input().split()))
heapq.heapify(a)

for i in range(m):
    heapq.heappush(a, int(heapq.heappop(a)/2))

print(-sum(a))
n,m = map(int,input().split())
x = sorted(list(map(int,input().split())))
gap = [x[i+1]-x[i] for i in range(m-1)]
def dp(n):
    if n == 1:
        return max(x) - min(x)
    else:
        if len(gap) > 0:
            maxGap = max(gap)
            gap.remove(maxGap)
        else:
            maxGap = 0
        return dp(n-1) - maxGap
if n < m:
    print(dp(n))
else:
    print(0)

### FIXED CODE ###

t,x = map(int,input().split())
print(t/x)
N = int(input())
P = list(map(int, input().split()))

cnt = 0
for i in range(1, N+1):
    if P[i] != i:
        cnt += 1
        
print('YES' if cnt == 2 else 'NO')

### FIXED CODE ###

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

cnt = 0
for i in range(N):
    if P[i] != i + 1:
        cnt += 1

print('YES' if cnt == 0 or cnt == 2 else 'NO')
N,M= int(input())
A = list(map(int, input().split()))
sum=0
for i in range(M):
    sum+=A[i]
if N-sum<0:
    print(-1)
else:
    print(N-sum)


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
sum=0
for i in range(M):
    sum+=A[i]
if N-sum<0:
    print(-1)
else:
    print(N-sum)
### D - Triangles ###

N = int(input())
L = list(map(int, input().split()))

# N = 7
# L = [218, 786, 704, 233, 645, 728, 389]

L.sort()

from itertools import combinations

cb = combinations(L, 2)
cb = list(map(sorted, cb))

rslt = 0

for el_cb in cb:
    for v in L:
        if el_cb[1] - el_cb[0] <= v and el_cb[0] >= v:
            rslt = rslt + 1

# if のところに2分探索入れる

print(rslt)

### FIXED CODE ###

### A - Curtain ###
A, B = map(int, input().split())
print(A-B*2 if A-B*2 > 0 else 0)
n = int(input())
x = input().split()
x_int = [int(i) for i in x]
y = list(range(n))

for i in x_int:
     y[-i] = i
print(y)

### FIXED CODE ###

n = int(input())
x = input().split()
x_int = [int(i) for i in x]
y = list(range(n))

for i in range(n):
     y[-i-1] = x_int[i]
y_str = [str(i) for i in y]
print(' '.join(y_str))
n,m = map(int,input().split())
L = [0]*n
AC = 0
WA = 0
tmp = [0]*n
for i in range(m):
	x,y = input().split()
	x = int(x)
	if L[x-1] == 0:
		if y == "WA":
			tmp[x-1] += 1
		else:
			AC += 1
			WA += tmp[x-1]
			L[x-1]=1
print(A,W)


### FIXED CODE ###

n,m = map(int,input().split())
L = [0]*n
AC = 0
WA = 0
tmp = [0]*n
for i in range(m):
	x,y = input().split()
	x = int(x)
	if L[x-1] == 0:
		if y == "WA":
			tmp[x-1] += 1
		else:
			AC += 1
			WA += tmp[x-1]
			L[x-1]=1
print(AC,WA)
n,a,b=map(int, input().split())

al = [1]*a
bl = [0]*b
cl =[]
d = a + b
e = n//d + 2

for i in range(e):
    cl = cl + al + bl

print(sum(cl[:n]))

### FIXED CODE ###

n,a,b=map(int, input().split())

d = a+b
c = n%d
e = n//d

if c <= a:
    print(e*a+c)
if c > a:
    print((e+1)*a)
input=input()
  
  weather={"Sunny":0,"Cloudy":1,"Rainy":2}
  output={0:"Sunny",1:"Cloudy",2:"Rainy"}
  s=weather[input]+1
  if s>=3:
           s=s-3
           print(output[s])
　else:
		　　print(output[s])

### FIXED CODE ###

input=input()
weather={"Sunny":0,"Cloudy":1,"Rainy":2}
output={0:"Sunny",1:"Cloudy",2:"Rainy"}
s=weather[input]+1
if s>=3:
	s=s-3
	print(output[s])
else:
	print(output[s])
a, b = map(imt, input().split())
if a * b % 2 == 0:
  print("Even")
else:
  print("Odd")


### FIXED CODE ###

a, b = map(int, input().split())
if a * b % 2 == 0:
  print("Even")
else:
  print("Odd")
import sys
input = sys.stdin.readline
N = int(input())
L = list(map(int, input().split()))
if N == 1:
  print(0)
else:
  x = 0
  for i in range(0,len(L)-1):
    if L[i] > L[i + 1]:
      x = x + (L[i] - L[i + 1])
      L[i + 1] = L[i + 1] + (L[i] - L[i + 1])
  print(x)
    



### FIXED CODE ###

N, X, T = map(int, input().split())
if N % X > 0:
  a = (N // X + 1) * T
else:
  a = (N // X) * T

print(a)
a, b, c = map(int, input().split())
print(a+b+c)

### FIXED CODE ###

a = list(input())
for i in range(3):
    a[i] = int(a[i])
print(a[0]+a[1]+a[2])
from sys import stdin, stdout
def main():
    line = stdin.readLine()
    parts = line.split()
    a = int(parts[1])
    b = int(parts[2])
    stdout.write((a-1)*(b-1))
main()

### FIXED CODE ###

from sys import stdin,stdout

def main():
    line=stdin.readline()
    parts=line.split()
    a=int(parts[0])
    b=int(parts[1])

    stdout.write(str((a-1)*(b-1)))
main()
n=int(input())
d = list(map(int,input().split()))
li=[]
for i in n:
  for j in n:
    a=d[i]*d[j]
    li.append(a)
b=sum(li)
print(b/2)

### FIXED CODE ###

import math
n = int(input())
d = list(map(int,input().split()))
li=[]
li2=[]
for i in range(n):
  for j in range(n):
    a = d[i]*d[j]
    li.append(a)
b = sum(li)
for k in range(n):
  c=d[k]**2
  li2.append(c)
d=sum(li2)
b -= d
print(math.floor(b/2))
n,k = map(int,input().split())
if n%k ==0:
  print(0)
elif n < k:
  print((1)
else:
  print((n//k) - 1)

### FIXED CODE ###

n,k = map(int,input().split())
if n%k ==0:
  print(0)
else:
  print(1)
N,M=map(int,input().split())
edge=[set([]) for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].add(b-1)
    edge[b-1].add(a-1)

cedge=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if j not in edge[i] and j!=i:
            cedge[i].append(j)

ans=[]
def is_bipartgraph():
    color=[0]*N
    used=[False]*N
    for i in range(N):
        if not used[i]:
            stack=[(i,1)]
            black=0
            white=0
            while stack:
                v,c=stack.pop()
                used[v]=True
                color[v]=c
                black+=(c==1)
                white+=(c==-1)
                for nv in cedge[v]:
                    if color[nv]==color[v]:
                        return False
                    elif color[nv]==0:
                        stack.append((nv,-c))
            ans.append([black,white])
    return True

if is_bipartgraph():
    dp=[[False for i in range(0,N+1)] for j in range(len(ans))]
    a,b=ans[0]
    dp[0][a],dp[0][b]=True,True
    for i in range(1,len(ans)):
        a,b=ans[i]
        for j in range(0,N+1):
            test=False
            if j>=a:
                test=test|dp[i-1][j-a]
            if j>=b:
                test=test|dp[i-1][j-b]
            dp[i][j]=test
    ans=0
    for i in range(0,N+1):
        if dp[-1][i] and abs(ans-N/2)>abs(i-N/2):
            ans=i
    ans2=N-ans
    print(ans*(ans-1)//2+ans2*(ans2-1)//2)
else:
    print(-1)

### FIXED CODE ###

N,M=map(int,input().split())
edge=[set([]) for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].add(b-1)
    edge[b-1].add(a-1)

cedge=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if j not in edge[i] and j!=i:
            cedge[i].append(j)

ans=[]
def is_bipartgraph():
    color=[0]*N
    used=[False]*N
    for i in range(N):
        if not used[i]:
            stack=[(i,1)]
            black=0
            white=0
            while stack:
                v,c=stack.pop()
                color[v]=c
                black+=(not used[v])*(c==1)
                white+=(not used[v])*(c==-1)
                used[v]=True
                for nv in cedge[v]:
                    if color[nv]==color[v]:
                        return False
                    elif color[nv]==0:
                        stack.append((nv,-c))
            ans.append([black,white])
    return True

if is_bipartgraph():
    dp=[[False for i in range(0,N+1)] for j in range(len(ans))]
    a,b=ans[0]
    dp[0][a],dp[0][b]=True,True
    for i in range(1,len(ans)):
        a,b=ans[i]
        for j in range(0,N+1):
            test=False
            if j>=a:
                test=test|dp[i-1][j-a]
            if j>=b:
                test=test|dp[i-1][j-b]
            dp[i][j]=test
    ans=0
    for i in range(0,N+1):
        if dp[-1][i] and abs(ans-N/2)>abs(i-N/2):
            ans=i
    ans2=N-ans
    print(ans*(ans-1)//2+ans2*(ans2-1)//2)
else:
    print(-1)
import numpy as np

n = input()
n = int(n)
a = input()
a = a.split()
a = [int(x) for x in a]

q = input()
q = int(q)
ms = input()
ms = ms.split()
ms = [int(x) for x in ms]

np.sort(a)
a = np.array(a)
for m in ms:
    if m > a[-1]:
        print("no")
    elif a.any()==m:
        print("yes")
    else:
        a_new = a[a < m]
        print(a_new)
        select = []
        length = len(a_new)
        selects = np.zeros(2**length, length)

### FIXED CODE ###

import re
from itertools import product
import itertools

q1 = int(input())
q2 = input()
q3 = int(input())
q4 = input()

S = re.split(r' ',q2)
S=list(map(int, S))

T = re.split(r' ',q4)
T=list(map(int, T))

S_len = len(S)
T_len = len(T)

array = []
for j in range(q1+1):
    x = list(itertools.combinations(S, j))
    for k in range(len(x)):
        y = sum(x[k])
        array.append(y)

for i in range(T_len):
    if(T[i] in array):
        print("yes")
    else:
        print("no")
sec = int(input())

min = sec / 60
hour = min / 60

min -= hour * 60
sec %= 60

print(hour+":"+min+":"+sec)

### FIXED CODE ###

# coding: utf-8

sec  = int(input())

hun  = int(sec/60)
hour = int(hun/60)

hun -= hour * 60
sec %= 60

print(hour,end=":")
print(hun,end=":")
print(sec)
import math
print(math.ceil((B-1)/A))

### FIXED CODE ###

A,B=input().split()
import math
print(math.ceil((int(B)-1)/(int(A)-1)))
N = int(input())
#s = input()
#S = []
#for i in range(N):
S = input().split(" ")
for i in range(N):
    S[i] = int(S[i])
for i in range(N):
    S[i+1] = (int(S[i])+int(S[i+1])) / 2
print(S[N-1])




### FIXED CODE ###


N = int(input())
#s = input()
#S = []
#for i in range(N):
S = input().split(" ")
for i in range(N):
    S[i] = float(S[i])
S.sort()
for i in range(N-1):
    S[i+1] = (float(S[i])+float(S[i+1])) / 2.000000
print(S[N-1])
resolve()
def resolve():
    S = str(input())
    Q = int(input())

    rev_flag = 1
    head_str = ""
    tail_str = ""
    for _ in range(Q):
        query = input() # contains spaces
        if query[0] == "1":
            rev_flag *= -1
        else:
            h_or_t_flag = 1 if query[2] == "1" else -1
            h_or_t_flag *= rev_flag

            if h_or_t_flag == 1:
                head_str += query[4]
            else:
                tail_str += query[4]

    ans = head_str[::-1] + S + tail_str
    print(ans if rev_flag == 1 else ans[::-1])


### FIXED CODE ###

# -*- coding: utf-8 -*-
S = str(input())
Q = int(input())

rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        rev_flag *= -1
    else:
        h_or_t_flag = 1 if query[1] == "1" else -1
        h_or_t_flag *= rev_flag
        
        if h_or_t_flag == 1:
            head_str = query[2] + head_str
        else:
            tail_str += query[2]

ans = head_str + S + tail_str
print(ans if rev_flag == 1 else ans[::-1])
a, b = map(int, input().split())
print(max(0, a - 2 * b)

### FIXED CODE ###

a, b = map(int, input().split())
print(max(0, a - 2 * b))
N, M, X=map(int, input().split())
list=[0]*(N+1)
m=list(int() for i in input().split())
for i in m:
  list[i]=1
min(sum(list.loc[0:X]), sum(list.loc(X+1:N+1)))

### FIXED CODE ###

N, M, X=map(int, input().split())
sum=sum(int(i)<X for i in input().split())
print(min(sum, M-sum))
# 未完成
import numpy as np
N = int(input())
x = np.zeros(N)
y = np.zeros(N)
kouholist = []

if N == 1:
    print(1)
else:
    for i in range(N):
        x[i], y[i] = map(int, input().split())
    for m in range(N):
        for p in range(N):
            if m == p:
                continue
            diff_x = x[m] - x[p]
            diff_y = y[m] - y[p]
            if (diff_x, diff_y) not in kouholist:
                kouholist.append((diff_x, diff_y))

    for list_i in kouholist:
        ans_kari = 0
        for r in range(N):
            for q in range(N):
                if r == q:
                    continue
                if x[q] - x[r] == list_i[0] and y[q] - y[r] == list_i[1]:
                    ans_kari += 1
        ans.append(ans_kari)

    print("{}".format(N-max(ans)))


### FIXED CODE ###

# 未完成

import sys
N = int(input())
x = [0]*N
y = [0]*N
kouholist = []
ans = N
if N == 1:
    print(1)
    sys.exit()

for i in range(N):
    x[i], y[i] = map(int, input().split())
for m in range(N):
    for p in range(N):
        if m == p:
            continue
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = N
        for r in range(N):
            for q in range(N):
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans_kari -= 1
        if ans_kari < ans:
            ans = ans_kari

print("{}".format(ans))
n = int(input())
a = list(map(int, input().split()))

fromLeft = [-1]*n

for i in range(n):
    fromLeft[i] = a[i] - i

ans = 0

ldList = [0]*(3*10**5)

for i in reversed(range(n)):
    if fromLeft[i] < 3*10**5-10:
        ldList[fromLeft[i]] += 1
    ans += ldList[-1*a[i]-i]

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

fromLeft = [-1]*n

for i in range(n):
    fromLeft[i] = a[i] - i

ans = 0

ldList = [0]*(n*2+5)

for i in reversed(range(n)):
    if 0 <= fromLeft[i]+n+1 and fromLeft[i]+n+1 < n*2+5:
        ldList[fromLeft[i]+n+1] += 1
    if 0 <= -1*a[i]-i+n+1 and -1*a[i]-i+n+1 < n*2+5:
        ans += ldList[-1*a[i]-i+n+1]

print(ans)