#include <bits/stdc++.h>

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, l;
  cin >> n >> l;
  vector<int> x(n);
  vector<int> catch_left(n), catch_right(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  vector<long long> t(n);
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    ans += (t[i] + 2 * l - 1) / (2 * l);
  }
  for (int i = 0; i < n; i++) {
    if (t[i] % (2 * l) > 0 && t[i] % (2 * l) <= 2 * (l - x[i])) {
      catch_right[i] = 1;
    }
    if (t[i] % (2 * l) > 0 && t[i] % (2 * l) <= 2 * x[i]) {
      catch_left[i] = 1;
    }
  }
  if (catch_right[n - 1]) {
    ans--;
  }
  int cnt_left = 0;
  int any = 0;
  for (int i = 0; i + 1 < n; i++) {
    if (catch_left[i] && catch_right[i]) {
      if (cnt_left > 0) {
        ans--;
        cnt_left--;
      } else {
        any++;
      }
    } else if (catch_right[i]) {
      if (cnt_left > 0) {
        ans--;
        cnt_left--;
      } else if (any > 0) {
        ans--;
        any--;
      }
    } else if (catch_left[i]) {
      cnt_left++;
    }
  }
  ans -= any / 2;
  ans *= 2 * l;
  cout << ans << '\n';
  return 0;
}