program B086
    implicit none
    integer(8) :: N
    integer(8), allocatable, dimension(:) :: a
    integer(8) :: i, j, max, Alice, Bob

    read(5,*) N
    allocate(a(N))
    read(5,*) (a(i), i = 1, N)
    Alice = 0
    Bob = 0


    do i = 1, N
        if (mod(i,2) /= 0) then
            max = maxval(a)
            Alice = Alice + max 

        else
            max = maxval(a)
            Bob = Bob + max

        end if

        j = 1
        do while (a(j) /= max)
            j = j + 1
        end do

        a(j) = 0

    end do

    write(6,*) Alice - Bob


end program B086
