#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 3e5 + 10;

typedef long long ll;
typedef pair<int, int> pii;

int N;
ll ans = 1, L, A[MAX_N], T[MAX_N], must_reach;
pii type[MAX_N];
bool used[MAX_N];

int main() {
    scanf("%d%lld", &N, &L);
    for (int i = 1; i <= N; i++) scanf("%lld", &A[i]);
    for (int i = 1; i <= N; i++) {
        scanf("%lld", &T[i]);
        ans += T[i] / (2 * L) * 2;
        T[i] %= 2 * L;

        if (!T[i]) {
            type[i] = {-1, -1};
            must_reach = max(must_reach, A[i]);
        } else {
            type[i].first = T[i] > (L - A[i]) * 2;
            type[i].second = T[i] > A[i] * 2;
        }
    }

    for (int i = 1; i <= N; i++) {
        if (type[i].first < 0) used[i] = true;
        if (type[i] == make_pair(1, 1)) {
            ans += 2;
            must_reach = max(must_reach, A[i]);
            used[i] = true;
        }
    }
    
    stack<int> stk;

    for (int i = 1; i <= N; i++) {
        if (used[i]) continue;
        if (type[i] == make_pair(1, 0)) {
            stk.push(i);
        }
        if (type[i] == make_pair(0, 1) && !stk.empty()) {
            must_reach = max(must_reach, A[i]);
            used[stk.top()] = true;
            stk.pop();
            used[i] = true;
            ans += 2;
        }
    }

    while (!stk.empty()) stk.pop();

    for (int i = 1; i <= N; i++) {
        if (used[i]) continue;
        if (type[i] == make_pair(1, 0)) {
            stk.push(i);
        }
        if (type[i] == make_pair(0, 0) && !stk.empty()) {
            must_reach = max(must_reach, A[i]);
            used[stk.top()] = true;
            stk.pop();
            used[i] = true;
            ans += 2;
        }
    }

    while (!stk.empty()) stk.pop();

    for (int i = 1; i < N; i++) {
        if (used[i]) continue;
        if (type[i] == make_pair(0, 0)) {
            stk.push(i);
        }
        if (type[i] == make_pair(0, 1) && !stk.empty()) {
            must_reach = max(must_reach, A[i]);
            used[stk.top()] = true;
            stk.pop();
            used[i] = true;
            ans += 2;
        }
    }

    while (!stk.empty()) stk.pop();

    for (int i = 1; i < N; i++) {
        if (used[i]) continue;
        if (type[i] == make_pair(0, 0)) {
            if (stk.empty()) stk.push(i);
            else {
                must_reach = max(must_reach, A[i]);
                used[stk.top()] = true;
                stk.pop();
                used[i] = true;
                ans += 2;
            }
        }
    }

    while (!stk.empty()) stk.pop();

    if (!used[N] && type[N].first == 0) {
        for (int i = 1; i < N; i++) {
            if (!used[i] && type[i].second == 0) {
                used[i] = true;
                used[N] = true;
                ans += 2;
                break;
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        if (used[i]) continue;
        stk.push(i);
        ans++;
    }

    if (stk.empty()) ans++;
    else {
        if (type[stk.top()] == make_pair(1, 0)) ans += stk.size() + 1;
        else if (A[stk.top()] < must_reach) ans += stk.size() + 1;
        else ans += stk.size() - 1;
    }
    printf("%lld\n", ans * L);
}


Measured memory_bytes: 8652