import sys input = sys.stdin.readline N,S=map(int,input().split()) X=list(map(int,input().split())) W=list(map(int,input().split())) ind=N for i in range(N): if X[i]>S: ind=i break X=X[:ind]+[S]+X[ind:] W=W[:ind]+[0]+W[ind:] N+=1 DP=[[1<<60]*(N) for i in range(N)] DP2=[[1<<60]*(N) for i in range(N)] DP[ind][ind]=0 SUM=sum(W) Q=[(ind,ind,SUM,0)] WS=[0] for w in W: WS.append(WS[-1]+w) while Q: NQ=[] while Q: l,r,weight,com=Q.pop() if com==0: now=DP[l][r] if r+1now+dis*weight: DP[l][r+1]=now+dis*weight NQ.append((l,r+1,weight-minus,0)) if l-1>=0: dis=X[r]-X[l-1] minus=W[l-1] if DP2[l-1][r]>now+dis*weight: DP2[l-1][r]=now+dis*weight NQ.append((l-1,r,weight-minus,1)) else: now=DP2[l][r] if r+1now+dis*weight: DP[l][r+1]=now+dis*weight NQ.append((l,r+1,weight-minus,0)) if l-1>=0: dis=X[l]-X[l-1] minus=W[l-1] if DP2[l-1][r]>now+dis*weight: DP2[l-1][r]=now+dis*weight NQ.append((l-1,r,weight-minus,1)) Q=list(set(NQ)) ANS=DP[0][N-1] ANS2=DP2[0][N-1] print(min(ANS,ANS2))