#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=3e5+20;

int n,L;
int x[maxn],t[maxn];
int a[maxn],b[maxn],vis[maxn];
ll ans;

inline void init()
{
	n=read();L=read();
	REP(i,1,n)x[i]=read();
	REP(i,1,n)
	{
		t[i]=read();
		ans+=t[i]/(L<<1);
		t[i]%=L<<1;
		if(!t[i]){ vis[i]=1; continue;}
		if(t[i]<=2*(L-x[i]))a[i]=1;//右进左出
		if(t[i]<=2*x[i])b[i]=1;//左进右出
		if(a[i]+b[i]==0){ vis[i]=1; ans++; continue;}
	}
	vector<int>t01;
	queue<int>t11;
	
	REP(i,1,n-1)
	{
		if(a[i] || b[i])
		{
			if(b[i])
			{
				if(a[i])t11.push(i);
				else t01.push_back(i);
			}else
			{
				if(!t01.empty())vis[t01.back()]=1,vis[i]=1,t01.pop_back(),ans++;
				else if(!t11.empty())vis[t11.front()]=1,vis[i]=1,t11.pop(),ans++;
				//else;
			}
		}
	}
	t01.clear(); while(!t11.empty())t11.pop();
	REP(i,1,n-1)if(!vis[i])
	{
		if(b[i])
		{
			if(a[i])
			{
			 	if(!t01.empty())vis[t01.back()]=1,vis[i]=1,t01.pop_back(),ans++;
			 	else t11.push(i);
			}else t01.push_back(i);
		}//else if(!t11.empty())vis[t11.front()]=1,vis[i]=1,t11.pop(),ans++;
	}
	while(SZ(t11)>=2)
	{
		int x=t11.front(); t11.pop();
		int y=t11.front(); t11.pop();
		vis[x]=1; vis[y]=1; ans++;
	}
	if(vis[n]==0 && a[n])
	{
		REP(i,1,n-1)if(vis[i]==0 && b[i])
		{
			vis[i]=vis[n]=1;
			ans++;
			break;
		}
	}
	REP(i,1,n)
	{
		if(!vis[i])
		{
			ans++;
		}
	}
	ans+=(vis[n] || !a[n]);
	printf("%lld\n",ans*(L<<1));
}

int main()
{
	init();
	return 0;
}
