N = int(input()) *A, = map(int, input().split()) *X, = map(int, input().split()) *Y, = map(int, input().split()) X0 = sorted(set(A)) Z = {e: i for i, e in enumerate(X0)} N1 = len(X0) N0 = 2**(N1-1).bit_length() X0 = X0 + [10**6] * (N0 - N1) data = [None]*(2*N0+1) def f(line, x): p, q = line return p*x + q def _add_line(line, k, l, r): m = (l + r) // 2 if data[k] is None: data[k] = line return lx = X0[l] mx = X0[m] rx = X0[r-1] left = (f(line, lx) < f(data[k], lx)) mid = (f(line, mx) < f(data[k], mx)) right = (f(line, rx) < f(data[k], rx)) if left and right: data[k] = line return if not left and not right: return if mid: data[k], line = line, data[k] if left != mid: _add_line(line, 2*k+1, l, m) else: _add_line(line, 2*k+2, m, r) def add_line(line, a, b): L = a + N0; R = b + N0 a0 = a; b0 = b sz = 1 while L < R: if R & 1: R -= 1 b0 -= sz _add_line(line, R-1, b0, b0+sz) if L & 1: _add_line(line, L-1, a0, a0+sz) L += 1 a0 += sz L >>= 1; R >>= 1 sz <<= 1 def query(k): x = X0[k] def gen(k, x): k += N0-1 while k >= 0: if data[k]: yield f(data[k], x) k = (k - 1) // 2 return min(gen(k, x)) v = 0 j = -1 for i in range(N): x = X[i]; a = A[i]; y = Y[i] while j+1 < N1 and X0[j+1] < x: j += 1 add_line((-1, x+y+v), 0, j+1) add_line((1, -x+y+v), j+1, N0) v = query(Z[a]) print(v)