Problem:
Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.

Solution in C# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC20190427
{
    class Program
    {
        static void Main(string[] args)
        {
            //Sample();
            //Biscuit();
            //Console.ReadLine();
            //Biscuit();
            //Console.ReadLine();
            //Biscuit();
            //Console.ReadLine();

            GCDOnBlackBoard();
            //Console.ReadLine();

            //GCDOnBlackBoard();
            //Console.ReadLine();

            //GCDOnBlackBoard();
            //Console.ReadLine();

            //Console.ReadLine();
            //Resale();
            //Console.ReadLine();

        }

        static void GCDOnBlackBoard()
        {
            int n = int.Parse(Console.ReadLine());
            int[] numArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();


            int result = 0;
            for (int i = 0; i < n; i++)
            {
                int[] copy = new int[n];
                numArray.CopyTo(copy, 0);

                if (i == 0)
                {
                    copy[i] = copy[i + 1];
                }
                else
                {
                    copy[i] = copy[i - 1];
                }

                int resultTmp = CalcGCD(copy);

                if (resultTmp > result)
                    result = resultTmp;
            }

            Console.WriteLine(result);
        }
        
        static int CalcGCD(int[] numArray)
        {
            int result = 0;
            int maxIndex = numArray.Length - 1;

            for (int i = 0; i <= maxIndex - 1; i++)
            {
                int a = 0;
                int b = 0;
                if (numArray[i] > numArray[i + 1])
                {
                    a = numArray[i];
                    b = numArray[i + 1];
                }
                else
                {
                    a = numArray[i + 1];
                    b = numArray[i];
                }

                numArray[i + 1] = _CalcGCD(a, b);
            }

            return numArray[maxIndex];
        }

        /// <summary>
        /// a >= b が前提
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        static int _CalcGCD(int a, int b)
        {
            while (true)
            {
                int amari = a % b;
                if (amari == 0)
                {
                    return b;
                }
                else
                {
                    a = b;
                    b = amari;
                }
            }
        }



        static void Resale()
        {
            // 整数の入力
            int n = int.Parse(Console.ReadLine());
            int[] jewelValues = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int[] jewelCosts  = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            // 宝石オブジェクトに変換
            List<Jewel> jewelList = new List<Jewel>();
            for (int i = 0; i < n; i++)
            {
                jewelList.Add(new Jewel(jewelValues[i], jewelCosts[i]));
            }
            
            int result = jewelList
                .Select(jewel => jewel.Value - jewel.Cost)
                .Where(profit => profit >= 0)
                .Sum();

            //for (int i = 0; i < n; i++) {
            //    // 全ての組み合わせを試す。
            //    foreach (var ary in Comb(jewelList, i))
            //    {
            //        int tmp = CalcProfit(ary);
            //        if (result < tmp)
            //        {
            //            result = tmp;
            //        }
            //    }
            //}
            Console.WriteLine(result);
        }

        static int CalcProfit(IEnumerable<Jewel> jewelArray)
        {
            return jewelArray.Select(jewel => jewel.Value - jewel.Cost).Sum();
        }

        struct Jewel
        {
            public int Value { get; set; }
            public int Cost { get; set; }

            public Jewel(int value, int cost)
            {
                Value = value;
                Cost = cost;
            }
        }

        static void Biscuit()
        {
            // A B T
            string[] input = Console.ReadLine().Split(' ');
            int span = int.Parse(input[0]);
            int biscuitPerSpan = int.Parse(input[1]);
            int time = int.Parse(input[2]);

            int spanCount = time / span;
            int result = biscuitPerSpan * spanCount;

            //出力
            Console.WriteLine(result);
        }


        static void Sample()
        {
            // 整数の入力
            int a = int.Parse(Console.ReadLine());

            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int b = int.Parse(input[0]);
            int c = int.Parse(input[1]);

            // 文字列の入力
            string s = Console.ReadLine();

            //出力
            Console.WriteLine((a + b + c) + " " + s);
        }

        //// 要素をシーケンスに追加するユーティリティ
        //public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
        //{
        //    yield return first;

        //    foreach (var i in items)
        //        yield return i;
        //}

        //public static IEnumerable<IEnumerable<T>> Comb<T>(this IEnumerable<T> items, int r)
        //{
        //    if (r == 0)
        //    {
        //        yield return Enumerable.Empty<T>();
        //    }
        //    else
        //    {
        //        var i = 1;
        //        foreach (var x in items)
        //        {
        //            var xs = items.Skip(i);
        //            foreach (var c in Comb(xs, r - 1))
        //                yield return c.Before(x);

        //            i++;
        //        }
        //    }
        //}
    }
}