<pre>import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Lunch {
	
	static int[] arra;
	static int[] arrb;
	static int[] arrc;
	static int[] arrd;
	
	static long total;
	
	public static void main(String[] args) {
		
		BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
		
		try {
			
			String line = bfr.readLine();
			while (line != null) {
				
				if (line.startsWith(&quot;0 0 0 0 0&quot;)) break;
				
				int l, a,b,c,d;
				l = Integer.parseInt(line.split(&quot; &quot;)[0]);
				
				a = Integer.parseInt(line.split(&quot; &quot;)[1]);
				b = Integer.parseInt(line.split(&quot; &quot;)[2]);
				c = Integer.parseInt(line.split(&quot; &quot;)[3]);
				d = Integer.parseInt(line.split(&quot; &quot;)[4]);
				
				arra = new int[a];
				arrb = new int[b];
				arrc = new int[c];
				arrd = new int[d];
				
				String[] split = bfr.readLine().split(&quot; &quot;); 
				for (int i=0; i&lt;a; i++) {
					arra[i] = Integer.parseInt(split[i]);
				}
				split = bfr.readLine().split(&quot; &quot;); 
				for (int i=0; i&lt;b; i++) {
					arrb[i] = Integer.parseInt(split[i]);
				}
				split = bfr.readLine().split(&quot; &quot;); 
				for (int i=0; i&lt;c; i++) {
					arrc[i] = Integer.parseInt(split[i]);
				}
				split = bfr.readLine().split(&quot; &quot;); 
				for (int i=0; i&lt;d; i++) {
					arrd[i] = Integer.parseInt(split[i]);
				}
				
				Arrays.sort(arra);
				Arrays.sort(arrb);
				Arrays.sort(arrc);
				Arrays.sort(arrd);
				/*
				System.out.println(Arrays.toString(arra));
				System.out.println(Arrays.toString(arrb));
				System.out.println(Arrays.toString(arrc));
				System.out.println(Arrays.toString(arrd));
				*/
				total = 0;
				
				check(l, 0, 0);
				
				
				System.out.println(total);
				
				bfr.readLine();
				line = bfr.readLine();
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	private static void check(long limit, long price, int level) {
		int[] arr = null;
		if (level == 0)	arr = arra;
		if (level == 1)	arr = arrb;
		if (level == 2)	arr = arrc;
		if (level == 3)	arr = arrd;
		
		for (int i=0; i&lt;arr.length; i++) {
			price += arr[i];
			if (price &lt;= limit) {
				if (level == 3) total++;
				else check(limit, price, level+1);
			}
			price -= arr[i];
		}
	}

}



/*

11 3 1 1 1
4 5 6
3
2
1

10 4 5 4 2
3 2 5 7
1 1 8 4 2
3 5 2 1
2 3

0 0 0 0 0

 */ 
</pre>
