#include<cstdio>
using namespace std;
#define N 300500
int st[N],v[N],s[N],n,l;
long long as;
int main()
{
	scanf("%d%d",&n,&l);as=l*2;
	for(int i=1;i<=n;i++)scanf("%d",&s[i]);
	for(int i=1;i<=n;i++)scanf("%d",&v[i]);
	for(int i=1;i<=n;i++)
	{
		as+=(1ll*v[i]+l*2-1)/(l*2)*l*2;
		v[i]=(v[i]-1)%(l*2)+1;
		if(v[i]<=s[i]*2)st[i]++;
		if(v[i]<=(l-s[i])*2)st[i]+=2;
	}
	int l1=0,l2=0;
	for(int i=1;i<n;i++)
	if((st[i]&2)&&l1)l1--,as-=l*2,l2+=st[i]&1;
	else if((st[i]&2)&&l2)l1++,l2--,l2+=st[i]&1;
	else l1+=st[i]&1;
	if((st[n]&2))as-=l*2;
	printf("%lld\n",as);
}//