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

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())
i = 1
num = [0] * 13

while True:
    cnt = 0
    for j in range(1, i+1):
        if i % j == 0:
            cnt += 1
    if cnt >= 12:
        i += 1
        continue

    if num[cnt] == 0:
        num[cnt] = i

    if num[n] > 0:
        ans = num[n]
        break

    i += 1

print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())
i = 1
num = [0] * 13

while True:
    cnt = 0
    for j in range(1, i+1):
        if i % j == 0:
            cnt += 1

    if cnt > 12:
        i += 1
        continue

    if num[cnt] == 0:
        num[cnt] = i

    if num[n] > 0:
        ans = num[n]
        break

    i += 1

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

N, M = map(int, input().split())
MOD = 1000000007

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

dp = [0] * (N + 2)
dp[N] = 1
for i in reversed(range(N)):
    if i in broken:
        dp[i] = 0
        continue
    dp[i] = dp[i+1] + dp[i+2]

print(dp[0] % MOD)


### FIXED CODE ###

N, B = map(int, input().split())
ana = []
dp = [0] * (N+2)

for i in range(B):
    ana.append(int(input()))

mod = 1000000007

dp[N] = 1
for i in reversed(range(N)):
    if len(ana) >= 1 and i == ana[-1]:
        dp[i] = 0
        if len(ana) != 0:
            ana.pop(-1)
        continue
    dp[i] = dp[i + 1] + dp[i + 2]
print(dp[0] % mod)
### BUGGY CODE ###

import os
import sys

from scipy.misc import comb

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# MOD = 998244353


R1, C1, R2, C2 = list(map(int, sys.stdin.buffer.readline().split()))


# 解説
# ある要素に注目して残りを選ぶ数を数えると分かる
# ncr(n, r) == ncr(n-1,r) + (n-1,r-1)
# nhr(n, r) == sum([nhr(n-1,k) for k in range(r)])

# g(r, c) を f(i, j) (0<=i<=r, 0<=j<=c) の総和とすると
# g(R2, C2) - g(R1-1, C2) - g(R2, C1-1) + g(R1-1, C1-1)

def f(n, r):
    return comb(n + r, r, exact=True)


# @debug
def g(r, c):
    # ret = 0
    # for i in range(1, c + 2):
    #     ret += f(r, i)
    #     ret %= MOD

    # f(r,k) (k=[1,c+1]) の和
    return f(r + 1, c + 1) - f(r, 0)


ans = g(R2, C2) - g(R1 - 1, C2) - g(R2, C1 - 1) + g(R1 - 1, C1 - 1)
ans %= MOD
print(ans)


### FIXED CODE ###

import os
import sys


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def mod_invs(max, mod):
    """
    逆元 0, 1/1, 1/2, 1/3, ..., 1/max
    :param int max:
    :param int mod:
    """
    invs = [1] * (max + 1)
    invs[0] = 0
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


def factorial_invs(max, mod):
    """
    階乗 0!, 1!, 2!, ..., max! の逆元
    :param int max:
    :param int mod:
    """
    ret = [1]
    r = 1
    for inv in mod_invs(max, mod)[1:]:
        r = r * inv % mod
        ret.append(r)
    return ret


def get_factorials(max, mod=None):
    """
    階乗 0!, 1!, 2!, ..., max!
    :param int max:
    :param int mod:
    """
    ret = [1]
    n = 1
    if mod:
        for i in range(1, max + 1):
            n *= i
            n %= mod
            ret.append(n)
    else:
        for i in range(1, max + 1):
            n *= i
            ret.append(n)
    return ret


class Combination:
    def __init__(self, max, mod):
        """
        :param int max:
        :param int mod: 3 以上の素数であること
        """
        self._factorials = get_factorials(max, mod)
        self._finvs = factorial_invs(max, mod)
        self._mod = mod

    def ncr(self, n, r):
        """
        :param int n:
        :param int r:
        :rtype: int
        """
        if n < r:
            return 0
        return self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod


R1, C1, R2, C2 = list(map(int, sys.stdin.buffer.readline().split()))

comb = Combination(max=10 ** 6 * 2 + 100, mod=MOD)


# 解説
# ある要素に注目して残りを選ぶ数を数えると分かる
# ncr(n, r) == ncr(n-1,r) + (n-1,r-1)
# nhr(n, r) == sum([nhr(n-1,k) for k in range(r)])

# g(r, c) を f(i, j) (0<=i<=r, 0<=j<=c) の総和とすると
# g(R2, C2) - g(R1-1, C2) - g(R2, C1-1) + g(R1-1, C1-1)

def f(n, r):
    return comb.ncr(n + r, r)


