#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int n, L;
Int x[330000], t[330000];

int main(){
    Int ans = 0;
    cin >> n >> L;
    for(int i = 0;i < n;i++)cin >> x[i];
    for(int i = 0;i < n;i++){
        cin >> t[i];
        ans += t[i] / (2*L) * 2*L;
        t[i] %= 2*L;
        if(t[i] == 0){
            t[i] = 2*L;
            ans -= 2*L;
        }
    }
    string str = "";
    
    for(int i = 0;i < n;i++){
        bool flip_left = t[i] <= 2 * (L - x[i]);
        bool flip_right = t[i] <= 2 * x[i];
        if(i == n-1){
            if(!flip_left)ans += 2*L;
            continue;
        }
        if(!flip_left && !flip_right)ans += 2*L;
        if(flip_left && !flip_right)str += 'l';
        if(flip_left && flip_right)str += 'x';
        if(!flip_left && flip_right)str += 'r';
    }
    int last_l = -1, first_r = str.size();
    for(int i = 0;i < str.size();i++)if(str[i] == 'l')last_l = i;
    for(int i = (int)str.size() - 1;i >= 0;i--)if(str[i] == 'r')first_r = i;
    int l_stack = 0, r_stack = 0;
    for(int i = 0;i <= last_l;i++){
        if(str[i] == 'x')l_stack++;
        else if(l_stack > 0){
            l_stack--;
            ans += 2*L;
        }
        else{
            ans += 2*L;
        }
    }
    for(int i = (int)str.size() - 1;i >= first_r;i--){
        if(str[i] == 'x')r_stack++;
        else if(r_stack > 0){
            r_stack--;
            ans += 2*L;
        }
        else{
            ans += 2*L;
        }
    }
    int x_cnt = l_stack + r_stack;
    for(int i = last_l + 1;i < first_r;i++)x_cnt++;
    
    ans += x_cnt * 2 * L;
    ans -= x_cnt / 2 * 2 * L;
    ans += 2*L;
    cout << ans << endl;    
    return 0;
}