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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N, L;
    cin >> N >> L;

    vi x(N + 1), t(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> x[i];
    }
    int ext = 0;
    for (int i = 1; i <= N; i++) {
        cin >> t[i];
        ext += t[i] / (2 * L) * 2;
        t[i] %= 2 * L;
        if (!t[i]) { t[i] = 2 * L; ext -= 2; }
    }

    auto ceil = [](ll n, ll d) { return (n + d - 1) / d; };
    vi left(N + 1), right(N + 1);
    for (int i = 1; i <= N; i++) {
        left[i] = t[i] <= 2 * x[i];
        right[i] = t[i] <= 2 * (L - x[i]);
    }

    int pr = 0, lo = 0, bt = 0;
    for (int i = 1; i <= N - 1; i++) {
        if (left[i] && right[i]) {
            if (lo) { pr++; lo--; }
            else bt++;
        } else if (right[i]) {
            if (bt) { pr++; bt--; }
        } else if (left[i]) {
            lo++;
        }
    }
    pr += bt / 2;
    if (right[N]) pr++;

    cout << (2 + ext + 2 * (N - pr)) * ll(L) << "\n";

    return 0;
}

