module Main where
import           Control.Monad
import           Data.Bits
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.Monoid
import Data.IORef
--import SegmentTree

data SegmentTree m = Leaf m | Node m (SegmentTree m) (SegmentTree m) deriving (Eq,Show)

val :: SegmentTree m -> m
val (Leaf v) = v
val (Node v _ _) = v




update :: (Monoid m) => SegmentTree m -> Int -> Int -> m -> SegmentTree m
update (Leaf v) _ _ x = Leaf x
update (Node v l r) size i x                                                     
    | i < n'   =   Node ((val left) `mappend` (val r)) left r
    | otherwise =   Node ((val l) `mappend` (val right)) l right
    where n' = size `div` 2
          left = update l n' i x
          right = update r n' (i-n') x




query :: (Monoid m) => SegmentTree m -> Int -> Int -> Int -> m

query (Leaf v) _ 0 1 = v
query (Node v l r) size a b
    | a >= b    = mempty
    | a == 0 && b == size   = v
    | b <= n'             = query l n' a b
    | a >= n'                = query r n' (a-n') (b-n')
    | otherwise             = (query l n' a n') `mappend` (query r n' 0 (b-n'))
    where n' = size `div` 2

resize :: Int -> Int -> Int
resize n m 
    | m < n = resize n (2*m)
    | otherwise  = m


fromList :: Monoid m => [m] -> SegmentTree m
fromList xs = 
    let n = length xs
        m = resize n 1
        plus = [mempty | i<-[1..(m-n)]] 
        xs' = xs ++ plus
    in fromList' xs' m

fromList' ::Monoid m => [m] ->  Int ->SegmentTree m
fromList' _ 0 = Leaf mempty
fromList' [x] 1 = Leaf x
fromList' xs n = Node ((val left) `mappend` (val right)) left right
    where n' = n `div` 2
          (xs1,xs2) = splitAt n' xs
          left = fromList'  xs1 n'
          right = fromList' xs2 (n-n')

get :: Monoid m => SegmentTree m -> Int ->Int -> m
get tree i size= query tree size i (i+1)




tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined
 
 
readInt = fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words
 
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

newtype Gcd = Gcd Integer deriving (Show,Eq,Ord,Read)
 
instance Semigroup Gcd where
    Gcd x <> Gcd y = Gcd (gcd x y)
instance Monoid Gcd where
    mempty = Gcd 0
    Gcd x `mappend` Gcd y = Gcd (gcd x y)

toI :: Gcd -> Integer
toI (Gcd x) = x
 

solve :: [Integer] -> Integer
solve a =
    let n = length a
        seg = fromList $ map Gcd a :: SegmentTree Gcd
        m = resize n 1
    in maximum $ map toI [(query seg m 0 i) `mappend` (query seg m (i+1) (length a)) | i <- [0..length a ]]


main :: IO ()
main = do
    getLine
    a<- getIntList
    print $ solve a