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 Fortran (gfortran v4.8.4) (judge verdict: Time Limit Exceeded)

module ABC125

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_C
  private :: calc_GCD

  ! constants for this <program>
  integer(INT32), parameter, private :: num_integers_max = 10_INT32 ** 5_INT32

  ! variables for this <module>
  integer(INT32), private :: num_integers

  ! arrays for this <module>
  integer(INT32), private :: val_integer(1:num_integers_max)
  integer(INT32), private :: val_GCD    (1:num_integers_max)

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_C

    ! support variables for this <subroutine>
    integer :: iter_elem
    integer :: iter_trgt

    ! STEP.01
    ! read out the number of target integers
    read(unit=INPUT_UNIT, fmt=*) num_integers

    ! STEP.02
    ! read out the value of the given integers
    read(unit=INPUT_UNIT, fmt=*) val_integer(1:num_integers)

    val_GCD(:) = 0_INT32

    do iter_trgt = 1, num_integers, 1

      do iter_elem = 1, num_integers, 1
        if (iter_elem .ne. iter_trgt) then
          val_GCD(iter_trgt) = calc_GCD(val_GCD(iter_trgt), val_integer(iter_elem))
        end if
      end do

    end do

    ! STEP.03
    ! output the maximum value of the greatest common divisor
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') maxval(val_GCD(:), dim=1)

    ! STEP.END
    return

  end subroutine task_C

  pure function calc_GCD(target1, target2) result(gcd)

    ! arguments for this <function>
    integer(INT32), intent(in) :: target1, target2

    ! return value of this <function>
    integer(INT32) :: gcd

    ! variables for this <function>
    integer(INT32) :: buffer, buffer1, buffer2

    ! STEP.01
    ! handle the exception
    if (target1 .eq. 0_INT32) then; gcd = target2; return; end if
    if (target2 .eq. 0_INT32) then; gcd = target1; return; end if

    ! STEP.02
    ! store the values of the given integers
    buffer1 = target1
    buffer2 = target2

    ! STEP.03
    ! calculate the greatest common divisor
    do while (buffer2 .ne. 0_INT32)
      buffer  = mod(buffer1, buffer2)
      buffer1 = buffer2
      buffer2 = buffer
    end do

    gcd = buffer1

    ! STEP.END
    return

  end function calc_GCD

end module ABC125


program main

  ! <module>s to import
  use, non_intrinsic :: ABC125

  ! require all variables to be explicitly declared
  implicit none

  call task_C

end program main