def main():

    N = int(eval(input()))

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

    gcd_L = [0]*(N+2)

    gcd_R = [0]*(N+2)



    def gcd(x, y):

        if y == 0:

            return x

        while y != 0:

            x, y = y, x % y

        return x



    for i, a in enumerate(A):

        gcd_L[i+1] = gcd(gcd_L[i], a)

    for i, a in enumerate(A[::-1], start=1):

        gcd_R[-(i+1)] = gcd(gcd_R[-i], a)

    gcd_R[0] = gcd_R[1]

    gcd_L[-1] = gcd_L[-2]

    # print(gcd_L, gcd_R)

    ans = 0

    for i in range(1, N+1):

        cur = gcd(gcd_L[i-1], gcd_R[i+1])

        ans = max(ans, cur)

    print(ans)





if __name__ == '__main__':

    main()

from math import gcd





class SegTree:

    X_unit = 0

    X_f = gcd



    def __init__(self, N):

        self.N = N

        self.X = [self.X_unit] * (N + N)



    def build(self, seq):

        for i, x in enumerate(seq, self.N):

            self.X[i] = x

        for i in range(self.N - 1, 0, -1):

            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])



    def set_val(self, i, x):

        i += self.N

        self.X[i] = x

        while i > 1:

            i >>= 1

            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])



    def fold(self, L, R):

        L += self.N

        R += self.N

        vL = self.X_unit

        vR = self.X_unit

        while L < R:

            if L & 1:

                vL = self.X_f(vL, self.X[L])

                L += 1

            if R & 1:

                R -= 1

                vR = self.X_f(self.X[R], vR)

            L >>= 1

            R >>= 1

        return self.X_f(vL, vR)





def main():

    N = int(eval(input()))

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

    seg = SegTree(N)

    seg.build(A)

    ans = 0

    for i in range(N):

        ans = max(ans, gcd(seg.fold(0, i), seg.fold(i+1, N)))

    print(ans)





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    gcd_L = [0] * (N + 2)
    gcd_R = [0] * (N + 2)

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

    for i, a in enumerate(A):
        gcd_L[i + 1] = gcd(gcd_L[i], a)
    for i, a in enumerate(A[::-1], start=1):
        gcd_R[-(i + 1)] = gcd(gcd_R[-i], a)
    gcd_R[0] = gcd_R[1]
    gcd_L[-1] = gcd_L[-2]
    # print(gcd_L, gcd_R)
    ans = 0
    for i in range(1, N + 1):
        cur = gcd(gcd_L[i - 1], gcd_R[i + 1])
        ans = max(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

from math import gcd


class SegTree:
    X_unit = 0
    X_f = gcd

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)


def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    seg = SegTree(N)
    seg.build(A)
    ans = 0
    for i in range(N):
        ans = max(ans, gcd(seg.fold(0, i), seg.fold(i + 1, N)))
    print(ans)


if __name__ == "__main__":
    main()

+from math import gcd + + +class SegTree: +    X_unit = 0 +    X_f = gcd + +    def __init__(self, N): +        self.N = N +        self.X = [self.X_unit] * (N + N) + +    def build(self, seq): +        for i, x in enumerate(seq, self.N): +            self.X[i] = x +        for i in range(self.N - 1, 0, -1): +            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) + +    def set_val(self, i, x): +        i += self.N +        self.X[i] = x +        while i > 1: +            i >>= 1 +            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) + +    def fold(self, L, R): +        L += self.N +        R += self.N +        vL = self.X_unit +        vR = self.X_unit +        while L < R: +            if L & 1: +                vL = self.X_f(vL, self.X[L]) +                L += 1 +            if R & 1: +                R -= 1 +                vR = self.X_f(self.X[R], vR) +            L >>= 1 +            R >>= 1 +        return self.X_f(vL, vR) + + -    gcd_L = [0] * (N + 2) -    gcd_R = [0] * (N + 2) - -    def gcd(x, y): -        if y == 0: -            return x -        while y != 0: -            x, y = y, x % y -        return x - -    for i, a in enumerate(A): -        gcd_L[i + 1] = gcd(gcd_L[i], a) -    for i, a in enumerate(A[::-1], start=1): -        gcd_R[-(i + 1)] = gcd(gcd_R[-i], a) -    gcd_R[0] = gcd_R[1] -    gcd_L[-1] = gcd_L[-2] -    # print(gcd_L, gcd_R) +    seg = SegTree(N) +    seg.build(A) -    for i in range(1, N + 1): -        cur = gcd(gcd_L[i - 1], gcd_R[i + 1]) -        ans = max(ans, cur) +    for i in range(N): +        ans = max(ans, gcd(seg.fold(0, i), seg.fold(i + 1, N)))