#include #include #include #include typedef long long LL; const int N = 300300,LIM = 100000; const LL inf = 1e18; inline int getint() { int r = 0,s = 0;char c = getchar();for(;!isdigit(c);c = getchar()) s |= c == '-'; for(;isdigit(c);c = getchar()) r = (((r << 2) + r) << 1) + (c ^ '0');return s ? -r : r; } struct line { LL k,b; line(){k = 0,b = inf;} line(LL k_,LL b_){k = k_;b = b_;} inline LL v(LL x){return k * x + b;} inline friend double X(const line &a,const line &b){return 1.0 * (a.b - b.b) / (b.k - a.k);} }; struct SegmentTree { line val[(LIM + 10) << 2]; inline void insert(int k,int l,int r,line w) { // printf("i %d %d %d %lld %lld\n",k,l,r,w.k,w.b); if(val[k].b == inf) {val[k] = w;return;} line w2 = val[k]; if(w.v(l) <= w2.v(l)) std::swap(w,w2); if(w.v(r) >= w2.v(r)) {val[k] = w2;return;} if(l == r) return; double x = X(w,w2); int mid = (l + r) >> 1; if(x <= 1.0 * mid) {val[k] = w;insert(k << 1,l,mid,w2);} else {val[k] = w2;insert(k << 1 | 1,mid + 1,r,w);} } inline LL query(int k,int l,int r,int p) { LL re = val[k].v(p); if(l == r) return re; int mid = (l + r) >> 1; re = std::min(re,p <= mid ? query(k << 1,l,mid,p) : query(k << 1 | 1,mid + 1,r,p)); return re; } }SGT; int a[N],x[N],y[N]; LL f[N]; int n; int main() { int n = getint(); for(int i = 1;i <= n;i++) a[i] = getint(); for(int i = 1;i <= n;i++) x[i] = getint(); for(int i = 1;i <= n;i++) y[i] = getint(); for(int i = 1;i <= n;i++) { SGT.insert(1,0,LIM,line(-2LL * x[i],1LL * x[i] * x[i] + 1LL * y[i] * y[i] + f[i - 1])); f[i] = 1LL * a[i] * a[i] + SGT.query(1,0,LIM,a[i]); } printf("%lld\n",f[n]); return 0; }