#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 300005;
const int MM = 1000000007;

int X[MX], T[MX];
pii D[MX];

int main()
{
	int N, L;
	scanf("%d%d", &N, &L);
	for(int i = 1; i <= N; i++) scanf("%d", X+i);
	for(int i = 1; i <= N; i++) scanf("%d", T+i);

	ll ans = 0;
	for(int i = 1; i <= N; i++){
		ans += T[i] / (2*L);
		T[i] %= (2*L);
	}

	for(int i = 1; i <= N; i++){
		pii c = pii(0, 0);
		if(T[i] <= (L-X[i])*2) c.first = 1;
		if(T[i] <= X[i]*2) c.second = 1;
		if(T[i] == 0) c = pii(0, 0);
		if(c == pii(0, 0) && T[i]) ans++;
		D[i] = c;
	}
	
	int mn = 1e9;
	int s = 0, e = N, m1, m2;
	while(s <= e){
		auto f = [&](int v){
			int cur = 0, ans = 0, rm = v;
			for(int j = 1; j <= N; j++){
				int f, s;
				tie(f, s) = D[j];
				if(cur == 0) cur++, ans++;
				if(f && s){
					if(rm) --rm, cur++, ans++;
					else cur--;
				}
				else if(f) cur--;
				else if(s) cur++, ans++;
			}
			return ans;
		};
		m1 = (s*2+e)/3;
		m2 = (s+e*2+1)/3;
		int v1 = f(m1), v2 = f(m2);
		mn = min({mn, v1, v2});
		if(v1 <= v2) e = m2-1;
		else s = m1+1;
	}
	printf("%lld\n", (ans+mn) * (2*L));
}
