#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
inline int getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register int x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
using int64=long long;
const int N=3e5+1,LIM=1e5;
int a[N],x[N],y[N];
int64 f[N];
using Line=std::pair<int64,int64>;
class SegmentTree {
	#define _left <<1
	#define _right <<1|1
	#define mid ((b+e)>>1)
	private:
		Line node[LIM<<2];
		int64 calc(const Line &l,const int &x) const {
			return l.first*x+l.second;
		}
	public:
		void build(const int &p,const int &b,const int &e) {
			node[p]={0,LLONG_MAX};
			if(b==e) return;
			build(p _left,b,mid);
			build(p _right,mid+1,e);
		}
		void insert(const int &p,const int &b,const int &e,Line l1) {
			if(node[p].second==LLONG_MAX) {
				node[p]=l1;
				return;
			}
			Line l2=node[p];
			if(calc(l2,b)>=calc(l1,b)) std::swap(l1,l2);
			if(calc(l1,e)>=calc(l2,e)) {
				node[p]=l2;
				return;
			}
			if(b==e) return;
			const double c=1.*(l2.second-l1.second)/(l1.first-l2.first);
			if(c<=mid) {
				node[p]=l1;
				insert(p _left,b,mid,l2);
			} else {
				node[p]=l2;
				insert(p _right,mid+1,e,l1);
			}
		}
		int64 query(const int &p,const int &b,const int &e,const int &x) const {
			int64 ret=calc(node[p],x);
			if(b==e) return ret;
			if(x<=mid) ret=std::min(ret,query(p _left,b,mid,x));
			if(x>mid) ret=std::min(ret,query(p _right,mid+1,e,x));
			return ret;
		}
	#undef _left
	#undef _right
	#undef mid
};
SegmentTree t;
int main() {
	const int n=getint();
	for(register int i=1;i<=n;i++) a[i]=getint();
	for(register int i=1;i<=n;i++) x[i]=getint();
	for(register int i=1;i<=n;i++) y[i]=getint();
	t.build(1,1,LIM);
	for(register int i=1;i<=n;i++) {
		t.insert(1,1,LIM,(Line){-2*x[i],(int64)x[i]*x[i]+(int64)y[i]*y[i]+f[i-1]});
		f[i]=t.query(1,1,LIM,a[i])+(int64)a[i]*a[i];
	}
	printf("%lld\n",f[n]);
	return 0;
}