program test03_3
 implicit none
 integer first, last
 integer N
 integer,allocatable :: A(:)
 integer i,j
 integer :: kekka=0

 read *, N
 allocate(A(N))
 read *,A

 first=1
 last=N

 call quicksort1(A,first,last)

 if (kekka==0) print '(A)', 'YES' 
 if (kekka==1) print '(A)', 'NO' 

contains
recursive subroutine quicksort1(a, first, last)
implicit none
integer::a(N)
integer::first,last

 double precision::x
 integer t
 integer::i,j

 x = a((first+last)/2)
 i = first
 j = last

  if ( a(i) == a(j) ) then
   kekka=1
  end if
do 
  do while (a(i) <= x)
   i=i+1
  if ( a(i) == a(i+2) .and. i /= N ) then
   kekka=1
   exit
  end if
  end do
  do while (x <= a(j))
   j=j-1
  if ( a(j) == a(j-2) .and. j /= 1 ) then
   kekka=1
   exit
  end if
  end do

  if (i >= j) exit
    t = a(i)
    if (a(i)==a(j)) kekka=1
    a(i) = a(j)
    a(j) = t
    i=i+1
    j=j-1
end do

 if (first < i-1) call quicksort1(a, first, i-1)
 if (j+1 < last)  call quicksort1(a, j+1, last)
end subroutine quicksort1

endprogram test03_3
