      MODULE qSortMod
      implicit none
      interface qSort
        module procedure :: i16qSort
      end interface
      contains
      
      pure recursive function i16qSort( a ) result( r )
          !ref
          !https://t.doujin-constant.net/
          !post/143374686394/fortranをより使いこなしたquick-sort
          !
          !left is smaller!
        implicit none
        integer(16),intent(in) :: a(:)
        integer(16) :: r( size(a) )
        !integer(16),allocatable :: r(:) !is OK
        integer(16) :: sample(3),len,i,j
        
        len = size(a)
        if( len>1 )then
          sample(1) = a(1)
          sample(2) = a(len/2)
          sample(3) = a(len)
          !select median
          do i = 1,2
            do j = 2,3
              if( sample(i)>sample(j) )then
                len = sample(i) !len is buffer
                sample(i) = sample(j)
                sample(j) = len
              end if
            end do
          end do
          
          r = [ qSort( pack( a(:),a(:)> sample(2) ) ), &
                       pack( a(:),a(:)==sample(2) )  , &
                qSort( pack( a(:),a(:)< sample(2) ) ) ]
        else
          r = a
        end if
      end function i16qSort
      
      END MODULE qSortMod


      PROGRAM redAndGreenApples
      use qSortMod
      IMPLICIT NONE
      integer(16) :: x,y,a,b,c,sz
      integer(16),allocatable :: p(:),q(:),r(:),ans(:)
      
      read*,x,y,a,b,c
      allocate( p(a),q(b),r(c) )
      read*,p(:)
      read*,q(:)
      read*,r(:)
      
      p = qSort(p)
      q = qSort(q)
      r = qSort(r)
      
      sz = min(c,x,y)
      
      allocate( ans(x+y+sz) )
      ans(1:x) = p(1:x)
      ans(x+1:x+y) = q(1:y)
      ans(x+y+1:x+y+sz) = r(1:sz)
      
      ans = qSort( ans )
      print*,sum( ans(1:x+y) )
      
      
      END PROGRAM