import java.util.ArrayList;
import java.util.Scanner;

/*
 * 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.
 */
/**
 *
 * @author gardlo1
 */
public class Lunch {

    static int[] kombinacie;
    static int[] cenyPolievky;
    static int[] cenyJedla;
    static int[] cenyDezert;
    static int[] cenyNapoje;

    public static void main(String[] args) {

        String line = "";
        Scanner sc = new Scanner(System.in);
        while (!(line = sc.nextLine().trim()).equals("0 0 0 0 0")) {
            kombinacie = naplnPole(line);
            cenyPolievky = naplnPole(sc.nextLine());
            cenyJedla = naplnPole(sc.nextLine());
            cenyDezert = naplnPole(sc.nextLine());
            cenyNapoje = naplnPole(sc.nextLine());
            sc.nextLine();
            zoradPole(cenyPolievky);
            zoradPole(cenyDezert);
            zoradPole(cenyJedla);
            zoradPole(cenyNapoje);
            System.out.println(vytvorKombinacie());
        }
    }

    private static int[] naplnPole(String riadok) {
        String[] cisla = riadok.split(" ");
        int[] pole = new int[cisla.length];
        for (int i = 0; i < cisla.length; i++) {
            pole[i] = Integer.parseInt(cisla[i]);
        }
        return pole;
    }

    private static long vytvorKombinacie() {
        //ArrayList<Integer> ceny = new ArrayList<>();
        int limit = kombinacie[0];
        int aktualnaCena = 0;
        long pocet = 0;
        for (int i = 0; i < cenyPolievky.length; i++) {
            int cena = cenyPolievky[i];
            if (cena >= limit) {
                 break;
            }
            for (int j = 0; j < cenyJedla.length; j++) {
                cena = cenyPolievky[i] + cenyJedla[j];
                if (cena >= limit) {
                    break;
                }
                for (int k = 0; k < cenyDezert.length; k++) {
                    cena = cenyPolievky[i] + cenyJedla[j] + cenyDezert[k];
                    if (cena >= limit) {
                        break;
                    }
                    for (int l = 0; l < cenyNapoje.length; l++) {
                        cena = cenyPolievky[i] + cenyJedla[j] + cenyDezert[k] + cenyNapoje[l];
                        if (cena <= limit) {
                            pocet++;
                        } else {
                            break;
                        }

                    }
                }
            }
            
        }

        return pocet;
    }

    private static void zoradPole(int[] pole) {
        boolean bolaVymena;

        do {
            bolaVymena = false;

            for (int i = 0; i < pole.length - 1; i++) {
                if (pole[i] > pole[i + 1]) {
                    int prvok = pole[i + 1];
                    pole[i + 1] = pole[i];
                    pole[i] = prvok;
                    bolaVymena = true;
                }
            }
        } while (bolaVymena);

    }
}