#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 3e5 + 5;
int n;
long long l;
long long x[maxn], t[maxn];

bool read() {
  if (scanf("%d%lld", &n, &l) < 2) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &t[i]);
  }
  return true;
}

vector<long long> ls, rs;
vector<long long> bad, good;
vector<int> used;

void solve() {
  ls.clear();
  rs.clear();
  bad.clear();
  good.clear();
  long long res = 0;
  for (int i = 0; i < n; i++) {
    res += t[i] / (2 * l);
    t[i] %= 2 * l;
    if (!t[i]) {
      bad.push_back(x[i]);
      continue;
    }
    if (t[i] <= 2 * x[i]) {
      if (t[i] <= 2 * (l - x[i])) {
        good.push_back(x[i]);
      } else {
        rs.push_back(x[i]);
      }
    } else {
      if (t[i] <= 2 * (l - x[i])) {
        ls.push_back(x[i]);
      } else {
        bad.push_back(x[i]);
        res++;
      }
    }
  }
  long long mx = 0;
  used.clear();
  used.resize(sz(good), false);
  int pos = 0;
  bool found = false;
  for (int i = 0; i < sz(ls); i++) {
    mx = max(mx, ls[i]);
    if (pos < sz(good) && good[pos] < ls[i]) {
      used[pos] = true;
      pos++;
      found = true;
    } else {
      found = false;
    }
    res++;
  }
  pos = sz(good) - 1;
  if (!rs.empty()) {
    if (pos >= 0 && !used[pos] && good[pos] > rs.back()) {
      mx = max(mx, good[pos]);
      used[pos] = true;
      pos--;
    } else {
      mx = l;
    }
    for (int i = sz(rs) - 1; i >= 0; i--) {
      if (pos >= 0 && !used[pos] && good[pos] > rs[i]) {
        mx = max(mx, good[pos]);
        used[pos] = true;
        pos--;
      } else {
        mx = l;
      }
      res++;
    }
    int cnt = 0;
    for (int i = 0; i < sz(good); i++) {
      cnt += !used[i];
    }
    res += 1 + (cnt + 1) / 2;
    if (cnt & 1) {
      mx = l;
    }
  } else {
    int cnt = 0;
    for (int i = 0; i < sz(good); i++) {
      cnt += !used[i];
    }
    if (found || cnt) {
      res += 1 + cnt / 2;
      if (!good.empty()) {
        mx = max(mx, good.back());
      }
      if (!(cnt & 1)) {
        mx = l;
      }
    }
  }
  if (!bad.empty() && bad.back() > mx) {
    res++;
  }
  printf("%lld\n", res * 2 * l);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}
