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

s = input()
q = int(input())
Q = [list(map(str, input().split())) for i in range(q)]

reverse_num = 0
for i in range(q):
  if int(Q[i][0]) == 1:
    reverse_num += 1
  else:
    if int(Q[i][1]) == 1:
      if reverse_num % 2 == 0:
      	s = Q[i][2] + s
      else:
        s = s + Q[i][2]
    else:
      if reverse_num % 2 == 0:
      	s = s + Q[i][2]
      else:
        s = Q[i][2] + s
        
if reverse_num % 2 == 0:
  print(s)
else:
  print(s[::-1])


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())
Q = [list(map(str, input().split())) for i in range(q)]

ans = deque(s)

reverse_num = 0
for i in range(q):
  if int(Q[i][0]) == 1:
    reverse_num += 1
  else:
    if int(Q[i][1]) == 1:
      if reverse_num % 2 == 0:
        ans.appendleft(Q[i][2])
      else:
        ans.append(Q[i][2])
    else:
      if reverse_num % 2 != 0:
        ans.appendleft(Q[i][2])
      else:
        ans.append(Q[i][2])

res = ''
if reverse_num % 2 == 0: 
  for i in range(len(ans)):
    res += ans.popleft()
  print(res)
else:
  for i in range(len(ans)):
    res += ans.pop()
  print(res)
### BUGGY CODE ###

import bisect
from collections import deque
class UnionFind(): #Union-Find木の実装
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
N = int(input())
same = set()
xseq = []
yseq = []
edge = []
uf = UnionFind(N)
ans = 0

x,y = (int(x) for x in input().split())
same.add((x,y))
xseq.append((x,0))
yseq.append((y,0))
for i in range(1,N):
    x,y = (int(x) for x in input().split())
    if (x,y) not in same:
        same.add((x,y))
        xb = bisect.bisect_left(xseq,(x,i))
        xseq.insert(xb,(x,i))
        if xb == 0:
            edge.append((xseq[1][0]-x,(xseq[1][1],i)))
        elif xb == len(xseq)-1:
            edge.append((x-xseq[-2][0],(xseq[-2][1],i)))
        else:
            edge.append((xseq[xb+1][0]-x,(xseq[xb+1][1],i)))
            edge.append((x-xseq[xb-1][0],(xseq[xb-1][1],i)))
        yb = bisect.bisect_left(yseq,(y,i))
        yseq.insert(yb,(y,i))
        if yb == 0:
            edge.append((yseq[1][0]-y,(yseq[1][1],i)))
        elif yb == len(yseq)-1:
            edge.append((y-yseq[-2][0],(yseq[-2][1],i)))
        else:
            edge.append((yseq[yb+1][0]-y,(yseq[yb+1][1],i)))
            edge.append((y-yseq[yb-1][0],(yseq[yb-1][1],i)))
edge.sort()
d = deque([e[0] for e in edge])
for i in range(len(d)):
    temp = d.popleft()
    a,b = edge[i][1][0],edge[i][1][1]
    if uf.find(a) != uf.find(b):
        uf.union(a,b)
        ans += temp
print(ans)

### FIXED CODE ###

from collections import deque
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
N = int(input())
xseq = []
yseq = []
uf = UnionFind(N)
ans = 0

for i in range(N):
    x,y = (int(x) for x in input().split())
    xseq.append((x,i))
    yseq.append((y,i))
xseq.sort()
yseq.sort()
xdiff = [(xseq[i][0]-xseq[i-1][0],(xseq[i][1],xseq[i-1][1])) for i in range(1,N)]
ydiff = [(yseq[i][0]-yseq[i-1][0],(yseq[i][1],yseq[i-1][1])) for i in range(1,N)]
diff = xdiff + ydiff
diff.sort()
d = deque(diff)

for i in range(len(d)):
    temp = d.popleft()
    if uf.find(temp[1][0]) != uf.find(temp[1][1]):
        uf.union(temp[1][0],temp[1][1])
        ans += temp[0]
print(ans)
### BUGGY CODE ###

def getinputdata():

    array_result = []

    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if (data != ""):

                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

power = 1

for i in range(1, 1 + n):
    
    power *= i
    
print(power % (10 ** 9 + 7))
    
#    print(i, power, power % (10 ** 9 + 7), power < power % (10 ** 9 + 7))
    
#    print(power % (10 ** 9 + 7))





