program main
  integer :: N
  integer,allocatable :: C(:)
  integer :: i,j
  integer :: count
  integer :: nsave
  integer(8) :: out
  integer(8) :: itmp
  read(*,*) N
  allocate(C(N))
  do i = 1,N
     read(*,*) C(i)
  end do
  itmp = 0
  out=counter(C,1,itmp)+1
  write(*,'(i0)') out
  deallocate(C)
  stop
contains
  recursive function counter(C,Ns,in) result(ires)
    integer,intent(in) ::  C(:)
    integer(8) :: ires
    integer :: nsave
    integer,intent(in) :: Ns
    integer(8) :: in
    integer :: i,j
    ires = in
    do j = Ns,N-1
       nsave = C(j)
       do i = j+1,N
          if (C(i) == nsave) then
             if (C(i) /= C(i-1)) then
                ires = ires + 1
             elseif(i < N-1) then
                ires = counter(C,i+1,ires)
             end if
          end if
       end do
    end do
  end function counter
end program main
  