program probB
  implicit none
  integer n
  integer i,j,k,alice,bob
  integer,allocatable :: a(:),a_tmp(:)
  

  read(*,*) n
  allocate(a(n),a_tmp(n))
  read(*,*) a(1:n)

  a_tmp=a
  call quicksort(a_tmp,1,n)

  do i=1,n
     a(i)=a_tmp(n+1-i)
  end do

  alice=0
  bob=0

  do i=n,1,-1
     if(mod(i,2)==1) then
        alice=alice+a(i)
     else
        bob=bob+a(i)
     end if
  end do
  
  write(*,*) alice-bob
  
   
end program probB


recursive subroutine quicksort(a, first, last)
  implicit none
  integer a(*)
  integer first, last
  integer i, j
  integer x, t

  x = a( (first+last) / 2 )
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i);  a(i) = a(j);  a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i - 1) call quicksort(a, first, i - 1)
  if (j + 1 < last)  call quicksort(a, j + 1, last)
end subroutine quicksort