implicit none

integer :: n
integer, allocatable :: a(:)
integer :: nd, i
integer :: iswp, icomb
logical :: flg_swp

read *, n
allocate(a(n))
read *, (a(i), i=1,n)

! Sort (comb11)
icomb = n
flg_swp = .false.
do while (icomb > 1 .or. flg_swp)
   icomb = (icomb * 10) / 13
   if (icomb < 1) then
      icomb = 1
   else if (icomb == 9 .or. icomb == 10) then 
      icomb = 11
   endif
   flg_swp = .false.
   do i = 1, n-icomb
      if (a(i) > a(i+icomb)) then
         iswp = a(i) 
         a(i) = a(i+icomb)
         a(i+icomb) = iswp
         flg_swp = .true.
      endif
   enddo
enddo

nd = 0
do i = 1, n
   if (mod(i,2) == 1) then
      nd = nd + a(n-i+1)
   else
      nd = nd - a(n-i+1)
   endif
enddo

write(6,'(i0)') nd

end