# @debug
def g(r, c):
    ret = 0
    for i in range(1, c + 2):
        ret += f(r, i)
        ret %= MOD
    return ret


ans = g(R2, C2) - g(R1 - 1, C2) - g(R2, C1 - 1) + g(R1 - 1, C1 - 1)
ans %= MOD
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

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

for i in range(1, M // 2 + 1):
    if M % i == 0 and i >= N:
        print(M // i)
        exit()

print(1)


### FIXED CODE ###

# -*- coding: utf-8 -*-

import bisect

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

y = [1, M]
for i in range(2, int(M ** 0.5) + 1):
    if M % i == 0:
        y.append(i)
        y.append(M // i)

y.sort()
print(M // y[bisect.bisect_left(y, N)])
### BUGGY CODE ###

N,s = input().split()
S = int(s)
a = []
for i in range(int(N)):
    a.append(int(input()))

a.sort()

diff = []

for i in range(int(N)-(S - 1)):
    v = 0
    for j in range(int(S)-1):
        v += a[i+j+1]-a[i+j]

    diff.append(v)

print(min(diff))





### FIXED CODE ###

N,s = input().split()
S = int(s)
a = []
for i in range(int(N)):
    a.append(int(input()))

a.sort()

mindiff = 1000000000

for i in range(int(N)-(S - 1)):
    v = a[i+S-1]-a[i]

    if mindiff > v: mindiff = v

print(mindiff)
### BUGGY CODE ###

from collections import Counter

def solve():
    MOD = 10**9 + 7

    def getPrimeFactors(x):
        anss = []
        for d in range(2, int(x**0.5)+1):
            while x%d == 0:
                anss.append(d)
                x //= d
        if x != 1:
            anss.append(x)
        return anss

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

    PFss = []
    Primes = set()
    for A in As:
        PFs = getPrimeFactors(A)
        cnt = Counter(PFs)
        PFss.append(cnt)
        Primes |= cnt.keys()

    cntP = Counter()
    for PFs in PFss:
        for key, num in PFs.items():
            cntP[key] = max(cntP[key], num)

    lcmA = 1
    for key, num in cntP.items():
        lcmA *= pow(key, num, MOD)
        lcmA %= MOD

    def getInvs(n, MOD):
        invs = [1] * (n+1)
        for x in range(2, n+1):
            invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
        return invs

    invs = getInvs(10**6, MOD)

    ans = 0
    for A in As:
        ans += lcmA * invs[A]
        ans %= MOD

    print(ans)

solve()


### FIXED CODE ###

from collections import Counter

def solve():
    MOD = 10**9 + 7
    maxA = 10**6

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

    isPrimes = [False]*2 + [True]*(maxA-1)
    minFs = [1] * (maxA+1)
    for i in range(2, int(maxA**0.5) + 1):
        if isPrimes[i]:
            for x in range(i*i, maxA+1, i):
                isPrimes[x] = False
                minFs[x] = i

    def getPrimeFactors(x):
        anss = []
        while minFs[x] > 1:
            anss.append(minFs[x])
            x //= minFs[x]
        if x != 1:
            anss.append(x)
        return anss

    PFss = []
    Primes = set()
    for A in As:
        PFs = getPrimeFactors(A)
        cnt = Counter(PFs)
        PFss.append(cnt)
        Primes |= cnt.keys()

    cntP = Counter()
    for PFs in PFss:
        for key, num in PFs.items():
            cntP[key] = max(cntP[key], num)

    lcmA = 1
    for key, num in cntP.items():
        lcmA *= pow(key, num, MOD)
        lcmA %= MOD

    def getInvs(n, MOD):
        invs = [1] * (n+1)
        for x in range(2, n+1):
            invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
        return invs

    invs = getInvs(10**6, MOD)

    ans = 0
    for A in As:
        ans += lcmA * invs[A]
        ans %= MOD

    print(ans)

solve()
### BUGGY CODE ###

N,M = map(int,input().split())
gateInfos = [list(map(int,input().split()))for i in range(M)]
c = 0
for i in range(1,N+1):
  al = True
  for g in gateInfos:
    L = g[0]
    R = g[1]
    if not L <= i <= R:
      al = False
      break
 
  if al:
    c+= 1
print(c)

### FIXED CODE ###

N,M = map(int,input().split())
maL = 0
miR = N
for g in range(M):
  L,R = map(int,input().split())
  maL = max(maL,L)
  miR = min(miR,R)
if maL <= miR:
  print(miR-maL+1)
else:
  print(0)
### BUGGY CODE ###

def main():
    from fractions import gcd
    import sys
    input = sys.stdin.readline
    n=int(input())
    a=list(map(int,input().split()))
    # n,*a=map(int,open(0).read().split())
    mod=10**9+7
    b=a[0]
    for i in a:
        b=b*i//gcd(b,i)
    ans=0
    for i in a:
        ans+=b//i
        ans%=mod
    print(ans)    
    # print(sum(b//i%mod for i in a)%mod)    
if __name__ == '__main__':
    main()

### FIXED CODE ###

from fractions import *
n,*a=map(int,open(0).read().split())
b=1
for i in a:b*=i//gcd(b,i)
print(sum(b//i for i in a)%(10**9+7))
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    tmp = a[:i] + a[i+1:]
    print(max(tmp))


### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
mx = max(a)
mxi = a.index(mx)
mx2 = max(a[:mxi] + a[mxi+1:])

for i in range(n):
    if i == mxi: print(mx2) 
    else: print(mx)
### BUGGY CODE ###

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return 
    if self.root[x] > self.root[y]:
      x, y = y, x
    self.root[x] += self.root[y]
    self.root[y] = x 
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x): # xが属するグループのサイズを返す
    return -self.root[self.Find_Root(x)]
  def Members(self, x): # xが属するグループに属する要素をリストで返す
    return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
  def Roots(self): # 全ての根の要素をリストで返す
    return [i for i, x in enumerate(self.root) if x < 0]
  def Group_Count(self): # グループの数を返す
    return len(self.Roots())

n, k, l = map(int, input().split())
uf_road = UnionFind(n)
uf_train = UnionFind(n)

for _ in range(k):
  p, q = map(lambda x:int(x)-1, input().split())
  uf_road.Unite(p, q)

for _ in range(l):
  r, s = map(lambda x:int(x)-1, input().split())
  uf_train.Unite(r, s)

for i in range(n):
  road_member = set(uf_road.Members(i))
  train_member = set(uf_train.Members(i))
  print(len(road_member&train_member), end=" ")



### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)

        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[y] = x
        else:
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def main():
  N, K, L = map(int, input().split())
  U_road = UnionFind(N)
  U_train = UnionFind(N)
  for _ in range(K):
    p, q = map(int, input().split())
    U_road.Unite(p, q)
  for _ in range(L):
    r, s = map(int, input().split())
    U_train.Unite(r, s)
  connect_dict = {}
  for i in range(1, N+1):
    x, y = U_road.Find_Root(i), U_train.Find_Root(i)
    if (x, y) in connect_dict:
      connect_dict[(x, y)] += 1
    else:
      connect_dict[(x, y)] = 1
  ans = []
  for i in range(1, N+1):
    x, y = U_road.Find_Root(i), U_train.Find_Root(i)
    ans.append(connect_dict[(x, y)])
  ans = list(map(str, ans))
  print(' '.join(ans))

  

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

S = input()
count = 0
while True:
    flag = []
    S = list(S)
    for i in range(len(S)):
        if i == 0:
            pre_s = S[i]
            flag.append(0)
        else:
            if pre_s != S[i] and flag[i-1] == 0:
                flag.append(1)
                flag[i-1] = 1
                pre_s = S[i]
                S[i-1] = "a"
                S[i] = "a"
            else:
                flag.append(0)
                pre_s = S[i]
            
    if sum(flag) == 0:
        break
    else:
        count += sum(flag)

    S = "".join(S).replace("a", "")
            
print(count)

### FIXED CODE ###

S = input()
a = S.count("0")
b = S.count("1")
if a<b:
    print(a*2)
else:
    print(b*2)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = [None] * n
    for i in range(n):
        s[i] = str(input()).replace("\n", "")

    ans = [None] * n
    index = 0
    for i in s:
        count_word = dict()
        sorted_word = list()
        for j in i:
            if not j in sorted_word:
                count_word[j] = i.count(j)
                sorted_word.append(j)

        ans[index] = count_word
        index += 1

    count = 0
    for i in range(n):
        for j in range(i + 1, n):
            if ans[i] == ans[j]:
                count += 1

    print(count)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = [None] * n
    for i in range(n):
        s[i] = str(input()).replace("\n", "")

    ans = dict()
    pairs = 0
    for i in s:
        i = ''.join(sorted(list(i)))

        if i in ans:
            pairs += ans[i]
            ans[i] += 1
            continue

        ans[i] = 1

    print(pairs)


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

import bisect
import heapq
H,W,N = map(int,input().split())
P = list(list(map(int,input().split()))for i in range(N))
P.sort()

def index(a,x):
    i = bisect.bisect_left(a,x)
    if i != len(a) and a[i] == x:
        return 0
    return -1

def around(a,b):
    out = []
    for i in [-1,0,1]:
        if not 1 < a+i < H:
            continue
        for j in [-1,0,1]:
            if not 1 < b+j < W:
                continue
            out.append([a+i,b+j])
    return out



def search(a,b):
    hoge = 0
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            x,y = a+i,b+j
            if index(P,[x,y]) != -1:
                hoge += 1
    return hoge

A = []
for a,b in P:
    for x,y in around(a,b):
        heapq.heappush(A,[search(x,y),x,y])
a,b = 0,0
ans = [0]*10

while A:
    a = heapq.heappop(A)
    if a != b:
        ans[a[0]] += 1
    b = a[:]

ans[0] = (H-2)*(W-2)-sum(ans[1:])

for i in ans:
    print(i)

### FIXED CODE ###

import sys
input = sys.stdin.readline

H,W,N = map(int,input().split())
A = []
for i in range(N):
    a,b = map(int,input().split())
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if (1< a+i <H) and (1 < b+j < W):
                A.append([a+i,b+j])
A.sort()
ans = [0]*10
hoge = 0
for i in range(len(A)):
    if A[i] == A[i-1]:
        hoge += 1
    else:
        ans[hoge]+= 1
        hoge = 1
ans[hoge]+= 1


ans[0] = (W-2)*(H-2)-sum(ans[1:])

for i in ans:
    print(i)
### BUGGY CODE ###

A, B, C, K = input().strip().split()
A, B, C, K = [int(A), int(B), int(C), int(K)]
sum = 0

for i in range(K):
	if A > 0:
		sum += 1
		A -= 1
	elif B > 0:
		B -= 1
	elif C > 0:
		sum -= 1
		C -= 1

print(sum)

### FIXED CODE ###

A, B, C, K = list(map(int, input().strip().split()))
sum = 0

# for i in range(K):
# 	if A > 0:
# 		sum += 1
# 		A -= 1
# 	elif B > 0:
# 		B -= 1
# 	else:
# 		sum -= 1
# 		C -= 1

# print(sum)

if K <= A:
	sum += K
	print(sum)
else:
	sum += A
	K -= A
	if K <= B:
		print(sum)
	else:
		K -= B
		sum -= K
		print(sum)
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a,b,c,d = LI()

    dp = [[0] * (d+1) for _ in range(c+1)]
    dp[a][b] = 1

    for i in range(a,c+1):
        for j in range(b,d+1):
            if a < i:
                dp[i][j] += dp[i-1][j] * j % mod2
            if b < j:
                dp[i][j] += dp[i][j-1] * i % mod2
            if a < i and b < j:
                dp[i][j] -= dp[i-1][j-1] * (i-1) * (j-1)

            dp[i][j] %= mod2

    return dp[c][d]


print(main())




### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a,b,c,d = LI()

    dp = [[0] * (d+1) for _ in range(c+1)]
    dp[a][b] = 1

    for i in range(a,c+1):
        for j in range(b,d+1):
            if a < i:
                dp[i][j] += dp[i-1][j] * j % mod2
            if b < j:
                dp[i][j] += dp[i][j-1] * i % mod2
            if a < i and b < j:
                dp[i][j] -= dp[i-1][j-1] * (i-1) * (j-1) % mod2

    return dp[c][d] % mod2


print(main())
### BUGGY CODE ###

n = int(input())
a = [0 for i in range(n)]
for i in range(n):
    a[i] = int(input())
now = a[0]
count = 0
while True:
    count += 1
    if now ==2:
        print(count)
        break
    else:
        now = a[now-1]
if count == n:
    print(-1)


### FIXED CODE ###

import sys
a = [int(i) for i in sys.stdin]
now = a[1]
count = 0
while count!=a[0]:
    count += 1
    if now == 2:
        print(count)
        exit()
    now = a[now]
print(-1)
### BUGGY CODE ###

s = input()
counts = [0]*2019
counts[0] += 1
num = 0
d = 1
for c in reversed(s):
    num += int(c)%2019 * d%2019
    counts[num % 2019] += 1
    d *= 10
ans = 0
for count in counts:
    ans += count*(count -1) // 2
print(ans)


### FIXED CODE ###

s = input()
counts = [0]*2019
counts[0] += 1
num = 0
d = 1
for c in reversed(s):
    num += int(c) * d
    counts[num % 2019] += 1
    d *= 10
    d %= 2019
ans = 0
for count in counts:
    ans += count*(count -1) // 2
print(ans)
### BUGGY CODE ###

import itertools
N = int(input())
L = sorted(list(map(int, input().split())))
a = 0
for i in range(len(L)-2):
  if L[i] >= L[i+1] + L[i+2]:
    L.pop(i)
for i in list(itertools.combinations(L,3)):
  if (i[0]<i[1]+i[2]) and (i[1]<i[0]+i[2]) and (i[2]<i[1]+i[0]):
    a += 1
print(a)

### FIXED CODE ###

from bisect import bisect_left
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
 
cnt = 0
 
# 2番目に長い棒bを固定
for b in range(N):
    # bより短い棒aを一つずつ探索
    for a in range(b):
        ab = L[a] + L[b]
        # 二分探索でa+bより短い棒（c<a+bが成り立つc）の範囲を求める
        r = bisect_left(L, ab)
        # cの範囲のうちbの範囲を除外して、cの本数を求める
        cnt += r - (b + 1)
 
print(cnt)
### BUGGY CODE ###

import fractions # python 3.4.3
# import copy
from functools import reduce

N=int(input())

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


def gcd(arr):
    return reduce(fractions.gcd, arr)

ans=gcd(A)

poped=None

for n in range(N):
	if poped != None:
		A.insert(n-1,poped)
	poped=A.pop(n)
	# print(A)
	ans=max(gcd(A),ans)

print(ans)



### FIXED CODE ###

import fractions # python 3.4.3
# import copy
from functools import reduce

N=int(input())

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

# n個目までの最小公約数
dp=[0 for _ in range(N+1)]
dpRev=[0 for _ in range(N+1)]

def gcd(a,b):
	if a == 0: 
		return b
	elif b == 0: 
		return a
	# print(a,b)
	return reduce(fractions.gcd, (a,b))

dp[0]=0
for n in range(0,N):
	dp[n+1]=gcd(dp[n],A[n])

dpRev[N]=0
for n in range(N-1,-1,-1):
	dpRev[n]=gcd(A[n],dpRev[n+1])

# print(dp)
# print(dpRev)


ans=0
for n in range(N):
	ans = max( ans, gcd(dp[n],dpRev[n+1]) )


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

def main():
    c = [ [ int(x) for x in input().split() ] for _ in range(3) ]

    for a1 in range(101):
        for a2 in range(101):
            for a3 in range(101):
                b1 = c[0][0] - a1
                b2 = c[0][1] - a1
                b3 = c[0][2] - a1
                a = [a1, a2, a3]
                b = [b1, b2, b3]
                flag = True
                for i in range(3):
                    for j in range(3):
                        if c[i][j] != a[i] + b[j]:
                            flag = False
                if flag:
                    print("Yes")
                    return
    print("No")

main()


### FIXED CODE ###

def main():
    c = [ [ int(x) for x in input().split() ] for _ in range(3) ]

    for a1 in range(101):
        for a2 in range(101):
            for a3 in range(101):
                b1 = c[0][0] - a1
                b2 = c[0][1] - a1
                b3 = c[0][2] - a1
                a = [a1, a2, a3]
                b = [b1, b2, b3]
                flag = True
                for i in range(3):
                    for j in range(3):
                        if c[i][j] != a[i] + b[j]:
                            flag = False
                if flag:
                    print("Yes")
                    return
    print("No")

main()
### BUGGY CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

ans = 0
for i in range(2**n):
  mo = 1000
  st = 0
  for j in range(n):
    if ((i>>j) & 1):
      s = mo//a[j]
      st += s
      mo -=a[j]*s
    else:
      mo+=st*a[j]
      st = 0
  ans = max(ans, mo)
print(ans) 


### FIXED CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

dp=[0]*(n+1)
dp[0] = 1000

for i in range(1,n):
  dp[i]=dp[i-1]
  for j in range(i):
    v = dp[j] // a[j]
    w = dp[j] + (a[i]-a[j])*v
    dp[i] = max(dp[i],w)
print(dp[n-1])
### BUGGY CODE ###

def main():

    S = str(input())
    Q = int(input())

    Query = []
    for i in range(Q):
        Query.append(list(input().split()))
    for i in range(Q):
        if Query[i][0] == "1":
            S = S[::-1]
        else:
            if Query[i][1] == "1":
                S = "".join([Query[i][2],S])
            else:
                S = "".join([S,Query[i][2]])

    print(S)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque

def main():

    S = deque(list(input()))

    r = False
    for i in range(int(input())):
        Query = input().split()
        if Query[0] == "1":
            r = not r
        else:
            if (r==False and Query[1] == "1") or (r==True and Query[1] == "2"):
                S.appendleft(Query[2])
            else:
                S.append(Query[2])

    if r == True:
        S.reverse()

    print("".join(list(S)))


if __name__ == '__main__':
    main()