program rec
	implicit none
    integer :: n, i,j,c1,c2
    integer(8),allocatable :: a(:)
    integer(8) :: l1, l2, s1, s2
    logical :: status
    read(*,*) n
    allocate(a(n))
    read(*,*) a
    call heapsort(a)
	
    s1 = 0
    s2 = 0
    c1 = n
    do i = n - 1, 1, -1
    	l1 = a(i)
        l2 = a(i+1)
    	if(l1 == l2) then
        	s1 = l1
        	c1 = i
        	exit
        else
        	l1 = a(i)
            l2 = a(i-1)
        end if
    end do
    do i = c1 - 1, 1, -1
    	l1 = a(i)
        l2 = a(i+1)
    	if(l1 == l2) then
        	s2 = l1
        	c1 = i
        	exit
        else
        	l1 = a(i)
            l2 = a(i-1)
        end if
    end do
    	
    write(*,*) s1*s2

	stop
contains
	subroutine heapsort(array)
    implicit none
    integer(8):: array(:)
    integer ::i,k,j,l
    integer(8) :: t

    n=size(array)

    if (n==1) then
       return
    end if
    
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k == 1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       end do
       array(i)=t
    end do
    return
  end subroutine heapsort

end program rec

