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

import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SMI(): return input().split()
def SLI(): return list(input())

def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
# from fractions import gcd

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return sorted(divisors, reverse=True)

def solve():
    N = II()
    A = LI()

    p = 1
    l = 1
    for a in A:
        l = lcm(p, a)
        p = a

    div = make_divisors(l)

    for d in div:
        no = 1
        for a in A:
            if a % d == 0:
                continue
            else:
                no -= 1
                if no < 0:
                    break
        else:
            print(d)
            return
    print(1)



if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SMI(): return input().split()
def SLI(): return list(input())

def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

from fractions import gcd

def solve():
    N = II()
    A = LI()

    # 左から累積和的gcd
    L = [1] * N
    L[0] = A[0]
    for i in range(1, N):
        L[i] = gcd(A[i], L[i-1])

    # 右から累積和的gcd
    R = [1] * N
    R[-1] = A[-1]
    for i in range(N-2, -1, -1):
        R[i] = gcd(A[i], R[i+1])

    # print(L)
    # print(R)
    ans = 1
    for i, a in enumerate(A):
        l = i - 1
        r = i + 1
        if l < 0:
            ans = max(ans, R[r])
        elif r >= N:
            ans = max(ans, L[l])
        else:
            ans = max(ans, gcd(L[l], R[r]))
    print(ans)

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

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

p = len(format(max(A), 'b'))
digit = ['0' + str(p) + 'b'] * N
S = list(map(format, A, digit))

r = [0] * p
for s in S:
  for j in range(p):
    r[j] += int(s[j])

res = 0
for j in range(p):
  res += r[j] * (N - r[j]) * (2 ** (p-1-j))

print(res % (10**9 + 7))

### FIXED CODE ###

import numpy as np 
N = int(input())
A = np.fromstring(input(), dtype = np.int64, sep = ' ')

res = 0
for bit in range(60):
  c = int((A & 1).sum())
  res += c * (N - c) * (1 << bit)
  A >>= 1

print(res % 1000000007)
### BUGGY CODE ###

N = int(input())
P_list = [int(i) for i in input().split()]

cnt = 1 # 1件目は必ず合致するので
for i in range(1,len(P_list)) :
    pi = P_list[i]
    is_match = True
    for j in range(i) : # Pi==Pjは必ず正なのでジャッジ不要
        pj = P_list[j]
        if (pi > pj) :
            is_match = False
            break
    
    if (is_match) :
        cnt += 1

print(cnt)

### FIXED CODE ###

N = int(input())
P_list = [int(i) for i in input().split()]

# cnt = 1 # 1件目は必ず合致するので

# for i in range(1,len(P_list)) :
#     pi = P_list[i]
#     is_match = True
#     for j in range(i) : # Pi==Pjは必ず正なのでジャッジ不要
#         pj = P_list[j]
#         if (pi > pj) :
#             is_match = False
#             break
    
#     if (is_match) :
#         cnt += 1

cnt = 1 # 1件目は必ず合致するので
min_map = [P_list[0]]
min_value = P_list[0]
for i in range(1,len(P_list)) :
    min_value = min(min_value,P_list[i])
    min_map.append(min_value)

# print(min_map)
for i in range(1,len(P_list)) :
    if (min_map[i] >= P_list[i]) :
        cnt += 1



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

n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[-1]+a[i])
s=sum(a)
ans=10**20
for i in range(n-1):
    ans=min(ans,abs(sum(a)-2*b[i]))
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
for i in range(1,n):
    b.append(b[-1]+a[i])
s=sum(a)
ans=10**20
for i in range(n-1):
    ans=min(ans,abs(s-2*b[i]))
print(ans)
### BUGGY CODE ###

s = input()

l, r = 0, len(s)
while r - l > 1:
    c = (l + r) // 2
    
    # current point can be seen as xth smallest val, where x can be any value in [a, b] (subset of [0, c])
    # a <= b
    a, b = 0, c
    ok = True
    discrete = False # when True x = a, a+2, ..., b-2, b
    for si in s:
        if si == '1':
            if a == b == c:
                ok = False
                break
            a += 1
            b += 1
            if b > c:
                b = c - 1 if discrete else c
        elif si == '0':
            if a == b == 0:
                ok = False
                break
            a -= 1
            b -= 1
            if a < 0:
                a = 1 if discrete else 0
        else:
            if a == b == 0:
                a = b = 1
            elif a == b == c:
                a = b = c - 1
            elif a == b:
                discrete = True
                a -= 1
                b += 1
            else:
                a -= 1
                b += 1
                if a < 0:
                    a = 1 if discrete else 0
                if b > c:
                    b = c - 1 if discrete else c
    if ok:
        r = c
    else:
        l = c
