#!/usr/bin/env python3

import sys

from fractions import gcd

input = sys.stdin.readline



class DisjointSparseTable:

    def __init__(self, a):

        # Identity element

        self.e = 0

        self.level = (len(a) - 1).bit_length()

        self.size = 2**self.level

        self.table = [[self.e] * self.size for _ in range(self.level)]

        # Set bottom first

        for i, item in enumerate(a):

            self.table[-1][i] = item

        self.build()



    def build(self):

        for i in range(1, self.level):

            step = 2**i

            lv = self.level - 1 - i

            for mid in range(step, self.size, step*2):

                # Forward

                val = self.e 

                for j in range(step):

                    val = gcd(self.table[-1][mid + j], val)

                    self.table[lv][mid + j] = val

                # Backward

                val = self.e

                for j in range(step):

                    val = gcd(self.table[-1][mid - 1 - j], val)

                    self.table[lv][mid - 1 - j] = val



    # Returns f[l:r)

    def query(self, l, r):

        if l == r:

            return self.e

        elif l == r - 1:

            return self.table[-1][l]

        lv = self.level - (l ^ r-1).bit_length()

        return gcd(self.table[lv][l], self.table[lv][r-1])



 

if __name__ == "__main__":

    n = int(eval(input()))

    a = [int(item) for item in input().split()]

    DST = DisjointSparseTable(a)

    ans = 0

    for i in range(0, n):

        ans = max(ans, gcd(DST.query(0, i), DST.query(i+1, n)))

    print(ans)
#!/usr/bin/env python3

import sys

from fractions import gcd

input = sys.stdin.readline

 

class DisjointSparseTable:

    def __init__(self, a):

        # Identity element

        self.e = 0

        self.n = len(a)

        self.level = (len(a) - 1).bit_length()

        self.size = 2**self.level

        self.table = [[self.e] * self.size for _ in range(self.level)]

        # Set bottom first

        for i, item in enumerate(a):

            self.table[-1][i] = item

        self.build()

 

    def build(self):

        for i in range(1, self.level):

            step = 2**i

            lv = self.level - 1 - i

            for mid in range(step, self.size, step*2):

                if mid - step >= self.n:

                    continue

                # Forward

                val = self.e 

                for j in range(step):

                    val = gcd(self.table[-1][mid + j], val)

                    self.table[lv][mid + j] = val

                # Backward

                val = self.e

                for j in range(step):

                    val = gcd(self.table[-1][mid - 1 - j], val)

                    self.table[lv][mid - 1 - j] = val

 

    # Returns f[l:r)

    def query(self, l, r):

        if l == r:

            return self.e

        elif l == r - 1:

            return self.table[-1][l]

        lv = self.level - (l ^ r-1).bit_length()

        return gcd(self.table[lv][l], self.table[lv][r-1])

 

 

if __name__ == "__main__":

    n = int(eval(input()))

    a = [int(item) for item in input().split()]

    DST = DisjointSparseTable(a)

    ans = 0

    for i in range(0, n):

        ans = max(ans, gcd(DST.query(0, i), DST.query(i+1, n)))

    print(ans)
#!/usr/bin/env python3
import sys
from fractions import gcd

input = sys.stdin.readline


class DisjointSparseTable:
    def __init__(self, a):
        # Identity element
        self.e = 0
        self.level = (len(a) - 1).bit_length()
        self.size = 2**self.level
        self.table = [[self.e] * self.size for _ in range(self.level)]
        # Set bottom first
        for i, item in enumerate(a):
            self.table[-1][i] = item
        self.build()

    def build(self):
        for i in range(1, self.level):
            step = 2**i
            lv = self.level - 1 - i
            for mid in range(step, self.size, step * 2):
                # Forward
                val = self.e
                for j in range(step):
                    val = gcd(self.table[-1][mid + j], val)
                    self.table[lv][mid + j] = val
                # Backward
                val = self.e
                for j in range(step):
                    val = gcd(self.table[-1][mid - 1 - j], val)
                    self.table[lv][mid - 1 - j] = val

    # Returns f[l:r)
    def query(self, l, r):
        if l == r:
            return self.e
        elif l == r - 1:
            return self.table[-1][l]
        lv = self.level - (l ^ r - 1).bit_length()
        return gcd(self.table[lv][l], self.table[lv][r - 1])


if __name__ == "__main__":
    n = int(eval(input()))
    a = [int(item) for item in input().split()]
    DST = DisjointSparseTable(a)
    ans = 0
    for i in range(0, n):
        ans = max(ans, gcd(DST.query(0, i), DST.query(i + 1, n)))
    print(ans)

#!/usr/bin/env python3
import sys
from fractions import gcd

input = sys.stdin.readline


class DisjointSparseTable:
    def __init__(self, a):
        # Identity element
        self.e = 0
        self.n = len(a)
        self.level = (len(a) - 1).bit_length()
        self.size = 2**self.level
        self.table = [[self.e] * self.size for _ in range(self.level)]
        # Set bottom first
        for i, item in enumerate(a):
            self.table[-1][i] = item
        self.build()

    def build(self):
        for i in range(1, self.level):
            step = 2**i
            lv = self.level - 1 - i
            for mid in range(step, self.size, step * 2):
                if mid - step >= self.n:
                    continue
                # Forward
                val = self.e
                for j in range(step):
                    val = gcd(self.table[-1][mid + j], val)
                    self.table[lv][mid + j] = val
                # Backward
                val = self.e
                for j in range(step):
                    val = gcd(self.table[-1][mid - 1 - j], val)
                    self.table[lv][mid - 1 - j] = val

    # Returns f[l:r)
    def query(self, l, r):
        if l == r:
            return self.e
        elif l == r - 1:
            return self.table[-1][l]
        lv = self.level - (l ^ r - 1).bit_length()
        return gcd(self.table[lv][l], self.table[lv][r - 1])


if __name__ == "__main__":
    n = int(eval(input()))
    a = [int(item) for item in input().split()]
    DST = DisjointSparseTable(a)
    ans = 0
    for i in range(0, n):
        ans = max(ans, gcd(DST.query(0, i), DST.query(i + 1, n)))
    print(ans)

+        self.n = len(a) +                if mid - step >= self.n: +                    continue