import java.util.ArrayDeque; import java.util.Arrays; 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(System.in); 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.peekFirst().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) { 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_; } } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }