import java.util.*; import java.io.*; public class Main { static int[] families; static int[] sheets; static int[][] dp; //idx, 1, 2, 3 public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 3); families = new int[3]; for (int i = 0; i < 3; i++) { families[i] = Integer.parseInt(first[i]); } Arrays.sort(families); int n = Integer.parseInt(br.readLine()); sheets = new int[n + 1]; String[] line = br.readLine().split(" ", n); for (int i = 0; i < n; i++) { sheets[i + 1] = Integer.parseInt(line[i]); } Arrays.sort(sheets); dp = new int[n + 1][3 * 16 + 3 * 4 + 3 + 1]; for (int i = 0; i <= n; i++) { Arrays.fill(dp[i], -1); } System.out.print(dfw(n, 0)); } static int dfw(int idx, int value) { if (idx <= 0) { return 0; } if (dp[idx][value] != -1) { return dp[idx][value]; } int s = value / 16; int m = (value % 16) / 4; int l = value % 4; dp[idx][value] = dfw(idx - 1, value); if (sheets[idx] >= families[0]) { s = Math.min(s + 1, 3); } if (sheets[idx] >= families[1]) { m = Math.min(m + 1, 3); } if (sheets[idx] >= families[2]) { l = Math.min(l + 1, 3); } int next = s * 16 + m * 4 + l; if (s >= 3 && m >= 2 && l >= 1) { dp[idx][value] += (int)(Math.pow(2, idx - 1)); } else { dp[idx][value] += dfw(idx - 1, next); } return dp[idx][value]; } static class Bridge { int left; int right; public Bridge (String arg) { String[] arr = arg.split(" ", 2); left = Integer.parseInt(arr[0]) - 1; right = Integer.parseInt(arr[1]) - 1; } public int hashCode() { return left + right; } public boolean equals(Object o) { Bridge b = (Bridge)o; return b.left == left && b.right == right; } } static class UnionFindTree { int[] parents; HashMap> map = new HashMap<>(); HashSet nothing = new HashSet<>(); public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (parents[x] == x) { return x; } else { return parents[x] = find(parents[x]); } } public void unite(int x, int y) { int xx = find(x); int yy = find(y); if (xx == yy) { return; } int small = Math.min(xx, yy); int large = Math.max(xx, yy); parents[large] = small; } public void unite(Bridge b) { unite(b.left, b.right); } public HashSet uniteNext(int x, int y) { int xx = find(x); int yy = find(y); if (xx == yy) { return nothing; } int small = Math.min(xx, yy); int large = Math.max(xx, yy); parents[large] = small; if (small == 0) { return map.get(large); } else { map.get(small).addAll(map.get(large)); return nothing; } } public HashSet uniteNext(Bridge b) { return uniteNext(b.left, b.right); } public HashSet prepare() { for (int i = 0; i < parents.length; i++) { int x = find(i); if (!map.containsKey(x)) { map.put(x, new HashSet()); } map.get(x).add(i); } return map.get(0); } } }