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

/**
 *
 * @author korenciak4
 */

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

class lunch {
        
    public static ArrayList<Integer>[] meals;
    public static int[] counts;
    public static Scanner sc = new Scanner(System.in);
    public static int[] ceny2, ceny1;
    
    public static void vymen(){
        ceny1= ceny2;
        ceny2= new int[100001000];
    }
    
    public static void main(String[] args) {
        
        while (true){
            ceny1= new int[100001000];
            ceny2= new int[100001000];
            int pom;
            
            meals = new ArrayList[4];
            meals[0] =new ArrayList<Integer>();
            meals[1] =new ArrayList<Integer>();
            meals[2] =new ArrayList<Integer>();
            meals[3] =new ArrayList<Integer>();
            counts = new int[4];
            counts[0] =new Integer(0);
            counts[1] =new Integer(0);
            counts[2] =new Integer(0);
            counts[3] =new Integer(0);
            
            Integer[] idx = {new Integer(0), new Integer(0), new Integer(0), new Integer(0)};
            int L =sc.nextInt();                      
            for(int i=0; i<4; i++){
                counts[i] = sc.nextInt();
            }
            for(int i=0; i<4; i++){
                for(int j=counts[i]; j>0; j--){
                    meals[i].add( sc.nextInt());
                }
            }
            for(int i=0; i<4; i++){
                Collections.sort( meals[i]);
            }
            if ((L+counts[0]+counts[1]+counts[2]+counts[3]) <1) return;
        
            ceny1[0] = 1;
            for(int i=0; i<4; i++){
                for (int j = 0; j < counts[i]; j++) {
                    pom = meals[i].get(j);
                    for (int k = 0; k <= L; k++) {
                        if (ceny1[k]>0)
                            ceny2[pom + k] += ceny1[k];
                    }
                }
                /*for (int k = 0; k <= L; k++) {
                    System.out.print(ceny2[k]); 
                    System.out.print(" ");
                }
                System.out.println();*/
                vymen();
            }
            long a = 0L;
            for (int k = 0; k <= L; k++) {
                a += ceny1[k];
            }
            
            System.out.println(a);
        }
    }
    
}