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(0:N+1),s(N)) read *,a(1:N) s = qsort(a(1:N)) a(0) = 0 a(N+1) = 0 do i=1,N if(a(i).ne.a(i-1).and.a(i).ne.a(i+1))then total = total + 1 end if end do print '(i0)', total end program main