/*
 * 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.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import javafx.collections.transformation.SortedList;

/**
 *
 * @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);

            for (int i = 0; i < sP.length; i++) {
                for (int j = 0; j < sM.length; j++) {
                    for (int k = 0; k < sD.length; k++) {
                        for (int l = 0; l < sB.length; l++) {
                            if ((sP[i] + sM[j] + sD[k] + sB[l]) <= cena) {
                                rieseni++;
                            } else {
                                break;
                            }
                        }
                        if (sP[i] + sM[j] + sD[k] > cena) {
                            break;
                        }
                    }
                    if (sP[i] + sM[j] > cena) {
                        break;
                    }
                }
                if (sP[i] > cena) {
                    break;
                }
            }
            System.out.println(rieseni);
        }
    }
}