#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int x[300005];
int ans;
int p[300005];
int sum[300005],mx[300005];
int main(){
	int n,l;
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)scanf("%d",&x[i]);
	for(int i=1;i<=n;i++){
		int t;
		scanf("%d",&t);
		ans+=t/(2*l)*2;
		t%=(2*l);
		if(!t)p[i]=0;
		else if(t>max(2*x[i],2*(l-x[i]))){
			ans+=2;
			p[i]=0;
		}else
		if(t>2*x[i]){
			p[i]=1;
			ans+=1;
		}else
		if(t>2*(l-x[i])){
			p[i]=2;
			ans+=1;
		}else{
			p[i]=-1;
			ans+=1;
		}
		// printf("%d ",p[i]);
	}
	// puts("");
	// printf("%d\n",ans);
	for(int i=n;i>=1;i--)sum[i]=sum[i+1]+(!p[i]?0:(p[i]!=2?-1:1));
	memset(mx,-1,sizeof(mx));
	for(int i=n;i>=1;i--)mx[i]=max(mx[i+1],sum[i]);
	int res=1e9;
	// printf("%d\n",ans);
	for(int i=1,mn=0,s=0;i<=n+1;i++){
		int t=max(-mn+1,i<=n?max(-(sum[i]-mx[i]+s)+1,-(sum[i]+s)):-(sum[i]+s) );
		// printf("%d %d %d\n",t,t+(t+s+sum[i]),-(sum[i]-mx[i]+s)+1);
		res=min(res,t+(t+s+sum[i]));
		if(p[i]){
			if(p[i]!=1)s++;
			else s--;
		}
		mn=min(mn,s);
	}
	printf("%lld\n",1ll*l*(res+ans));
	return 0;
}