print(r)


### FIXED CODE ###

from numba import njit
import numpy as np
s = np.array(list(map(lambda x: -1 if x == '?' else int(x), input())))
@njit
def test(c):
    # current point can be seen as xth smallest val, where x can be any value in [a, b] (subset of [0, c])
    # a <= b
    a, b = 0, c
    ok = True
    discrete = False # when True x = a, a+2, ..., b-2, b
    for si in s:
        if si == 1:
            if a == b == c:
                return False
            a += 1
            b += 1
            if b > c:
                b = c - 1 if discrete else c
        elif si == 0:
            if a == b == 0:
                return False
            a -= 1
            b -= 1
            if a < 0:
                a = 1 if discrete else 0
        else:
            if a == b == 0:
                a = b = 1
            elif a == b == c:
                a = b = c - 1
            elif a == b:
                discrete = True
                a -= 1
                b += 1
            else:
                a -= 1
                b += 1
                if a < 0:
                    a = 1 if discrete else 0
                if b > c:
                    b = c - 1 if discrete else c
    return True

l, r = 0, s.size
while r - l > 1:
    c = (l + r) // 2
    if test(c):
        r = c
    else:
        l = c
print(r)
### BUGGY CODE ###

n=int(input())
s=input()
r=[]
g=[]
b=[]

for i in range(len(s)):
    if s[i]=='R':
        r.append(i)
    elif s[i]=='G':
        g.append(i)
    elif s[i]=='B':
        b.append(i)

def cal(l1,l2,l3):
    cnt=0
    for _l1 in range(len(l1)):
        for _l2 in range(len(l2)):
            if l1[_l1]<l2[_l2]:
                for _l3 in range(len(l3)):
                    if l2[_l2]<l3[_l3]:
                        if l3[_l3]-l2[_l2]!=l2[_l2]-l1[_l1]:
                            cnt+=1
    return cnt
        
count=0
count+=cal(r,g,b)
count+=cal(r,b,g)
count+=cal(g,r,b)
count+=cal(g,b,r)
count+=cal(b,r,g)
count+=cal(b,g,r)
print(count)



### FIXED CODE ###

n=int(input())
s=input()
c=s.count
m=c('R')*c('G')*c('B')
for i in range(n):
  for j in range(i+2,n,2):
    if s[i]!=s[i+j>>1]!=s[j]!=s[i]:
      m-=1
print(m)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
Ad = [A[i]-(i+1) for i in range(N)]
max_Ad = max(map(abs, Ad))
min_total = float("inf")

for b in range(-max_Ad, max_Ad+1):
    Ad = list(map(lambda x: x-b, Ad))
    total = sum(map(abs, Ad))
    if min_total > total:
        min_total = total
print(min_total)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
Ad = [A[i]-(i+1) for i in range(N)]
Ad.sort()
l = len(Ad)
if l % 2 == 1:
    b = Ad[l//2]
    ans = sum(map(lambda x:abs(x-b), Ad))
else:
    b1, b2 = Ad[l//2], Ad[l//2-1]
    ans = min(sum(map(lambda x:abs(x-b1), Ad)), sum(map(lambda x:abs(x-b2), Ad)))
print(ans)
### BUGGY CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
nodes = [[] for i in range(N)]
edges = {}
for i in range(N-1):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)
    edges[(a, b)] = [i, -1]

mx = 0
used = [set() for i in range(N)]
ans = [0] * (N-1)
cnt = 0
for u in range(N):
    mx = max(mx, len(nodes[u]))
    for v in nodes[u]:
        a, b = min(u, v), max(u, v)
        if edges[(a, b)][1] == -1:
            color = 1
            while color in used[a] or color in used[b]:
                color += 1
            edges[(a, b)][1] = color
            used[a].add(color)
            used[b].add(color)
            i = edges[(a, b)][0]
            ans[i] = str(color)
            cnt += 1
            if cnt == N-1:
                break
    else:
        continue
    break
print(mx)
print('\n'.join(ans))


### FIXED CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
nodes = [[] for i in range(N)]
edges = {}
for i in range(N-1):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)
    edges[(a, b)] = [i, -1]

