import java.io.*; import java.util.*; public class klaus_mb { public static void main(String[] args) throws IOException { try (Input in = new Input()) { // read the input int d = in.nextInt(); // left block int n0 = in.nextInt() + 1; int s0 = in.nextInt(); long s0Sq = (long) (s0) * s0; int[] y0 = in.nextIntArray(n0); Arrays.sort(y0); // mid block int n1 = in.nextInt() + 1; int s1 = in.nextInt(); long s1Sq = (long) (s1) * s1; int[] y1 = in.nextIntArray(n1); Arrays.sort(y1); // right block int n2 = in.nextInt() + 1; int s2 = in.nextInt(); long s2Sq = (long) (s2) * s2; int[] y2 = in.nextIntArray(n2); Arrays.sort(y2); // this stores answer + 1 to also track reachability long[][][] dp = new long[n0][n1][n2]; long answer = 1; dp[0][0][0] = 1; for (int i0 = 0; i0 < n0; ++i0) { for (int i1 = 0; i1 < n1; ++i1) { for (int i2 = 0; i2 < n2; ++i2) { long curr = dp[i0][i1][i2]; answer = Math.max(answer, curr); if (curr > 0) { // scan in 0 upwards int low0 = Math.max(y0[i0] + s0, s0 + s1 <= d ? -1 : y1[i1] + s0 + s1 - d); for (int j0 = i0 + 1; j0 < n0; ++j0) { if (y0[j0] >= low0) { dp[j0][i1][i2] = Math.max(dp[j0][i1][i2], curr + s0Sq); } } // scan in 1 upwards int low1 = Math.max(y1[i1] + s1, Math.max( s0 + s1 <= d ? -1 : y0[i0] + s0 + s1 - d, s2 + s1 <= d ? -1 : y2[i2] + s2 + s1 - d )); for (int j1 = i1 + 1; j1 < n1; ++j1) { if (y1[j1] >= low1) { dp[i0][j1][i2] = Math.max(dp[i0][j1][i2], curr + s1Sq); } } // scan in 2 upwards int low2 = Math.max(y2[i2] + s2, s2 + s1 <= d ? -1 : y1[i1] + s2 + s1 - d); for (int j2 = i2 + 1; j2 < n2; ++j2) { if (y2[j2] >= low2) { dp[i0][i1][j2] = Math.max(dp[i0][i1][j2], curr + s2Sq); } } } } } } System.out.println(answer - 1); } } private static class Input implements Closeable { private final BufferedReader in; private StringTokenizer st; Input() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(in.readLine()); } int nextInt() throws IOException { while (!st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return Integer.parseInt(st.nextToken()); } int[] nextIntArray(int n) throws IOException { int[] rv = new int[n]; rv[0] = -10000001; for (int i = 1; i < n; ++i) { rv[i] = nextInt(); } return rv; } public void close() throws IOException { in.close(); } } }