### FIXED CODE ###

import math
def getinputdata():

    array_result = []

    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if (data != ""):

                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

power = 1

print(math.factorial(n) % (10 ** 9 + 7))
### BUGGY CODE ###

K = int(input())
num = 0
K_s = len(str(K))
flg = 0

for i in range(K_s, 10**6):
    if K %2 == 0:
        print(-1)
        flg = 1
        break
    num = int(str(1)*i)
    if 7*num % K ==0:
        print(i)
        flg = 1
        break

if flg == 0:
    print(-1)




### FIXED CODE ###

cnt = 1
mod = 7
k = int(input())
for i in range (k):
    if mod % k == 0:
        break
    cnt +=1
    mod = (mod * 10 + 7) % k
if mod % k == 0:
    print(cnt)
else:
    print(-1)
### BUGGY CODE ###

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

lis = []
for _ in range(Q):
    lis.append(int(input()))

point = [K] * N

for i in range(Q):
    num = lis[i]
    point[num-1] += 1

    for j in range(N):
        point[j] -= 1



for i in range(N):
    if point[i] > 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

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

lis = []
for _ in range(Q):
    lis.append(int(input()))

point = [K] * N

for i in range(Q):
    num = lis[i]
    point[num-1] += 1

for j in range(N):
    point[j] -= Q



for i in range(N):
    if point[i] > 0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

from collections import deque
n = int(input())
seque = deque([i for i in range(1,n+1)])
a = seque.popleft()
seque.append(a)
# 1 2 3 4 5 6 7 8 9 10 11 12 13
# 2 3 4 5 6 7 8 9 10 11 12 13 1 
# print(seque)
ans = 0
for i in range(1,n+1):
    ans += i%seque[i-1]
print(ans)

### FIXED CODE ###

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

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+=a[i]*a[j]
        ans%=10**9+7
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
s=sum(a)
for i in range(n-1,-1,-1):
    s-=a[i]
    ans+=a[i]*(s)
    ans%=10**9+7
print(ans)
### BUGGY CODE ###

# ABC149 B - Greedy Takahashi
a,b,k = map(int,input().split())

for i in range(k):
    if a>0:
        a -=1
    else:
        if b>0:
            b -=1
print(str(a)+' '+str(b))

### FIXED CODE ###

# ABC149 B - Greedy Takahashi
a,b,k = map(int,input().split())

if a-k>=0:
    a -=k
else:
    k -= a
    a=0
    if b-k>=0:
        b -=k
    else:
        b=0
print(str(a)+' '+str(b))
### BUGGY CODE ###

import math
import bisect

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

alist.sort()
#print(alist)

answer=0
while(True):
  if len(alist) <= 1:
    break
  
  p1=alist.pop()
  p2=2**math.ceil(math.log(p1+1,2))-p1
  
  index1 = bisect.bisect_left(alist,p2)  
  if index1 != bisect.bisect_right(alist,p2):
    alist.pop(index1)
    answer+=1
    
print(answer)

### FIXED CODE ###

import bisect
N=int(input())
alist=list(map(int,input().split()))
alist.sort(reverse=True)

blist=[]
for a in alist:
  a2=a
  digit_a2=0
  while(a2>0):
    a2>>=1
    digit_a2+=1
  b=2**(digit_a2)-a
  blist.append(b)
#print(alist)
#print(blist)

dic_a={}
for a in alist:
  if a in dic_a:
    dic_a[a]+=1
  else:
    dic_a[a]=1

answer=0
for i in range(N):
  a=alist[i]
  b=blist[i]
  if a==b:
    if dic_a[a]>1:
      dic_a[a]-=2
      answer+=1
      #print(a,a)
  else:
    if dic_a[a]>0 and b in dic_a and dic_a[b]>0:
      dic_a[a]-=1
      dic_a[b]-=1
      answer+=1
      #print(a,b)
    
print(answer)
### BUGGY CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


#隣接リスト 1-order
def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def cmb_mod(n, r, m):
    r = min(r, n-r)
    res = 1
    for i in range(0, r):
        res *= divide_mod(n-i, r-i, m)
        res %= m
    return res


def divide_mod(x, y, m):
    return (x%m) * pow_mod(y, m-2, m) % m


