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;
        for (int i = 0; i < cenyPolievky.length; i++) {
            for (int j = 0; j < cenyJedla.length; j++) {
                for (int k = 0; k < cenyDezert.length; k++) {
                    for (int l = 0; l < cenyNapoje.length; l++) {
                        int cena = cenyPolievky[i] + cenyJedla[j] +
                                   cenyDezert[k] + cenyNapoje[l];
                        
                        ceny.add(new Integer(cena));
                    }
                }
            }
        }
        
        
        long i = 0;
        for (int q : ceny) {
            if(q <= limit){
                i++;
            }
        }
        return i;
    } 
    
    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);
        
    }
}