mx = 0
used = [set() for i in range(N)]
ans = [0] * (N-1)
cnt = 0
for u in range(N):
    mx = max(mx, len(nodes[u]))
    color = 1
    for v in nodes[u]:
        a, b = min(u, v), max(u, v)
        if edges[(a, b)][1] == -1:
            while color in used[a] or color in used[b]:
                color += 1
            edges[(a, b)][1] = color
            used[a].add(color)
            used[b].add(color)
            i = edges[(a, b)][0]
            ans[i] = str(color)
            color += 1
            cnt += 1
            if cnt == N-1:
                break
    else:
        continue
    break
print(mx)
print('\n'.join(ans))
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

def inv_gcd(a, b):
    a = (a + b) % b
    if a == 0:
        return (b, 0)
    s, t = b, a
    m0, m1 = 0, 1
 
    while t:
        u = s // t
        s -= t * u
        m0 -= m1 * u
 
        tmp = s
        s = t
        t = tmp
        tmp = m0
        m0 = m1
        m1 = tmp
    
    if m0 < 0:
        m0 += b // s
    return (s, m0)
 
 
def crt(r, m):
    n = len(r)
    r0, m0 = 0, 1
 
    for i in range(n):
        r1, m1 = (r[i] + m[i]) % m[i], m[i]
 
        if m0 < m1:
            m0, m1 = m1, m0
            r0, r1 = r1, r0
        
        if m0 % m1 == 0:
            if r0 % m1 != r1:
                return (0, 0)
            continue
        
        g, im = inv_gcd(m0, m1)
 
        u1 = m1 // g
        if (r1 - r0) % g:
            return (0, 0)
        
        x = (r1 - r0) // g % u1 * im % u1
 
        r0 += x * m0
        m0 *= u1
        if (r0 < 0):
            r0 += m0
        
    return (r0, m0)


def divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.sort()
  return divisors


# print(divisors(z))

z=int(input())


ans = z-1 if z%2 else 2*z-1
for i in divisors(2*z):
  y=2*z//i
  if y == 1:
    continue
  a=[0,y-1]
  b=[i,y]
  rem, mod = crt(a, b)
  #print(rem)
  #print(mod)
  if rem == mod == 0:
      continue
  ans = min(ans, rem)

print(ans if z-1 else 1)

### FIXED CODE ###

def inv_gcd(a, b):
    a = (a + b) % b
    if a == 0:
        return (b, 0)
    s, t = b, a
    m0, m1 = 0, 1
 
    while t:
        u = s // t
        s -= t * u
        m0 -= m1 * u
 
        tmp = s
        s = t
        t = tmp
        tmp = m0
        m0 = m1
        m1 = tmp
    
    if m0 < 0:
        m0 += b // s
    return (s, m0)
 
 
def crt(r, m):
    n = len(r)
    r0, m0 = 0, 1
 
    for i in range(n):
        r1, m1 = (r[i] + m[i]) % m[i], m[i]
 
        if m0 < m1:
            m0, m1 = m1, m0
            r0, r1 = r1, r0
        
        if m0 % m1 == 0:
            if r0 % m1 != r1:
                return (0, 0)
            continue
        
        g, im = inv_gcd(m0, m1)
 
        u1 = m1 // g
        if (r1 - r0) % g:
            return (0, 0)
        
        x = (r1 - r0) // g % u1 * im % u1
 
        r0 += x * m0
        m0 *= u1
        if (r0 < 0):
            r0 += m0
        
    return (r0, m0)


def divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.sort()
  return divisors


# print(divisors(z))

z=int(input())


ans = z-1 if z%2 else 2*z-1
for i in divisors(2*z):
  y=2*z//i
  if y == 1:
    continue
  a=[0,-1]
  b=[i,y]
  rem, mod = crt(a, b)
  #print(rem)
  #print(mod)
  if rem == mod == 0:
      continue
  ans = min(ans, rem)

print(ans if z-1 else 1)
### BUGGY CODE ###

import bisect
from collections import deque
n, m = map(int, input().split())
A = deque(sorted(map(int, input().split())))
BC = []
for j in range(m):
    b, c = map(int, input().split())
    BC.append((b, c))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
for b, c in BC:
    i = bisect.bisect_left(A, c)
    if i == 0:
        break
    else:
        start = min(i, b)
        A.extend([c for j in range(start)])
        for _ in range(start):
            A.popleft()
print(sum(A))

### FIXED CODE ###