def pow_mod(base, exp, m):
    if exp == 1:
        return base % m
    elif exp % 2:
        return pow_mod(base, exp-1, m) * base % m
    else:
        return pow_mod(base, exp//2, m) ** 2 % m


def main():
    n, a, b = NMI()
    all = pow_mod(2, n, MOD) - 1
    ans = all - cmb_mod(n, a, MOD) - cmb_mod(n, b, MOD)
    ans %= MOD
    print(ans)



if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def combinations_mod(n, r, mod=1000000007):
    """Returns nCr in mod."""
    r = min(r, n - r)
    combs = 1
    for i, j in zip(range(n - r + 1, n + 1), range(1, r + 1)):
        combs *= (i % mod) * pow(j, mod - 2, mod)
        combs %= mod
    return combs


def main():
    n, a, b = NMI()
    all = pow(2, n, MOD) - 1
    ans = all - combinations_mod(n, a) - combinations_mod(n, b)
    ans %= MOD
    print(ans)



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

l = []
r = []
n,q = input().split()
N = int(n)
Q = int(q)
S = input()
for i in range(Q):
    L,R = input().split()
    l.append(int(L)-1)
    r.append(int(R)-1)
for j in range(Q):
    count = 0
    for i in range(l[j],r[j]):
        if(S[i]=="A")&(S[i+1]=="C"):
            count = count + 1
    print(count)

### FIXED CODE ###

n,q = (int(x) for x in input().split())
s = input()
l = []
r = []
for i in range(q):
    temp1,temp2 = (int(x) for x in input().split())
    l.append(temp1-1)
    r.append(temp2-1)

bb = []
bb.append(0)
# print(l)
for i in range(1,n):
    if s[i-1] == 'A' and s[i] == 'C':
        bb.append(bb[i-1] + 1)
    else:
        bb.append(bb[i-1])

for i in range(q):
    print(bb[r[i]] - bb[l[i]])
### BUGGY CODE ###

h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
q=int(input())
lr=[list(map(int,input().split())) for i in range(q)]
data=[[0]*(h*w//d+1) for i in range(d)]
for i in range(h):
    for j in range(w):
        b=a[i][j]%d
        c=a[i][j]//d
        data[b][c]=[i, j]
for u in lr:
    l,r=u
    b=l%d
    c=l//d
    e=r//d
    ans=0
    for i in range(c,e):
        x,y=data[b][i]
        X,Y=data[b][i+1]
        ans+=abs(x-X)+abs(y-Y)
    print(ans)

### FIXED CODE ###

h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
q=int(input())
lr=[list(map(int,input().split())) for i in range(q)]
data=[[[0,0]]*(h*w//d+1) for i in range(d)]
for i in range(h):
    for j in range(w):
        b=a[i][j]%d
        c=a[i][j]//d
        data[b][c]=[i, j]
lst=[[0]*(h*w//d+1) for i in range(d)]
for i in range(d):
    for j in range(1,h*w//d+1):
        x,y=data[i][j]
        X,Y=data[i][j-1]
        lst[i][j]=lst[i][j-1]+abs(x-X)+abs(y-Y)
for u in lr:
    l,r=u
    b=l%d
    c=l//d
    e=r//d
    ans=lst[b][e]-lst[b][c]
    print(ans)
### BUGGY CODE ###

import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A = sorted(enumerate(A), key = lambda x: x[1])[::-1]

    dp = np.zeros((N+1,N+1), dtype='int64')
    #dp = [[0]*(N+1-i) for i in range(N+1)]

    #m = 0
    for i in range(1,len(A)+1):
        index,a = A[i-1]
        for j in range(i+1):
            if (i-j,j) == (0,0):
                dp[i-j][j] = 0
            elif i-j == 0:
                dp[i-j][j] = dp[i-j][j-1] + (N-j-index)*a
            elif j == 0:
                dp[i-j][j] = dp[i-j-1][j] + (abs(index-(i-j-1)))*a
            else:
                dp[i-j][j] = max(dp[i-j][j-1] + (N-j-index)*a, dp[i-j-1][j] + (abs(index-(i-j-1)))*a)
            #if i == len(A):
            #    m = max(m, dp[i-j][j])

    #print(dp)
    print(np.max(dp))
    #print(m)

main()


### FIXED CODE ###

#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A = sorted(enumerate(A), key = lambda x: x[1])[::-1]

    #dp = np.zeros((N+1,N+1), dtype='int64')
    dp = [[0]*(N+1-i) for i in range(N+1)]

    m = 0
    for i in range(1,len(A)+1):
        index,a = A[i-1]
        for j in range(i+1):
            if (i-j,j) == (0,0):
                dp[i-j][j] = 0
            elif i-j == 0:
                dp[i-j][j] = dp[i-j][j-1] + (N-j-index)*a
            elif j == 0:
                dp[i-j][j] = dp[i-j-1][j] + (abs(index-(i-j-1)))*a
            else:
                dp[i-j][j] = max(dp[i-j][j-1] + (N-j-index)*a, dp[i-j-1][j] + (abs(index-(i-j-1)))*a)
            if i == len(A):
                m = max(m, dp[i-j][j])

    #print(dp)
    #print(np.max(dp))
    print(m)

main()
### BUGGY CODE ###

from collections import defaultdict

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

MOD = 10 ** 9 + 7

# 素因数分解
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
    if temp % i == 0:
      cnt = 0
      while temp % i == 0:
        cnt += 1
        temp //= i
      arr.append([i, cnt])
  if temp != 1:
    arr.append([temp, 1])
  if arr == []:
    arr.append([n, 1])
  return arr

counter = defaultdict(int)
p_list = []
for a in A:
  for p, r in factorization(a):
    if counter[p] == 0:
      p_list.append(p)
    counter[p] = max(counter[p], r)
lcm = 1
  
answer = 0
for a in A:
  counter_a = defaultdict(int)
  for p, r in factorization(a):
    counter_a[p] += r
  tmp = 1
  for p in p_list:
     tmp = (tmp * p ** (counter[p] - counter_a[p])) % MOD
  answer = (answer + tmp) % MOD

print(answer)

### FIXED CODE ###

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

MOD = 10 ** 9 + 7

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
#print(tmp)

answer = 0
for a in A:
  answer += tmp // a
print(answer % MOD)
### BUGGY CODE ###

def main():
    N,K = map(int,input().split())
    A = list(map(int, input().split()))

    AA = []
    num = []
    for A in A:
        if (A in AA)==False:
            AA.append(A)
            num.append(1)
        else:
            num[AA.index(A)] += 1

    B = list(zip(num, AA))
    B.sort()
    B = B[::-1]
    count = 0
    if len(B)<=K:
        return 0
    else:
        for i in range(K,len(B)):
            count += B[i][0]
        return count


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

### FIXED CODE ###

def main():
    N,K = map(int,input().split())
    A = list(map(int, input().split()))

    num = [0 for _ in range(200000)]
    s = 0
    for A in A:
        num[A-1] += 1

    count = 0
    num.sort()
    for i in range(200000-K):
        count += num[i]
    return count

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

import sys

n,k = list(map(int, input().split(" ")))
l = list(map(int, input().split(" ")))
l = [999999]*k + l
dp= [0]*(n+k)

for i in range( k + 1, n+k):
	dp[i] = min([ dp[i - j] + abs(l[i] - l[i - j]) for j in range(1, k + 1) ])

print(dp[n + k - 1])

### FIXED CODE ###

import sys

n,k = list(map(int, input().split(" ")))
l = list(map(int, input().split(" ")))
l = [999999]*k + l
dp= [0]*(n+k)

for i in range( k + 1, n+k):
	dp[i] = min([ dp[i - j] + abs(l[i] - l[i - j]) for j in range(1, k + 1) ])

print(dp[n + k - 1])
### BUGGY CODE ###

from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    S = list(_ for _ in input())
    S.reverse()

    for i in range(4):
        T[i].reverse()
    while len(S)>0:        
        if(S[0:len(T[0])] == T[0]):
            S = S[len(T[0]):len(S)]
        elif(S[0:len(T[1])] == T[1]):
            S = S[len(T[1]):len(S)]
        elif(S[0:len(T[2])] == T[2]):
            S = S[len(T[2]):len(S)]
        elif(S[0:len(T[3])] == T[3]):
            S = S[len(T[3]):len(S)]
        else:
            break
        
    if(len(S)>0):
        print('NO')
    else:
        print('YES')

    
if __name__ == '__main__':
    main()


### FIXED CODE ###

from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    S = list(_ for _ in input())
    S.reverse()

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(S[0:len(T[0])] == T[0]):
            for i in range(len(T[0])):
                S.pop(0)
        elif(S[0:len(T[1])] == T[1]):
            for i in range(len(T[1])):
                S.pop(0)
        elif(S[0:len(T[2])] == T[2]):
            for i in range(len(T[2])):
                S.pop(0)
        elif(S[0:len(T[3])] == T[3]):
            for i in range(len(T[3])):
                S.pop(0)
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

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

n = int(input())
line = list(map(int, input().split()))
ans = 0
mod = 10**9 + 7
for i in range(n):
  for j in range(i+1,n):
    ans += line[i]*line[j]
    if ans > mod:
      ans = ans % mod
print(ans)

### FIXED CODE ###

n = int(input())
line = list(map(int, input().split()))
ans = 0
x = sum(line)
mod = 10**9 + 7
for i in range(n):
  x -= line[i]
  ans += line[i] * x
  if ans > mod:
    ans = ans % mod
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)

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

    
def findBrick(n,a,counter=0):
  if len(a) == 0:
    return counter
  elif a[0] == counter + 1:
    return findBrick(n,a[1:],counter+1)
  else:
    return findBrick(n,a[1:],counter)

c = findBrick(N,a)
  
ans = -1 if c == 0 else N - c
print(ans)

### FIXED CODE ###

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

counter = 0
for i in range(N):
  if a[i] == counter+1:
    counter += 1

ans = -1 if counter == 0 else N - counter
print(ans)
### BUGGY CODE ###

n = int(input())
items = []

for i in range(n):
    item = input()
    if item not in items:
        items.append(item)

print(len(items))

### FIXED CODE ###

n = int(input())
items = {}

for i in range(n):
    item = input()
    items[item] = True

print(len(items))
### BUGGY CODE ###

INF = 1000000000 + 7
N = int(input())
ans = 1
for i in range(1, N + 1):
    ans *= i

print(ans % INF)


### FIXED CODE ###

INF = 1000000000 + 7
N = int(input())
ans = 1
for i in range(1, N + 1):
    ans = ans * i % INF

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

import sys
import numpy as np

N,K = map(int, sys.stdin.readline().split())

A = list(map(int, sys.stdin.readline().split()))

dp = np.zeros(K+1)

for k in range(0,K+1):
    for i in A:
        if dp[k] == 0 and k-i >= 0 and dp[k-i] == 0:
            dp[k] = 1

            
if dp[k] == 1:
    print('First')
else:
    print('Second')

### FIXED CODE ###

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

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

dp = [0] * (K+1)

for k in range(0,K+1):
    for i in A:
        if dp[k] == 0 and k-i >= 0 and dp[k-i] == 0:
            dp[k] = 1

            
if dp[k] == 1:
    print('First')
else:
    print('Second')
### BUGGY CODE ###

from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l = list(set(l))

    while 1 < len(l):
        for i in range(1, len(l)):
            if l[i]%l[0] == 0:
                l[i] = l[0]
            elif l[i] - l[i-1] == 1:
                print(1)
                return
            else:
                l[i] = l[i]%l[0]
        #l = [e for e in l if e != 0]
        l = list(set(l))
        #l.sort()

        if l[0]==1:
            print(1)
            return

    print(l[0])
    return

if __name__ == '__main__':
    fun()


### FIXED CODE ###

from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l = list(set(l))
    l.sort()

    while 1 < len(l):
        k = len(l)
        for i in range(1, k):
            if l[k-i]%l[0] == 0:
                l.pop(k-i)
            elif l[k-i] - l[k-i-1] == 1:
                print(1)
                return
            else:
                l[k-i] = l[k-i]%l[0]
        #l = [e for e in l if e != 0]
        l = list(set(l))
        l.sort()

        if l[0]==1:
            print(1)
            return

    print(l[0])
    return

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

import sys
import functools
def func(a,b):
    y = max(a,b)
    x = min(a,b)
    i = 1
    while True:
        tmp = y * i
        if tmp % x == 0:
            break
        else:
            i += 1
    return tmp

def slove(n, t):
    t.sort()
    ans = functools.reduce(func, t)
    return ans

if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    t = [int(input()) for i in range(n)]
    print(slove(n, t))


### FIXED CODE ###

import sys
import functools
import fractions
def slove(n, t):
    t.sort()
    ans = functools.reduce(lambda x,y:(x*y)//fractions.gcd(x,y), t)
    return ans

if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    t = [int(input()) for i in range(n)]
    print(slove(n, t))