import sys readline=sys.stdin.readline class AVLTree_dict: def __init__(self): self.root=None self.parent=[] self.key=[] self.value=[] self.left=[] self.right=[] self.bias=[] self.size=[] def Make_Node(self,parent,key,value): retu=len(self.parent) self.parent.append(parent) self.key.append(key) self.value.append(value) self.left.append(None) self.right.append(None) self.bias.append(0) self.size.append(1) return retu def Rotate_Left(self,node): node_right=self.right[node] self.size[node_right]-self.size[node] self.size[node]-=1 if node_right0 if self.bias[node]==1: self.bias[self.right[node]]=-1 self.bias[self.left[node]]=0 elif self.bias[node]==-1: self.bias[self.right[node]]=0 self.bias[self.left[node]]=1 else: self.bias[self.right[node]]=0 self.bias[self.left[node]]=0 self.bias[node]=0 def __getitem__(self,key): v=self.root while v!=None: if keykey: if retu==None or retu[0]>self.key[v]: retu=(self.key[v],self.value[v]) v=self.left[v] else: v=self.right[v] return retu def Bisect_Left(self,key): retu=None v=self.root while v!=None: if self.key[v]1: mid=(ok+ng)//2 if self.avl: a0,b0=self.lines.Find_Kth_Element(mid) a1,b1=self.lines.Find_Kth_Element(mid+1) else: a0=self.lines_A[mid] b0=self.lines_B[a0] a1=self.lines_A[mid+1] b1=self.lines_B[a1] if a0*x+b0>a1*x+b1: ok=mid else: ng=mid if self.avl: a,b=self.lines.Find_Kth_Element(ok+1) else: a=self.lines_A[ok+1] b=self.lines_B[a] return a*x+b def __getitem__(self,a): if self.avl: return self.lines[a] else: if a in self.lines_A: return self.lines_B[a] else: return None def __setitem__(self,a,b): self.add_line(a,b) N=int(readline()) A=list(map(int,readline().split())) X=list(map(int,readline().split())) Y=list(map(int,readline().split())) dp=Convex_Hull_Trick(avl=True) cost=0 for i in range(N): dp.add_line(-2*X[i],cost+X[i]**2+Y[i]**2) cost=dp(A[i])+A[i]**2 ans=cost print(ans)