#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=3e5+10;
ll n,L,a[N],t[N],ans;
int main(){
	cin>>n>>L;
	for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++)scanf("%lld",&t[i]),ans+=t[i]/(2*L)*2*L,t[i]%=2*L;
	ans+=2*L;
	int cnt1=0,cnt2=0,cnt3=0,tag1=0,x,y;
	for (int i=1;i<=n;i++){
		x=2*a[i]>=t[i],y=2*(L-a[i])>=t[i];
		if (t[i]==0){x=y=0;continue;}
		if (x==0&&y==0){ans+=2*L;continue;};
		if (x==1&&y==1){
			cnt2++;
			if (cnt3)
				cnt3--,cnt2--,ans+=2*L,tag1=1;
		}
		if (x==0&&y==1){
			cnt1++;
			if (cnt2)
				cnt1--,cnt2--,ans+=2*L;
		}
		if (x==1&&y==0)cnt3++;
	}
	ans+=2*L*(cnt2/2);
	ans+=2*L*(cnt1+cnt3+(cnt2%2)*(!y));
	cout<<ans<<endl;
}