#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int N=300010;

int f[3010][3010][2][2];
int n,l,t[N],x[N],a[N],b[N];

int main(){
	scanf("%d%d",&n,&l); ll ans=2*l;
	for(int i=1;i<=n;i++) scanf("%d",&x[i]);
	for(int i=1;i<=n;i++){
		scanf("%d",&t[i]);
		ans+=1LL*((t[i]+2LL*l-1)/(2*l))*2*l;
		t[i]%=2*l;
		if(t[i]>0 && t[i]<=2LL*(l-x[i])) a[i]=1;
		if(t[i]>0 && t[i]<=2LL*x[i]) b[i]=1;
	}
	int cur=0,bt=0;
	for(int i=1;i<n;i++){
		if(a[i]){
			if(cur){
				if(b[i]) bt++;
				cur--; ans-=2*l;
			}
			else if(bt && !b[i]){
				bt--; cur++;
			}
			else if(b[i]) cur++;
		}
		else if(b[i]) cur++;
	}
	if(a[n]) ans-=2*l;
	printf("%lld\n",ans);
	return 0;
}