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,parameter::initdist=1000001 integer::N,i,mindist=initdist integer,allocatable::X(:) integer,allocatable::Y(:) read *,N allocate(X(N)) allocate(Y(N)) read *,X Y=qsort(X) do i=1,N-1 if(Y(i).eq.Y(i+1)) cycle mindist = MIN(mindist, Y(i+1)-Y(i)) if(mindist.eq.1) exit end do if(mindist.eq.initdist) mindist=0 print '(i0)', mindist end program main