#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

typedef unsigned long long lu;
typedef long long li;
const int mod = 1e9 + 7;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

int Inv(int x) { return Pow(x, mod - 2); }
template <class T> inline void Max(T &x, T y) { if (y > x) x = y; }
template <class T> inline void Min(T &x, T y) { if (y < x) x = y; }

// ----------------------------------------

const int maxn = 2e6;  // sdflsdkfj
const int inf = 1e9;

int n, L;
int x[maxn], t[maxn];
li cost0;

int v1[maxn + 1], v2[maxn + 1];
int pre[maxn + 2];
int suf[maxn + 2];
int min_pre[maxn + 2], max_suf[maxn + 2];

int Solve(char *s, int len) {
  // s[len] = '\0';
  // puts(s);
  if (s[len - 1] != '(') --len;
  for (int i = 0; i < len; ++i) {
    if (s[i] == '(') {
      v1[i] = v2[i] = 1;
    } else if (s[i] == ')') {
      v1[i] = v2[i] = -1;
    } else {
      v1[i] = 1;
      v2[i] = -1;
    }
  }

  pre[0] = 0;
  for (int i = 0; i < len; ++i) {
    pre[i + 1] = pre[i] + v1[i];
  }
  suf[len] = 0;
  for (int i = len - 1; i >= 0; --i) {
    suf[i] = suf[i + 1] + v2[i];
  }
  min_pre[0] = 0;
  for (int i = 1; i <= len; ++i) {
    min_pre[i] = min(min_pre[i - 1], pre[i]);
  }
  max_suf[len] = 0;
  for (int i = len - 1; i >= 0; --i) {
    max_suf[i] = max(max_suf[i + 1], suf[i]);
  }

  int ans = inf;
  for (int mid = 0; mid <= len; ++mid) {
    int suml = pre[mid];
    int sumr = suf[mid];
    int minp = min(min_pre[mid], suml + sumr - max_suf[mid]);
    int addl = -minp, addr = suml + sumr + addl;
    // printf("%d %d\n", addl, addr);
    // if (mid < len) printf("move %c\n", s[mid]);
    Min(ans, addl + addr + len);
  }
  return ans + 2;
}

int main(void) {
  scanf("%d%d", &n, &L);
  for (int i = 0; i < n; ++i) {
    scanf("%d", x + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", t + i);
    int rep = (t[i] - 1) / (2 * L);
    t[i] -= rep * (2 * L);
    cost0 += rep * 2;
  }

  static char str[maxn + 1];
  int slen = 0;
  for (int i = 0; i < n; ++i) {
    // if (t[i] == 0) {
    //   str[slen++] = '(';
    //   str[slen++] = ')';
    // }
    bool fastR = (t[i] <= (L - x[i]) * 2);
    bool fastL = (t[i] <= x[i] * 2);
    if (fastL && fastR) {
      str[slen++] = '?';
    } else if (fastL) {
      str[slen++] = '(';
    } else if (fastR) {
      str[slen++] = ')';
    } else {
      str[slen++] = '(';
      str[slen++] = ')';
    }
  }
  if (slen == 0) {
    li ans = cost0 + 2;
    printf("%lld\n", ans * L);
    return 0;
  }
  li ans = cost0 + Solve(str, slen);
  printf("%lld\n", ans * L);
  return 0;
}


Measured memory_bytes: 34944