#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
using namespace std;
const int N=300005;
int n,m,ans=1,cnt,ok;
int x[N],t[N],l[N],r[N];
int main(){
	scanf("%d%d",&n,&m); m*=2;
	For(i,1,n) scanf("%d",&x[i]);
	For(i,1,n) scanf("%d",&t[i]);
	For(i,1,n){
		int v=t[i]%m;
		ans+=t[i]/m+(t[i]%m!=0);
		l[i]=(0<v&&v<=2*x[i]);
		r[i]=(0<v&&v<=m-2*x[i]);
	}
	For(i,1,n-1)
		if (cnt&&r[i]){
			if (l[i]) ++ok;
			--ans; --cnt;
		}
		else if (l[i]) cnt++;
		else if (r[i]&&ok) ok--,cnt++;
	if (r[n]) ans--;
	printf("%lld",1ll*ans*m);
}