PROGRAM ATCODER

implicit none
integer(8) :: n,i,j,s,dif
integer(8),allocatable :: a(:), b(:), c(:)

read(*,*) n
allocate(a(n)) ; allocate(b(n)) ; allocate(c(n))

dif = 0
do i = 1, n
    read(*,*) a(i),b(i)
end do

c(:) = a(:) + b(:)

dif = -sum(b)

call hsort(n,c)

do i = 1, n, 2
    dif = dif + c(i)
end do

deallocate(a) ; deallocate(b) ; deallocate(c)

write(*,'(i0)') dif

END PROGRAM ATCODER


subroutine hsort(n, x)
  implicit none
  integer(8), intent(IN) :: n
  integer(8), intent(INOUT) :: x(n)
  ! local
  integer(8) :: k
  integer(8) :: tmp
  ! external subroutine
  external mkheap

  do k = n/2, 1, -1
     tmp = x(k)
     call mkheap(n, x, k, n, tmp)
  enddo

  do k = n, 2, -1
     tmp = x(k)
     x(k) = x(1)
     call mkheap(n, x, 1, k-1, tmp)
  end do

  return
end subroutine hsort

subroutine mkheap(n, x, root, leaf, val)
  implicit none
  integer(8), intent(IN)    :: n, root, leaf
  integer(8), intent(INOUT) :: x(1:n)
  integer(8), intent(IN)    :: val
  ! local
  integer(8) :: i, j

  i = root
  j = i * 2

  do
     if (j > leaf) exit

     if (j < leaf) then
        if (x(j) > x(j+1)) j = j + 1
     end if

     if (x(j) < val) then
        x(i) = x(j)
        i = j
        j = i * 2
     else
        j = leaf + 1
     endif
  end do

  x(i) = val

  return
end subroutine mkheap