n, m = map(int, input().split())
A = sorted(map(int, input().split()))
BC = []
for j in range(m):
    b, c = map(int, input().split())
    BC.append((b, c))
BC = sorted(BC, key=lambda x: x[1], reverse=True)
D = []
for b, c in BC:
    D.extend([c for i in range(b)])
    if len(D) >= n:
        D = D[:n]
        break
for x in range(len(D)):
    if A[x] > D[x]:
        break
else:
    x += 1
print(sum(A[x:]) + sum(D[:x]))
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
for i in range(Q):
  a,b=map(int,input().split())
  print(S[a-1:b].count("AC"))

### FIXED CODE ###

import bisect
N,Q=map(int,input().split())
S=input()
l=[]
for i in range(N-1):
  if S[i:i+2]=="AC":
    l.append(i+1)
for i in range(Q):
  a,b=map(int,input().split())
  c=bisect.bisect_left(l,a)
  d=bisect.bisect_right(l,b-1)
  print(d-c)
### BUGGY CODE ###

import bisect
import itertools
N,W=map(int,input().split())
w=[0 for i in range(N)]
v=[0 for i in range(N)]
flag1=1 if N<=30 else 0
flag2=1
flag3=1
for i in range(N):
    w[i],v[i]=map(int,input().split())
    if v[i]>100000:
        flag2=0
    if w[i]>100000:
        flag3=0
if flag1==1:
    A=[];B=[]
    for i in range(N):
        if i%2==0:
            A.append((v[i],w[i]))
        else:
            B.append((v[i],w[i]))
    Al=len(A);Bl=len(B)
    Xtmp=[]
    for seq in itertools.product(range(2),repeat=Al):
        tmp0=0
        tmp1=0
        for i in range(Al):
            if seq[i]==1:
                tmp0+=A[i][0]
                tmp1+=A[i][1]
        Xtmp.append((tmp0,tmp1))
    Xtmp.sort(key=lambda x:x[1])
    X=[]
    Xltmp=len(Xtmp)
    maxtmp=0
    for i,seq in enumerate(Xtmp):
        if maxtmp<=seq[0]:
            X.append(seq)
        maxtmp=max(maxtmp,seq[0])
    #print(X)
    wt=[i[1] for i in X]
    #print(wt)
    ans=0
    for seq in itertools.product(range(2),repeat=Bl):
        tmp0=0
        tmp1=0
        for i in range(Bl):
            if seq[i]==1:
                tmp0+=B[i][0]
                tmp1+=B[i][1]
        if W-tmp1<=0:
            continue
        index=bisect.bisect_right(wt,W-tmp1)-1
        tmp=X[index][0]+tmp0
        ans=max(ans,tmp)
    print(ans)
elif flag2==1:
    V=sum(v)
    INF=10**15
    dp=[[INF for j in range(V+1)] for i in range(N+1)]
    #dp[i][j]:iまで試して価値の合計がjのときの重さの最小値
    dp[0][0]=0
    for i in range(N):
        for j in range(V+1):
            if j-v[i]>=0:
                dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i],INF)
            else:
                dp[i+1][j]=min(dp[i][j],INF)
    b=[]
    for i in range(V+1):
        if dp[N][i]!=INF:
            b.append((dp[N][i],i))
    ans=0
    for (x,y) in b:
        if x<=W:
            ans=max(ans,y)
    print(ans)
elif flag3==1:
    dp=[[0 for i in range(W+1)] for i in range(N+1)]
    for j in range(W+1):
        dp[0][j]=0
    for i in range(N):
        for j in range(W+1):
            dp[i+1][j]=dp[i][j]
            if j-w[i]>=0:
                if dp[i][j]<dp[i][j-w[i]]+v[i]:
                    dp[i+1][j]=dp[i][j-w[i]]+v[i]
    print(dp[N][W])


### FIXED CODE ###

N,W=map(int,input().split())
w=[0 for i in range(N)]
v=[0 for i in range(N)]
for i in range(N):
    w[i],v[i]=map(int,input().split())
dp=[[0 for i in range(W+1)] for i in range(N+1)]
for j in range(W+1):
    dp[0][j]=0
for i in range(N):
    for j in range(W+1):
        dp[i+1][j]=dp[i][j]
        if j-w[i]>=0:
            if dp[i][j]<dp[i][j-w[i]]+v[i]:
                dp[i+1][j]=dp[i][j-w[i]]+v[i]
print(dp[N][W])
### BUGGY CODE ###

n, k = list(map(int, input().split()))
s = input()

