#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    int64_t L, X[300000], T[300000];
    cin >> N >> L;
    for(int i=0; i<N; i++) cin >> X[i];
    for(int i=0; i<N; i++) cin >> T[i];

    int64_t C = N;
    bitset<300000> l, r;
    for(int i=0; i<N; i++){
        int64_t c = (T[i]-1) / (2*L);
        C += c;
        T[i] -= c * 2 * L;
        r[i] = (T[i] <= 2*(L-X[i]));
        l[i] = (T[i] <= 2*X[i]);
    }
    if(r[N-1] == 0) C++;

    int cl = 0, clr = 0;
    for(int i=0; i<N-1; i++){
        if(l[i] && r[i]){
            if(cl > 0){
                C--;
                cl--;
            }else{
                clr++;
            }
        }else if(l[i]){
            cl++;
        }else if(r[i]){
            if(cl > 0){
                C--;
                cl--;
            }else if(clr > 0){
                C--;
                clr--;
            }
        }
    }
    C -= clr/2;

    int64_t ans = C * 2 * L;
    cout << ans << endl;
    return 0;
}