#include <bits/stdc++.h>
using namespace std;
int read();
int n, L, res;
int x[300005], t[300005], del[300005];
int l[300005], r[300005];
int main() {
    n = read(), L = read(), res = n + 1;
    for (int i = 1; i <= n; ++i) x[i] = read();
    for (int i = 1; i <= n; ++i)
        res += (t[i] = read()) / (L << 1), t[i] %= L << 1;
    for (int i = 1; i <= n; ++i) {
        if (!t[i]) {
            --res, del[i] = 1;
            continue;
        }
        del[i] = !((l[i] = 2 * (L - x[i]) >= t[i]) | (r[i] = 2 * x[i] >= t[i]));
    }

    res -= l[n];
    int sum = 0, top = 0, pos = n;
    for (int i = 1; i < n; ++i) {
        if (del[i]) continue;
        if (!l[i]) {
            pos = i;
            break;
        }
        r[i] ? ++top : (top ? --top, --res : 0);
    }

    sum += top, top = 0;
    for (int i = n - 1; i >= pos; --i) {
        if (del[i]) continue;
        if (!r[i]) break;
        l[i] ? ++top : (top ? --top, --res : 0);
    }
    printf("%lld\n", 2ll * L * (res -= sum + top >> 1));
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}