program main
      implicit none
      integer(4) :: x, y, a, b, c
      integer(4), allocatable :: p(:), q(:), r(:)
      integer(4), allocatable :: arr(:)
      integer(4) :: i, red, grn, key, total

      read(*,*) x, y, a, b, c
      allocate( p(a) )
      allocate( q(b) )
      allocate( r(c) )
      read(*,*) p
      read(*,*) q 
      read(*,*) r

      call quicksort( p, 1, a )
      call quicksort( q, 1, b )
      allocate( arr( x+y+c ) )
      arr(1:x) = p(a-x+1:a)
      arr(x+1:x+y) = q(b-y+1:b)
      arr(x+y+1:x+y+c) = r

      call quicksort( arr, 1, x+y+c )
      total = sum( arr(c+1:x+y+c) ) 
      print *, total

  contains

  recursive subroutine quicksort( a, first, last )
    implicit none
    integer(4), intent(in) :: first, last
    integer(4), intent(inout) :: a(last)
    integer(4) :: i, j, x, t

    x = a((first+last)/2)
    i = first
    j = last
    do
      do while ( a(i) < x ) 
        i = i + 1
      end do
      do while ( a(j) > x )
        j = j - 1
      end do
      if( i >= j ) exit
      t = a(i)
      a(i) = a(j)
      a(j) = t
      i = i + 1
      j = j - 1
    end do
    if ( first < i-1 )  call quicksort( a, first, i-1 )
    if ( j+1 < last ) call quicksort( a, j+1, last )

  end subroutine quicksort
end program main 
