#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=300000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,L,x[N],t[N];
bool l[N],r[N];

int main()
{
    n=read();L=read();
    int ans=0;
    rep(i,1,n) x[i]=read();
    rep(i,1,n)
    {
        t[i]=read();
        if (t[i]%(L<<1))
        {
            int tmp=t[i]/(L<<1);
            ans+=(tmp+1);t[i]%=(L<<1);
            if (t[i]<=2*x[i]) l[i]=1;
            if (t[i]<=2*(L-x[i])) r[i]=1;
        }
        else ans+=t[i]/(L<<1);
    }
    int lcnt=0,cnt=0;
    rep(i,1,n-1)
    {
        if ((lcnt) && (r[i]))
        {
            lcnt--;ans--;
            if (l[i]) cnt++;
        }
        else if ((!l[i]) && (r[i]))
        {
            if (cnt) {cnt--;lcnt++;}
        }
        else if (l[i]) lcnt++;
    }
    if (!r[n]) ans++;
    printf("%lld\n",1ll*(L<<1)*ans);
    return 0;
}