using System; using System.Collections.Generic; using System.Linq; class Program { static string ReadLine() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(ReadLine()); } static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); } static string[] ReadStrings() { return ReadLine().Split(); } static int Calc(int[] bcd, int n, int[] xs) { Array.Sort(bcd); Array.Sort(xs); var dp = new int[n + 1, 4]; dp[0, 0] = 1; for (int i = 0; i < xs.Length; i++) { // i 番目のレジャーシート for (int j = 0; j <= 3; j++) { dp[i + 1, j] += dp[i, j]; // i 番目を選択しない // i 番目を選択する if (j < 3 && bcd[j] <= xs[i]) { dp[i + 1, j + 1] += dp[i, j]; } else { dp[i + 1, j] += dp[i, j]; } } } return dp[n, 3]; } static void Main() { var bcd = ReadInts(); int n = ReadInt(); var xs = ReadInts(); var ans = Calc(bcd, n, xs); Console.WriteLine(ans); } }