Yui loves shopping. She lives in Yamaboshi City and there is a train service in the city. The city can be modelled as a very long number line. Yui's house is at coordinate 0.

There are N shopping centres in the city, located at coordinates x_{1}, x_{2}, ..., x_{N} respectively. There are N + 2 train stations, one located at coordinate 0, one located at coordinate L, and one located at each shopping centre.

At time 0, the train departs from position 0 to the positive direction. The train travels at a constant speed of 1 unit per second. At time L, the train will reach the last station, the station at coordinate L. The train immediately moves in the opposite direction at the same speed. At time 2L, the train will reach the station at coordinate 0 and it immediately moves in the opposite direction again. The process repeats indefinitely.

When the train arrives at a station where Yui is located, Yui can board or leave the train immediately. At time 0, Yui is at the station at coordinate 0.

Yui wants to go shopping in all N shopping centres, in any order, and return home after she finishes her shopping. She needs to shop for t_{i} seconds in the shopping centre at coordinate x_{i}. She must finish her shopping in one shopping centre before moving to the next shopping centre. Yui can immediately start shopping when she reaches a station with a shopping centre and she can immediately board the train when she finishes shopping.

Yui wants to spend the minimum amount of time to finish her shopping. Can you help her determine the minimum number of seconds required to complete her shopping?

Constraints

* 1 \leq N \leq 300000
* 1 \leq L \leq 10^{9}
* 0 < x_{1} < x_{2} < ... < x_{N} < L
* 1 \leq t_{i} \leq 10^{9}
* All values in the input are integers.

Input

Input is given from Standard Input in the following format:


N L
x_{1} x_{2} ... x_{N}
t_{1} t_{2} ... t_{N}


Output

Print the minimum time (in seconds) required for Yui to finish shopping at all N shopping centres and return home.

Examples

Input

2 10
5 8
10 4


Output

40


Input

2 10
5 8
10 5


Output

60


Input

5 100
10 19 28 47 68
200 200 200 200 200


Output

1200


Input

8 1000000000
2018 123456 1719128 1929183 9129198 10100101 77777777 120182018
99999999 1000000000 1000000000 11291341 1 200 1 123812831


Output

14000000000
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#define MN 300000
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,L,x[MN+5],t[MN+5],pre[MN+5],suf[MN+5];
priority_queue<int> q;
bool Solve(int s)
{
    while(q.size()) q.pop();
    memset(pre,0,sizeof(pre));memset(suf,0,sizeof(suf));
    int P=0,S=0;
    for(int i=1;i<=n;++i)
    {
        int a=(t[i]-1)/(2*L),b=(t[i]-1)%(2*L)+1;s-=a;
        int end1=2*(L-x[i])>=b?2:1;
        int end2=2*x[i]>=b?1:2;
        if(end1==end2)
        {
            if(end1==1) ++P,--pre[i];
            else ++suf[i];
        }
        else
        {
            if(end1==1) ++P,--pre[i],++suf[i];
            else ++P,--pre[i],q.push(i);
        }
    }
    for(int i=0;i<=n;++i)
    {
        P+=pre[i];S+=suf[i];
        while((P&&P+S>s-1)||S>s)
        {
            if(q.empty()||q.top()<=i) return false;
            int x=q.top();q.pop();//cout<<"Get"<<x<<endl;
            --P;++pre[x];++suf[x];
        }
    }
    return true;
}
int main()
{
    n=read();L=read();
    for(int i=1;i<=n;++i) x[i]=read();
    for(int i=1;i<=n;++i) t[i]=read();
    int l=1,r=1e9,mid,res;
    while(l<=r)
    {
        mid=l+r>>1;
        if(Solve(mid)) res=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%lld\n",1LL*res*L*2);
    return 0;
}