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

import java.io.*;

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

    public static BufferedReader in;

    public static void main(String args[]) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while (!(line = in.readLine()).equals("0 0 0 0 0")) {
            String[] parts = line.split("\\s");
            long max = Long.parseLong(parts[0]);
            int sizeSoup = Integer.parseInt(parts[1]);
            int sizeDish = Integer.parseInt(parts[2]);
            int sizeDess = Integer.parseInt(parts[3]);
            int sizeAle = Integer.parseInt(parts[4]);
            line = in.readLine();
            parts = line.split("\\s");
            long[] soup = new long[sizeSoup];
            for (int i = 0; i< sizeSoup; i++)
                soup[i] = Long.parseLong(parts[i]);
            
            line = in.readLine();
            parts = line.split("\\s");
            long[] dish = new long[sizeDish];
            for (int i = 0; i< sizeDish; i++)
                dish[i] = Long.parseLong(parts[i]);
            
            line = in.readLine();
            parts = line.split("\\s");
            long[] dess = new long[sizeDess];
            for (int i = 0; i< sizeDess; i++)
                dess[i] = Long.parseLong(parts[i]);
            
            line = in.readLine();
            parts = line.split("\\s");
            long[] ale = new long[sizeAle];
            for (int i = 0; i< sizeAle; i++)
                ale[i] = Long.parseLong(parts[i]);
            System.out.println(lunch(soup,dish,dess,ale,max));
        }
    }

    public static long lunch(long[] soup, long[] dish, long[] dess, long[] ale, long max) {
        long comb = 0;
        for (int i = 0; i < soup.length; i++) {
            for (int j = 0; j < dish.length; j++) {
                for (int k = 0; k < dess.length; k++) {
                    for (int l = 0; l < ale.length; l++) {
                        if (soup[i] + dish[j] + dess[k] + ale[l] <= max) {
                            comb++;
                        }
                    }
                }
            }
        }
        return comb;
    }

}