//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 300010
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int l[N],r[N],t[N],x[N],n,L; bool vis[N];
int main()
{
	n=read(),L=read(); ll ans=n;
	for(int i=1;i<=n;i++)	x[i]=read();
	for(int i=1;i<=n;i++)	t[i]=read();
	for(int i=1;i<=n;i++)
	{
		ans+=t[i]/(2*L),t[i]%=(2*L);
		if(!t[i])	ans--,vis[i]=1;
		else
		{
			r[i]=t[i]<=2*(L-x[i]),l[i]=t[i]<=2*x[i];
			if(!l[i]&&!r[i])	t[i]=0,vis[i]=1; 
		}
	}
	int pos=1;
	while(pos<n && !(l[pos]&&!r[pos]))	pos++;
	int tot=0,top=0;
	for(int i=1;i<pos;i++)	if(!vis[i])
	{
		if(!l[i]){if(top)	top--,ans--;}
		else	top++;
	}
	tot+=top,top=0;
	for(int i=n-1;i>=pos;i--) if(!vis[i])
	{
		if(!r[i]){if(top)	top--,ans--;}
		else	top++; 
	}
	tot+=top; ans-=tot>>1;
	if(!r[n])	ans++;
	printf("%lld\n",ans*2*L);
	return 0;
}