program abc094b
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,a_max, ha1,ha2, d, ii
    integer(int32), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)
    a_max = maxval(a)
    ha1 = a_max/2
    ha2 = ha1 + mod(a_max,2)
    d = 1000000000
    ii = 0
    do i=1,n
        if (d <= abs(ha1-a(i)) .and. d <= abs(ha2-a(i))) cycle
        if (a_max <= a(i)) cycle
        d = min(abs(ha1-a(i)), abs(ha2-a(i)))
        ii = i
    end do

    print'(*(i0,1x))', a_max, a(ii)
end program abc094b