program ABC088B
    implicit none
    integer(8)::N,i
    integer(8)::result=0
    integer(8),allocatable,dimension(:)::A

    read(5,*)N
    allocate(A(N))
    read(5,*)(A(i),i=1,N)

    A=iqsort(A)
    A=A(N:1:-1)
    do i=1,N
        if(mod(i,2)==1)then
            result=result+A(i)
        else
            result=result-A(i)
        end if
    end do

    print'(i0)',result
contains
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort
end program ABC088B