/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long llong;
#define int llong
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
	int n,l;
	cin>>n>>l;
	vi x(n),t(n);
	rep(i,n)cin>>x[i];
	rep(i,n)cin>>t[i];
	
	int out=0,h=0,H=0;
	stack<vi>st;
	rep(i,n){
		out+=t[i]/(2*l)*2;
		t[i]%=2*l;
		int a=t[i]>2*(l-x[i]),b=t[i]>2*x[i];
		
		if(!t[i]){
			h=i==n-1;
			continue;
		}
		out++;
      if(a&b){
        h=i==n-1;
        out++;
        continue;
      }
		if(st.empty())st.push({a,b});
		else{
			vi pr=st.top();
          if(i==n-1&&!a&&b){
            st.push({a,b});
            break;
          }
             st.pop();
			if(pr[0]+pr[1]+a+b&&pr[1]==0&&a==0)h=i==n-1;
			else{
				st.push(pr);
				st.push({a,b});
			}
		}
	}
	out+=st.size();
	int cnt=0,co0=0;
	while(!st.empty()){
		vi now=st.top();
		st.pop();
		cnt++;
		if(cnt==1&&now[0])h=true;
      if(cnt==1&&now[1])H=true;
		if(now[0]+now[1]==0)co0++;
	}
  out-=(co0+H)/2*2;
  if(!H&&co0%2==0||H&&co0%2)h=true;
	if(h)out+=2;
	cout<<out*l<<endl;
}















Measured memory_bytes: 21520