#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,l,res,t[maxn],le[maxn],ri[maxn],x[maxn],del[maxn]; 
signed main(){
	n=read();l=read(),res=n+1;
	for(int i=1;i<=n;i++)x[i]=read();
	for(int i=1;i<=n;i++){
		res+=(t[i]=read())/(l<<1);t[i]%=(l<<1);
	}
	for(int i=1;i<=n;i++){
		if(!t[i]){
			res--;del[i]=1;
			continue;
		}
		del[i]=!((le[i]=2*(l-x[i])>=t[i])|(ri[i]=2*x[i]>=t[i]));
	}
	res-=le[n];
	int sum=0,top=0,pos=n;
	for(int i=1;i<n;i++){
		if(del[i])continue;
		if(!le[i]){
			pos=i;break;
		}
		ri[i]?++top:(top?--top,--res:0);
	}
	sum+=top;top=0;
	for(int i=n-1;i>=pos;i--){
		if(del[i])continue;
		if(!ri[i])break;
		le[i]?++top:(top?--top,--res:0);
	}
	printf("%lld\n",2ll*l*(res-=sum+top>>1));
	return 0;
}