s =str(1)+ s + 'E'   # 終端処理
ans = -1    # 答えの初期値（十分に小さい値）

L=1
L2=0
for i in range(n):
    count=0
    v=0
    for j in range(L,n+2):
        if s[j]==str(0):
            #連続してる所は飛ばす。
            if s[j-1]==str(0):
                continue
                
            else:
                count+=1
                
        #0のあと初めて1が出たらindexを取得
        if s[j]==str(1) and count==1 and v==0:
                L2=j
                v+=1
                
            
        if count==k+1:
            
            if i==0:
                ans=j-1
                break
                
            else:
                ans=max(ans,j-L)
                L=L2
                break
            
        if s[j]=='E':
            ans=max(ans,j-L)
            print(ans)
            exit()

### FIXED CODE ###

n, k = list(map(int, input().split()))
s = input()

s =str(1)+ s + 'E'   # 終端処理
ans = -1    # 答えの初期値

L=1
count=0
L2=[1]
for i in range(n):
    if i>=1:
        count-=1
    v=0
    for j in range(L,n+2):
        if s[j]==str(0):
            #連続してる所は飛ばす。
            if s[j-1]==str(0):
                continue
                
            else:
                count+=1
                
        #0のあと初めて1が出たらindexを取得
        if s[j]==str(1):
            if s[j-1]==str(0):
                L2.append(j)
                
            
        if count==k+1:
            
            ans=max(ans,j-L2[i])
            #次はｊ+１から始める
            L=j+1
            break
            
        if s[j]=='E':
            ans=max(ans,j-L2[i])
            print(ans)
            exit()
### BUGGY CODE ###

import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())
    query = [None] * Q
    for i in range(Q):
        query[i] = input().split()

    ans = S
    is_reversed = False
    for q in query:
        if int(q[0]) == 1:
            is_reversed = not is_reversed
        else:
            F, C = int(q[1]), q[2]
            if F == 1:
                if is_reversed:
                    ans = "".join([ans, C])
                else:
                    ans = "".join([C, ans])
            else:
                if is_reversed:
                    ans = "".join([C, ans])
                else:
                    ans = "".join([ans, C])

    if is_reversed:
        ans = ans[::-1]

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

S = input().strip()
Q = int(input())
is_reverse = False
A = ""
B = ""
for i in range(Q):
  query = [j for j in input().strip().split()]
  T = int(query[0])
  if T == 1:
    is_reverse = not is_reverse
  else:
    F, C = int(query[1]), query[2]
    if F == 1:
      if not is_reverse:
        A = C + A
      else:
        B = B + C
    else:
      if not is_reverse:
        B = B + C
      else:
        A = C + A

res = A + S + B
if not is_reverse:
  print(res)
else:
  print(res[::-1])
### BUGGY CODE ###

import math
N=input()
r=math.factorial(N)
print r%(10**9+7)

### FIXED CODE ###

N=input()
 
r=1
for i in xrange(N):
    r=r*(i+1)
    r=r%(10**9 + 7)
 
print r
### BUGGY CODE ###

n, m = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
match = 0
ans = 0
mini = 0

for j in range(n):
    mini = min(a)
    
    for k in range(b[a.index(mini)]):
        if m <= match:
            break
        ans += mini
        match += 1
    
    b.pop(a.index(mini))
    a.remove(mini)
print(ans)

### FIXED CODE ###

# sys.stdin.readline()
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ab = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a,b))
ab = sorted(ab)
for c, d in ab:
    if m >= d:
        ans += c*d
        m -= d
    else:
        ans += c*m
        break
print(ans)
### BUGGY CODE ###

K = int(input())

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(gcd(a,b),c)

print(ans)


### FIXED CODE ###

K = int(input())
ans = 0

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

memo1 = []
memo2 = []
memo3 = []

for i in range(1, K+1):
    memo1.append((i,i,i))

for i in range(1, K):
    for j in range(i+1, K+1):
        memo2.append((i,i,j))
        memo2.append((j,j,i))

for i in range(1, K-1):
    for j in range(i+1, K):
        for k in range(j+1, K+1):
            memo3.append((i,j,k))

for item in memo1:
    ans += gcd(item[2], gcd(item[0], item[1]))
for item in memo2:
    ans += 3 * (gcd(item[2], gcd(item[0], item[1])))
for item in memo3:
    ans += 6 * (gcd(item[2], gcd(item[0], item[1])))

print(ans)