import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	long l = read.to!long;
	long[] xs = readln.chomp.split.to!(long[]);
	long[] ts = readln.chomp.split.to!(long[]);
	
	long[] as = ts.map!(t => (t + 2 * (2 * l - 1)) / (2 * l)).array; // 次の同じ向きに乗る場合の滞在時間(半往復=１)
	
	debug writeln("l = ", l, ", xs = ", xs, ", ts = ", ts);
	debug writeln("as = ", as);
	
	long c1 = 0, c2 = 0; // c1: 左行きのときアドバンテージ、c2: 右行きのときアドバンテージ
	
	foreach(i; 0 .. n){
		long r = ts[i] % (2 * l);
		if(r > 0){
			if(r <= 2 * xs[i]) c1 += 1;
			if(r <= 2 * (l - xs[i])) c2 += 1;
			}
		debug writeln("i = ", i, ",  c1 = ", c1, ", c2 = " , c2);
		}
	
	long sum = as.reduce!"a + b"();
	debug writeln("sum = ", sum);
	
	sum += 2;
	
	sum -= min(c1, c2);
	debug writeln("sum = ", sum);
	
	if(sum % 2) sum += 1;
	debug writeln("sum = ", sum);
	
	(sum * l).writeln;
	
	}