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

const int N = 300010;

typedef long long LL;

set<int> A, B, C; int X[N];

int main() {
    int n, L; scanf("%d%d", &n, &L); LL res = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &X[i]);
    for (int i = 1; i <= n; i++) {
        int x = X[i], t; scanf("%d", &t), res += t / (2 * L) * (2 * L), t %= 2 * L;
        int t1 = x * 2 >= t, t2 = (L - x) * 2 >= t;
        if ((i == n && t2) || !t) { res -= 2 * L; continue; }
        if (t1 && t2) C.insert(x);
        else if (t1) A.insert(-x);
        else if (t2) B.insert(x);
    }
    res += (LL)(n + 1) * 2 * L;
    for (auto t : B) if (C.size() && *C.begin() < t) C.erase(C.begin()), res -= 2 * L;
    for (auto t : A) if (C.size() && *C.rbegin() > -t) C.erase(*C.rbegin()), res -= 2 * L;
    res -= (LL)(C.size() / 2) * 2 * L;
    printf("%lld\n", res);
}