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 self.right[node_right]!=None: self.size[node]-=self.size[self.right[node_right]] if self.bias[node_right]==-1: self.bias[node_right]=0 self.bias[node]=0 else: #assert node_right.bias==0 self.bias[node_right]=1 self.bias[node]=-1 self.right[node]=self.left[node_right] self.left[node_right]=node return node_right def Rotate_Right(self,node): node_left=self.left[node] self.size[node_left]=self.size[node] self.size[node]-=1 if self.left[node_left]!=None: self.size[node]-=self.size[self.left[node_left]] if self.bias[node_left]==1: self.bias[node_left]=0 self.bias[node]=0 else: #assert node_left.bias==0 self.bias[node_left]=-1 self.bias[node_left]=-1 self.bias[node]=1 self.left[node]=self.right[node_left] self.right[node_left]=node return node_left def Rotate_Left_Right(self,node): node_left=self.left[node] node_left_right=self.right[node_left] #assert node.bias==2 #assert node_left.bias==-1 #assert node_left_right.bias in (-1,0,1) self.size[node_left_right]=self.size[node] self.size[node]-=self.size[node_left] if self.right[node_left_right]!=None: self.size[node]+=self.size[self.right[node_left_right]] self.size[node_left]-=1 if self.right[node_left_right]!=None: self.size[node_left]-=self.size[self.right[node_left_right]] self.right[node_left]=self.left[node_left_right] self.left[node_left_right]=node_left self.left[node]=self.right[node_left_right] self.right[node_left_right]=node self.Update_Bias_Double(node_left_right) return node_left_right def Rotate_Right_Left(self,node): node_right=self.right[node] node_right_left=self.left[node_right] #assert node.bias==-2 #assert node_right.bias==1 #assert node_right_left.bias in (-1,0,1) self.size[node_right_left]=self.size[node] self.size[node]-=self.size[node_right] if self.left[node_right_left]!=None: self.size[node]+=self.size[self.left[node_right_left]] self.size[node_right]-=1 if self.left[node_right_left]!=None: self.size[node_right]-=self.size[self.left[node_right_left]] self.left[node_right]=self.right[node_right_left] self.right[node_right_left]=node_right self.right[node]=self.left[node_right_left] self.left[node_right_left]=node self.Update_Bias_Double(node_right_left) return node_right_left def Update_Bias_Double(self,node): #assert node.right.bias*node.left.bias==-2 #assert node.right.bias>0 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)