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 heapsort(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 heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  double precision,intent(inout) :: array(1:n)
  
  integer ::i,k,j,l
  double precision :: t
  
  if(n <= 0)then
     write(6,*)"Error, at heapsort"; stop
  end if
  if(n == 1)return

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        end if
     end if
     i=l
     j=l+l
     do while(j <= k)
        if(j <= k)then
           if(array(j)  >= array(j+1))then
               j=j+1
           end if
        endif
        if (t >= array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort