/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lunch;

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author korenciak4
 */
public class Lunch {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner nacitaj = new Scanner(System.in);
        int cena = 0, s = 0, m = 0, d = 0, b = 0;

        int[] sP = null;
        int[] sM = null;
        int[] sD = null;
        int[] sB = null;

        long rieseni = 0;

        while (nacitaj.hasNext()) {

            cena = nacitaj.nextInt();
            rieseni = 0;
            s = nacitaj.nextInt();
            m = nacitaj.nextInt();
            d = nacitaj.nextInt();
            b = nacitaj.nextInt();

            if (cena == 0 && s == 0 && m == 0 && d == 0 && b == 0) {
                return;
            }

            sP = new int[s];
            sM = new int[m];
            sD = new int[d];
            sB = new int[b];

            for (int i = 0; i < s; i++) {

                sP[i] = nacitaj.nextInt();
            }
            for (int i = 0; i < m; i++) {
                sM[i] = nacitaj.nextInt();
            }
            for (int i = 0; i < d; i++) {
                sD[i] = nacitaj.nextInt();
            }
            for (int i = 0; i < b; i++) {
                sB[i] = nacitaj.nextInt();
            }

            Arrays.sort(sB);
            Arrays.sort(sM);
            Arrays.sort(sD);
            Arrays.sort(sP);

            int maxP, maxM, maxD, maxB;
            int c = 0;

            maxP = Arrays.binarySearch(sP, 0, sP.length, cena - c + 1);
            maxP = maxP >= 0 ? maxP : Math.abs(maxP + 1);
            for (int i = 0; i < maxP; ++i) {
                c += sP[i];
                maxM = Arrays.binarySearch(sM, 0, sM.length, cena - c + 1);
                maxM = maxM >= 0 ? maxM : Math.abs(maxM + 1);
                for (int j = 0; j < maxM; j++) {
                    c += sM[j];
                    maxD = Arrays.binarySearch(sD, 0, sD.length, cena - c + 1);
                    maxD = maxD >= 0 ? maxD : Math.abs(maxD + 1);
                    for (int k = 0; k < maxD; k++) {
                        c += sD[k];
                        maxB = Arrays.binarySearch(sB, 0, sB.length, cena - c + 1);
                        maxB = maxB >= 0 ? maxB : Math.abs(maxB + 1);
                        rieseni += maxB;
                        c -= sD[k];
                    }
                    c -= sM[j];
                }
                c -= sP[i];
            }

            System.out.println(rieseni);
        }
    }
}