import java.io.IOException; import java.io.InputStream; import java.util.ArrayDeque; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } int N; long[] A, X, Y; long[] D; void run() { Scanner sc = new Scanner(); N = sc.nextInt(); A = new long[N]; X = new long[N]; Y = new long[N]; D = new long[N]; Arrays.fill(D, Long.MAX_VALUE / 3); for (int i = 0; i < N; ++i) { A[i] = sc.nextLong(); } for (int i = 0; i < N; ++i) { X[i] = sc.nextLong(); } for (int i = 0; i < N; ++i) { Y[i] = sc.nextLong(); } // d[i]=min_{j<=i}(d[j-1]+cost[j,i]) ArrayDeque
dq = new ArrayDeque<>(); dq.add(new P(0, 0)); for (int i = 0; i < N; ++i) { // d[i]を求める while (dq.size() >= 2 && second(dq).i <= i) { dq.pollFirst(); } if (dq.size() > 0 && f(i, dq.peekLast().j) >= f(i, i)) { dq.pollLast(); } if (dq.isEmpty()) { dq.addLast(new P(i, i)); D[i] = f(i, i); continue; } D[i] = f(i, dq.peekFirst().j); if (i == 0) continue; while (true) { if (dq.size() == 0) { dq.addLast(new P(i, i)); break; } int ok = N; int ng = i - 1; while (ok - ng > 1) { int m = (ok + ng) / 2; if (f(m, i) <= f(m, dq.peekLast().j)) { ok = m; } else { ng = m; } } if (ok > dq.peekLast().i) { if (ok < N) dq.addLast(new P(ok, i)); break; } else { dq.pollLast(); } } } System.out.println(D[N - 1]); } P second(ArrayDeque
dq) { if (dq.size() < 2) throw new AssertionError(); P tmp = dq.pollFirst(); P ret = new P(dq.peekFirst().i, dq.peekFirst().j); dq.addFirst(tmp); return ret; } long cost(int from, int to) { long dx = Math.abs(X[from] - A[to]); long dy = Math.abs(Y[from]); return dx * dx * dx + dy * dy * dy; } long f(int i, int j) { if (j > 0 && D[j - 1] == -1) throw new AssertionError(); return (j > 0 ? D[j - 1] : 0) + cost(j, i); } class P { int i, j; public P(int i_, int j_) { i = i_; j = j_; } } class Scanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } private void skipUnprintable() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; } public boolean hasNext() { skipUnprintable(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } int nextInt() { return (int) nextLong(); } } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }