recursive function qsort(x) result(y) integer,intent(in) ::x(:) integer,allocatable::y(:) integer::pivot,total total = size(x) if (total <=1) then y = x else pivot = x(total/2) y = [qsort(pack(x, x .lt. pivot)), & pack(x, x .eq. pivot), & qsort(pack(x, x .gt. pivot))] endif end function qsort program main interface recursive function qsort(x) result(y) integer,intent(in) ::x(:) integer,allocatable::y(:) end function qsort end interface integer::N,total=0 integer,allocatable::s(:),a(:) read *,N allocate(a(N),s(0:N+1)) read *,a(1:N) s(1:N) = qsort(a) s(0) = 0 s(N+1) = 0 do i=1,N if(s(i).ne.s(i-1).and.s(i).ne.s(i+1))then total = total + 1 end if end do print '(i0)', total end program main