program nikkei2019
  implicit none
  integer n, i
  integer(8) ans
  integer(8), dimension(:,:), allocatable :: a

  read *, n
  allocate(a(2, n))
  read *, a
  ans = -sum(a(2,:))
  a(1,:) = a(1,:) + a(2,:)
  a(1,:) = qs(a(1,:))
  do i = 1, n
     if (mod(i, 2) /= 0) then
        ans = ans + a(1, i)
     end if
  end do
  print '(i0)', ans
contains
  recursive function qs(a) result(r)
    integer(8), dimension(:), intent(in) :: a
    integer(8), dimension(:), allocatable :: q, r
    integer(8) p

    if (size(a) < 2) then
       r = a
    else
       p = a(1)
       q = a(2:)
       r = [qs(pack(q, q > p)), p, qs(pack(q, q <= p))]
    end if
  end function qs
end program nikkei2019
