stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<set>

using namespace std;



const int MAXN=100005 ;

int n , E, T , dis[MAXN] ;

long long dp[MAXN] ;



multiset<long long> st;

multiset<long long>::iterator it ;



long long calc_1(int j){

	return dp[j]-2*dis[j+1]-dis[j] ;

}



long long calc_2(int j){

	return dp[j]-dis[j] ;

}



int main(){

	scanf("%d%d%d",&n,&E,&T) ;

	memset(dp,0x3f,sizeof(dp)) ;

	for(int i=1;i<=n;++i) scanf("%d",&dis[i]) ;

	dp[0]=0 ;

	int last=0 ; //第一个满足边界的

	st.insert(calc_2(0)) ;

	long long minn=(1ll<<60)-1 ;

	for(int i=1;i<=n;++i){

		while(last<i && 2*(dis[i]-dis[last+1])>=T){

			long long tmp=calc_2(last) ;

			it=st.find(tmp) , st.erase(it) ;

			minn=min(minn,calc_1(last)) , ++last ;

		}

		dp[i]=minn+(long long)3*dis[i] ;

		if(!st.empty()) dp[i]=min(dp[i],(*st.begin())+T+dis[i]) ;

		st.insert(calc_2(i)) ;

	}

	cout << dp[n]+E-dis[n] << '\n' ;

	return 0 ;

}

// Faster C++ solution for the same problem (measured speedup: 1.8049169437578032x):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <queue>

using namespace std;



int n, e, t;

int x[101010];

long long f[101010];



long long calc(int a, int b)

{

	return max(f[b - 1] + t, f[b - 1] + 2 * x[a] - 2 * x[b]);

}



priority_queue<long long> q;



int main()

{

	scanf("%d%d%d", &n, &e, &t);

	for(int i = 1; i <= n; ++i)

		scanf("%d", &x[i]);

	f[1] = t;

	int now = 0;

	for(int i = 2; i <= n; ++i)

	{

		f[i] = f[i - 1] + t;

		int l = 1;

		int r = i - 1, mid, key = i;

		while(l <= r)

		{

			mid = l + r;

			mid>>=1;

			if(t + 2 * x[mid] - 2 * x[i] >= 0)

			{

				r = mid - 1;

				key = mid;

			}

			else

				l = mid + 1;

		}

		f[i] = min(f[i], max(f[key - 1] + 2 * x[i] - 2 * x[key], f[key - 1] + t));

		if(key > 1)

		{

			while(now < key - 1)

			{

				++now;

				q.push(2 * x[now] - f[now - 1]);

			}

			f[i] = min(f[i], 2 * x[i] - q.top());

		}

	}

	

//	printf("%d\n", f[n] + e);

	cout<<f[n] + e<<endl;



	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;



long long f[100010],c[100010],d[100010];

int x[100010];

int n,e,t,T;



inline void add1(int x,long long o)

{

	while(x<=n)

	{

		c[x]=min(c[x],o);

		x+=x&-x;

	}

}



inline long long ask1(int x)

{

	long long nowans=0x3f3f3f3f3f3f3f3fll;

	while(x)

	{

		nowans=min(nowans,c[x]);

		x-=x&-x;

	}

	return nowans;

}



inline void add2(int x,long long o)

{

	while(x)

	{

		d[x]=min(d[x],o);

		x-=x&-x;

	}

}



inline long long ask2(int x)

{

	long long nowans=0x3f3f3f3f3f3f3f3fll;

	while(x<=n)

	{

		nowans=min(nowans,d[x]);

		x+=x&-x;

	}

	return nowans;

}



int main()

{

	scanf("%d%d%d",&n,&e,&t);

	T=t;

	if(t%2)T++;

	for(int i=1;i<=n;i++)

		scanf("%d",&x[i]);

	memset(f,0x3f,sizeof(f));

	memset(c,0x3f,sizeof(c));

	memset(d,0x3f,sizeof(d));

	f[0]=0;

	for(int i=1;i<=n;i++)

	{

		f[i]=min(f[i],f[i-1]+x[i]-x[i-1]+t);

		int now=upper_bound(x+1,x+1+i,x[i]-T/2)-x;

		if(x[i]-T/2>=x[1])

		{

			now--;

			long long nowans=ask1(now);

			f[i]=min(f[i],3ll*x[i]+nowans);

		}

		if(x[i]-T/2<x[1])now=0;

		now++;

		long long nowans=ask2(now);

		f[i]=min(f[i],x[i]+nowans);

		/*for(int j=i+1;j<=n;j++)

		{

			if((x[j]-x[i])*2>=t)f[j]=min(f[j],f[i-1]+3ll*(x[j]-x[i])+x[i]-x[i-1]);

			else f[j]=min(f[j],f[i-1]+t-2*(x[j]-x[i])+3ll*(x[j]-x[i])+x[i]-x[i-1]);

		}*/

		add1(i,-3ll*x[i]+f[i-1]+x[i]-x[i-1]);

		add2(i,0ll+t-x[i]+x[i]+f[i-1]-x[i-1]);

	}

	cout<<f[n]+e-x[n];

}

// Faster C++ solution for the same problem (measured speedup: 3.4016832881849246x):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <queue>

using namespace std;



int n, e, t;

int x[101010];

long long f[101010];



long long calc(int a, int b)

{

	return max(f[b - 1] + t, f[b - 1] + 2 * x[a] - 2 * x[b]);

}



priority_queue<long long> q;



int main()

{

	scanf("%d%d%d", &n, &e, &t);

	for(int i = 1; i <= n; ++i)

		scanf("%d", &x[i]);

	f[1] = t;

	int now = 0;

	for(int i = 2; i <= n; ++i)

	{

		f[i] = f[i - 1] + t;

		int l = 1;

		int r = i - 1, mid, key = i;

		while(l <= r)

		{

			mid = l + r;

			mid>>=1;

			if(t + 2 * x[mid] - 2 * x[i] >= 0)

			{

				r = mid - 1;

				key = mid;

			}

			else

				l = mid + 1;

		}

		f[i] = min(f[i], max(f[key - 1] + 2 * x[i] - 2 * x[key], f[key - 1] + t));

		if(key > 1)

		{

			while(now < key - 1)

			{

				++now;

				q.push(2 * x[now] - f[now - 1]);

			}

			f[i] = min(f[i], 2 * x[i] - q.top());

		}

	}

	

//	printf("%d\n", f[n] + e);

	cout<<f[n] + e<<endl;



	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define N 111111

#define M 444444

#define LL long long

using namespace std;

int n,i,k,j,a[N];LL f[N],V1[M],V2[M],E,T;

void ins(int k,int l,int r,int x,LL z1,LL z2){

	if(l==r){V1[k]=z1;V2[k]=z2;return;}

	int md=l+r>>1;

	if(x<=md)ins(k<<1,l,md,x,z1,z2);else ins(k<<1|1,md+1,r,x,z1,z2);

	V1[k]=min(V1[k<<1],V1[k<<1|1]);

	V2[k]=min(V2[k<<1],V2[k<<1|1]);

}

LL qu1(int k,int l,int r,int x,int y){

	if(x>y)return 1e18;

	if(x<=l&&r<=y)return V1[k];

	int md=l+r>>1;

	if(y<=md)return qu1(k<<1,l,md,x,y);

	if(x>md)return qu1(k<<1|1,md+1,r,x,y);

	return min(qu1(k<<1,l,md,x,y),qu1(k<<1|1,md+1,r,x,y));

}

LL qu2(int k,int l,int r,int x,int y){

	if(x>y)return 1e18;

	if(x<=l&&r<=y)return V2[k];

	int md=l+r>>1;

	if(y<=md)return qu2(k<<1,l,md,x,y);

	if(x>md)return qu2(k<<1|1,md+1,r,x,y);

	return min(qu2(k<<1,l,md,x,y),qu2(k<<1|1,md+1,r,x,y));

}

int main(){

	for(i=0;i<M;i++)V1[i]=V2[i]=1e18;

	scanf("%d%lld%lld",&n,&E,&T);

	for(i=1;i<=n;i++)scanf("%lld",&a[i]);

	for(i=0,k=0;i<=n;i++){

		f[i]=1e18;

		for(;(a[i]-a[k+1])*2>T&&k<i;k++);

		//f[i]=f[k]+max(a[i]-a[k+1]+a[i]-a[k+1],T)+a[i]-a[k];

		//j<=k a[i]-a[j+1*2>T

		//f[i]=qu2(1,0,0,k)

	//	printf("%d %d\n",(a[i]-a[k+1])*2,T);

		if(i==0)f[i]=0;else 

		f[i]=min(qu1(1,0,n,k,i-1)+T+a[i],qu2(1,0,n,0,k-1)+1ll*a[i]*3);

		//printf("%lld %lld\n",qu1(1,0,n,k,i-1)+T+a[i],qu2(1,0,n,0,k-1)+1ll*a[i]*3);

		//printf("%d %d %lld\n",i,k,f[i]);

	//	printf("%lld %lld %d\n",qu1(1,0,n,k,i-1),qu2(1,0,n,0,k-1),T+a[i]);

		//puts("-----------------------");

			//f[i]=min(f[i],f[j]+a[i]-a[j]+max((a[i]-a[j+1])*2,T));

		

		ins(1,0,n,i,f[i]-a[i],f[i]-a[i]-a[i+1]*2);

	}

	printf("%lld\n",f[n]+E-a[n]);

}

// Faster C++ solution for the same problem (measured speedup: 8.519119754649516x):
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <queue>

using namespace std;



int n, e, t;

int x[101010];

long long f[101010];



long long calc(int a, int b)

{

	return max(f[b - 1] + t, f[b - 1] + 2 * x[a] - 2 * x[b]);

}



priority_queue<long long> q;



int main()

{

	scanf("%d%d%d", &n, &e, &t);

	for(int i = 1; i <= n; ++i)

		scanf("%d", &x[i]);

	f[1] = t;

	int now = 0;

	for(int i = 2; i <= n; ++i)

	{

		f[i] = f[i - 1] + t;

		int l = 1;

		int r = i - 1, mid, key = i;

		while(l <= r)

		{

			mid = l + r;

			mid>>=1;

			if(t + 2 * x[mid] - 2 * x[i] >= 0)

			{

				r = mid - 1;

				key = mid;

			}

			else

				l = mid + 1;

		}

		f[i] = min(f[i], max(f[key - 1] + 2 * x[i] - 2 * x[key], f[key - 1] + t));

		if(key > 1)

		{

			while(now < key - 1)

			{

				++now;

				q.push(2 * x[now] - f[now - 1]);

			}

			f[i] = min(f[i], 2 * x[i] - q.top());

		}

	}

	

//	printf("%d\n", f[n] + e);

	cout<<f[n] + e<<endl;



	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<set>

using namespace std;



const int MAXN=100005 ;

int n , E, T , dis[MAXN] ;

long long dp[MAXN] ;



multiset<long long> st;

multiset<long long>::iterator it ;



long long calc_1(int j){

	return dp[j]-2*dis[j+1]-dis[j] ;

}



long long calc_2(int j){

	return dp[j]-dis[j] ;

}



int main(){

	scanf("%d%d%d",&n,&E,&T) ;

	memset(dp,0x3f,sizeof(dp)) ;

	for(int i=1;i<=n;++i) scanf("%d",&dis[i]) ;

	dp[0]=0 ;

	int last=0 ; //第一个满足边界的

	st.insert(calc_2(0)) ;

	long long minn=(1ll<<60)-1 ;

	for(int i=1;i<=n;++i){

		while(last<i && 2*(dis[i]-dis[last+1])>=T){

			long long tmp=calc_2(last) ;

			it=st.find(tmp) , st.erase(it) ;

			minn=min(minn,calc_1(last)) , ++last ;

		}

		dp[i]=minn+(long long)3*dis[i] ;

		if(!st.empty()) dp[i]=min(dp[i],(*st.begin())+T+dis[i]) ;

		st.insert(calc_2(i)) ;

	}

	cout << dp[n]+E-dis[n] << '\n' ;

	return 0 ;

}

// Faster C++ solution for the same problem (measured speedup: 1.8056377283336724x):
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

typedef long double DD;

const int inf = 1e9;

const int mo= 1e9+7;

const int N = 101010;

int n;

LL T, E, f[N], p[N];



struct sta{

	LL f,d;

	sta(){}

	sta(LL x, LL y){

		f = x;

		d = y;

	}

	friend bool operator <(sta a, sta b){

		if(a.f == b.f)

			return a.d<b.d;

		else 

			return a.f < b.f;

	}

};

set<sta> s1,s2;



int main(){

	scanf("%d%lld%lld",&n, &E, &T);

	for(int i = 1; i <= n; i++)

		scanf("%lld", p + i);

	sort(p + 1, p + n + 1);

	s1.insert(sta(T, p[1]));

	for(int i = 1; i <= n; i++){

		while(!s1.empty() && (p[i] - (*s1.begin()).d) * 2 > T){

			sta t = *s1.begin();

			s1.erase(s1.begin());

			s2.insert( sta(t.f - T - t.d * 2, t.d) );

		}

		f[i]=1ll << 62;

		if(!s2.empty())

			f[i]=(*s2.begin()).f + p[i] * 3;

		if(!s1.empty())

			f[i] = min(f[i], (*s1.begin()).f + p[i]);

		s1.insert(sta(f[i] - p[i] + T, p[i + 1]));

	}

//	for(int i = 1; i<= n; i++)

//		printf("%lld\n", f[i]);

	printf("%lld\n", f[n] + abs(E - p[n]));

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;



long long f[100010],c[100010],d[100010];

int x[100010];

int n,e,t,T;



inline void add1(int x,long long o)

{

	while(x<=n)

	{

		c[x]=min(c[x],o);

		x+=x&-x;

	}

}



inline long long ask1(int x)

{

	long long nowans=0x3f3f3f3f3f3f3f3fll;

	while(x)

	{

		nowans=min(nowans,c[x]);

		x-=x&-x;

	}

	return nowans;

}



inline void add2(int x,long long o)

{

	while(x)

	{

		d[x]=min(d[x],o);

		x-=x&-x;

	}

}



inline long long ask2(int x)

{

	long long nowans=0x3f3f3f3f3f3f3f3fll;

	while(x<=n)

	{

		nowans=min(nowans,d[x]);

		x+=x&-x;

	}

	return nowans;

}



int main()

{

	scanf("%d%d%d",&n,&e,&t);

	T=t;

	if(t%2)T++;

	for(int i=1;i<=n;i++)

		scanf("%d",&x[i]);

	memset(f,0x3f,sizeof(f));

	memset(c,0x3f,sizeof(c));

	memset(d,0x3f,sizeof(d));

	f[0]=0;

	for(int i=1;i<=n;i++)

	{

		f[i]=min(f[i],f[i-1]+x[i]-x[i-1]+t);

		int now=upper_bound(x+1,x+1+i,x[i]-T/2)-x;

		if(x[i]-T/2>=x[1])

		{

			now--;

			long long nowans=ask1(now);

			f[i]=min(f[i],3ll*x[i]+nowans);

		}

		if(x[i]-T/2<x[1])now=0;

		now++;

		long long nowans=ask2(now);

		f[i]=min(f[i],x[i]+nowans);

		/*for(int j=i+1;j<=n;j++)

		{

			if((x[j]-x[i])*2>=t)f[j]=min(f[j],f[i-1]+3ll*(x[j]-x[i])+x[i]-x[i-1]);

			else f[j]=min(f[j],f[i-1]+t-2*(x[j]-x[i])+3ll*(x[j]-x[i])+x[i]-x[i-1]);

		}*/

		add1(i,-3ll*x[i]+f[i-1]+x[i]-x[i-1]);

		add2(i,0ll+t-x[i]+x[i]+f[i-1]-x[i-1]);

	}

	cout<<f[n]+e-x[n];

}

// Faster C++ solution for the same problem (measured speedup: 3.4030417334333865x):
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

typedef long double DD;

const int inf = 1e9;

const int mo= 1e9+7;

const int N = 101010;

int n;

LL T, E, f[N], p[N];



struct sta{

	LL f,d;

	sta(){}

	sta(LL x, LL y){

		f = x;

		d = y;

	}

	friend bool operator <(sta a, sta b){

		if(a.f == b.f)

			return a.d<b.d;

		else 

			return a.f < b.f;

	}

};

set<sta> s1,s2;



int main(){

	scanf("%d%lld%lld",&n, &E, &T);

	for(int i = 1; i <= n; i++)

		scanf("%lld", p + i);

	sort(p + 1, p + n + 1);

	s1.insert(sta(T, p[1]));

	for(int i = 1; i <= n; i++){

		while(!s1.empty() && (p[i] - (*s1.begin()).d) * 2 > T){

			sta t = *s1.begin();

			s1.erase(s1.begin());

			s2.insert( sta(t.f - T - t.d * 2, t.d) );

		}

		f[i]=1ll << 62;

		if(!s2.empty())

			f[i]=(*s2.begin()).f + p[i] * 3;

		if(!s1.empty())

			f[i] = min(f[i], (*s1.begin()).f + p[i]);

		s1.insert(sta(f[i] - p[i] + T, p[i + 1]));

	}

//	for(int i = 1; i<= n; i++)

//		printf("%lld\n", f[i]);

	printf("%lld\n", f[n] + abs(E - p[n]));

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define N 111111

#define M 444444

#define LL long long

using namespace std;

int n,i,k,j,a[N];LL f[N],V1[M],V2[M],E,T;

void ins(int k,int l,int r,int x,LL z1,LL z2){

	if(l==r){V1[k]=z1;V2[k]=z2;return;}

	int md=l+r>>1;

	if(x<=md)ins(k<<1,l,md,x,z1,z2);else ins(k<<1|1,md+1,r,x,z1,z2);

	V1[k]=min(V1[k<<1],V1[k<<1|1]);

	V2[k]=min(V2[k<<1],V2[k<<1|1]);

}

LL qu1(int k,int l,int r,int x,int y){

	if(x>y)return 1e18;

	if(x<=l&&r<=y)return V1[k];

	int md=l+r>>1;

	if(y<=md)return qu1(k<<1,l,md,x,y);

	if(x>md)return qu1(k<<1|1,md+1,r,x,y);

	return min(qu1(k<<1,l,md,x,y),qu1(k<<1|1,md+1,r,x,y));

}

LL qu2(int k,int l,int r,int x,int y){

	if(x>y)return 1e18;

	if(x<=l&&r<=y)return V2[k];

	int md=l+r>>1;

	if(y<=md)return qu2(k<<1,l,md,x,y);

	if(x>md)return qu2(k<<1|1,md+1,r,x,y);

	return min(qu2(k<<1,l,md,x,y),qu2(k<<1|1,md+1,r,x,y));

}

int main(){

	for(i=0;i<M;i++)V1[i]=V2[i]=1e18;

	scanf("%d%lld%lld",&n,&E,&T);

	for(i=1;i<=n;i++)scanf("%lld",&a[i]);

	for(i=0,k=0;i<=n;i++){

		f[i]=1e18;

		for(;(a[i]-a[k+1])*2>T&&k<i;k++);

		//f[i]=f[k]+max(a[i]-a[k+1]+a[i]-a[k+1],T)+a[i]-a[k];

		//j<=k a[i]-a[j+1*2>T

		//f[i]=qu2(1,0,0,k)

	//	printf("%d %d\n",(a[i]-a[k+1])*2,T);

		if(i==0)f[i]=0;else 

		f[i]=min(qu1(1,0,n,k,i-1)+T+a[i],qu2(1,0,n,0,k-1)+1ll*a[i]*3);

		//printf("%lld %lld\n",qu1(1,0,n,k,i-1)+T+a[i],qu2(1,0,n,0,k-1)+1ll*a[i]*3);

		//printf("%d %d %lld\n",i,k,f[i]);

	//	printf("%lld %lld %d\n",qu1(1,0,n,k,i-1),qu2(1,0,n,0,k-1),T+a[i]);

		//puts("-----------------------");

			//f[i]=min(f[i],f[j]+a[i]-a[j]+max((a[i]-a[j+1])*2,T));

		

		ins(1,0,n,i,f[i]-a[i],f[i]-a[i]-a[i+1]*2);

	}

	printf("%lld\n",f[n]+E-a[n]);

}

// Faster C++ solution for the same problem (measured speedup: 8.522521822617447x):
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

typedef long double DD;

const int inf = 1e9;

const int mo= 1e9+7;

const int N = 101010;

int n;

LL T, E, f[N], p[N];



struct sta{

	LL f,d;

	sta(){}

	sta(LL x, LL y){

		f = x;

		d = y;

	}

	friend bool operator <(sta a, sta b){

		if(a.f == b.f)

			return a.d<b.d;

		else 

			return a.f < b.f;

	}

};

set<sta> s1,s2;



int main(){

	scanf("%d%lld%lld",&n, &E, &T);

	for(int i = 1; i <= n; i++)

		scanf("%lld", p + i);

	sort(p + 1, p + n + 1);

	s1.insert(sta(T, p[1]));

	for(int i = 1; i <= n; i++){

		while(!s1.empty() && (p[i] - (*s1.begin()).d) * 2 > T){

			sta t = *s1.begin();

			s1.erase(s1.begin());

			s2.insert( sta(t.f - T - t.d * 2, t.d) );

		}

		f[i]=1ll << 62;

		if(!s2.empty())

			f[i]=(*s2.begin()).f + p[i] * 3;

		if(!s1.empty())

			f[i] = min(f[i], (*s1.begin()).f + p[i]);

		s1.insert(sta(f[i] - p[i] + T, p[i + 1]));

	}

//	for(int i = 1; i<= n; i++)

//		printf("%lld\n", f[i]);

	printf("%lld\n", f[n] + abs(E - p[n]));

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<set>

using namespace std;



const int MAXN=100005 ;

int n , E, T , dis[MAXN] ;

long long dp[MAXN] ;



multiset<long long> st;

multiset<long long>::iterator it ;



long long calc_1(int j){

	return dp[j]-2*dis[j+1]-dis[j] ;

}



long long calc_2(int j){

	return dp[j]-dis[j] ;

}



int main(){

	scanf("%d%d%d",&n,&E,&T) ;

	memset(dp,0x3f,sizeof(dp)) ;

	for(int i=1;i<=n;++i) scanf("%d",&dis[i]) ;

	dp[0]=0 ;

	int last=0 ; //第一个满足边界的

	st.insert(calc_2(0)) ;

	long long minn=(1ll<<60)-1 ;

	for(int i=1;i<=n;++i){

		while(last<i && 2*(dis[i]-dis[last+1])>=T){

			long long tmp=calc_2(last) ;

			it=st.find(tmp) , st.erase(it) ;

			minn=min(minn,calc_1(last)) , ++last ;

		}

		dp[i]=minn+(long long)3*dis[i] ;

		if(!st.empty()) dp[i]=min(dp[i],(*st.begin())+T+dis[i]) ;

		st.insert(calc_2(i)) ;

	}

	cout << dp[n]+E-dis[n] << '\n' ;

	return 0 ;

}

// Faster C++ solution for the same problem (measured speedup: 1.833194643013317x):
#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <iostream>

#include <algorithm>

using namespace std;

inline int read()

{

	int res, ok = 1;

	char ch;

	for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())

	if (ch == '-')

	ok = -1;

	res = ch - '0';

	for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())

	res = res * 10 + ch - '0';

	return res * ok;

}

int n, t, e, a[100005], last;

long long ans[100005], minn = 1LL << 60;

int main()

{

	n = read();

	e = read();

	t = read();

	for (int i = 1; i <= n; i++)

	a[i] = read();

	ans[0] = 0;

	ans[1] = t;

	for (int i = 2; i <= n; i++)

	{

		while (2LL * (a[i] - a[last + 1]) > t)

		{

			long long now = ans[last] - 2LL * a[last + 1];

			minn = min (minn, now);

			last++;

		}

		ans[i] = ans[i - 1] + t;

		if (last > 0)

		ans[i] = min (ans[i], minn + 2LL * a[i]);

		ans[i] = min (ans[i], ans[last] + t);

	}

	printf ("%lld\n", ans[n] + e);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



using namespace std;



long long f[100010],c[100010],d[100010];

int x[100010];

int n,e,t,T;



inline void add1(int x,long long o)

{

	while(x<=n)

	{

		c[x]=min(c[x],o);

		x+=x&-x;

	}

}



inline long long ask1(int x)

{

	long long nowans=0x3f3f3f3f3f3f3f3fll;

	while(x)

	{

		nowans=min(nowans,c[x]);

		x-=x&-x;

	}

	return nowans;

}



inline void add2(int x,long long o)

{

	while(x)

	{

		d[x]=min(d[x],o);

		x-=x&-x;

	}

}



inline long long ask2(int x)

{

	long long nowans=0x3f3f3f3f3f3f3f3fll;

	while(x<=n)

	{

		nowans=min(nowans,d[x]);

		x+=x&-x;

	}

	return nowans;

}



int main()

{

	scanf("%d%d%d",&n,&e,&t);

	T=t;

	if(t%2)T++;

	for(int i=1;i<=n;i++)

		scanf("%d",&x[i]);

	memset(f,0x3f,sizeof(f));

	memset(c,0x3f,sizeof(c));

	memset(d,0x3f,sizeof(d));

	f[0]=0;

	for(int i=1;i<=n;i++)

	{

		f[i]=min(f[i],f[i-1]+x[i]-x[i-1]+t);

		int now=upper_bound(x+1,x+1+i,x[i]-T/2)-x;

		if(x[i]-T/2>=x[1])

		{

			now--;

			long long nowans=ask1(now);

			f[i]=min(f[i],3ll*x[i]+nowans);

		}

		if(x[i]-T/2<x[1])now=0;

		now++;

		long long nowans=ask2(now);

		f[i]=min(f[i],x[i]+nowans);

		/*for(int j=i+1;j<=n;j++)

		{

			if((x[j]-x[i])*2>=t)f[j]=min(f[j],f[i-1]+3ll*(x[j]-x[i])+x[i]-x[i-1]);

			else f[j]=min(f[j],f[i-1]+t-2*(x[j]-x[i])+3ll*(x[j]-x[i])+x[i]-x[i-1]);

		}*/

		add1(i,-3ll*x[i]+f[i-1]+x[i]-x[i-1]);

		add2(i,0ll+t-x[i]+x[i]+f[i-1]-x[i-1]);

	}

	cout<<f[n]+e-x[n];

}

// Faster C++ solution for the same problem (measured speedup: 3.4549775837027736x):
#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <iostream>

#include <algorithm>

using namespace std;

inline int read()

{

	int res, ok = 1;

	char ch;

	for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())

	if (ch == '-')

	ok = -1;

	res = ch - '0';

	for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())

	res = res * 10 + ch - '0';

	return res * ok;

}

int n, t, e, a[100005], last;

long long ans[100005], minn = 1LL << 60;

int main()

{

	n = read();

	e = read();

	t = read();

	for (int i = 1; i <= n; i++)

	a[i] = read();

	ans[0] = 0;

	ans[1] = t;

	for (int i = 2; i <= n; i++)

	{

		while (2LL * (a[i] - a[last + 1]) > t)

		{

			long long now = ans[last] - 2LL * a[last + 1];

			minn = min (minn, now);

			last++;

		}

		ans[i] = ans[i - 1] + t;

		if (last > 0)

		ans[i] = min (ans[i], minn + 2LL * a[i]);

		ans[i] = min (ans[i], ans[last] + t);

	}

	printf ("%lld\n", ans[n] + e);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define N 111111

#define M 444444

#define LL long long

using namespace std;

int n,i,k,j,a[N];LL f[N],V1[M],V2[M],E,T;

void ins(int k,int l,int r,int x,LL z1,LL z2){

	if(l==r){V1[k]=z1;V2[k]=z2;return;}

	int md=l+r>>1;

	if(x<=md)ins(k<<1,l,md,x,z1,z2);else ins(k<<1|1,md+1,r,x,z1,z2);

	V1[k]=min(V1[k<<1],V1[k<<1|1]);

	V2[k]=min(V2[k<<1],V2[k<<1|1]);

}

LL qu1(int k,int l,int r,int x,int y){

	if(x>y)return 1e18;

	if(x<=l&&r<=y)return V1[k];

	int md=l+r>>1;

	if(y<=md)return qu1(k<<1,l,md,x,y);

	if(x>md)return qu1(k<<1|1,md+1,r,x,y);

	return min(qu1(k<<1,l,md,x,y),qu1(k<<1|1,md+1,r,x,y));

}

LL qu2(int k,int l,int r,int x,int y){

	if(x>y)return 1e18;

	if(x<=l&&r<=y)return V2[k];

	int md=l+r>>1;

	if(y<=md)return qu2(k<<1,l,md,x,y);

	if(x>md)return qu2(k<<1|1,md+1,r,x,y);

	return min(qu2(k<<1,l,md,x,y),qu2(k<<1|1,md+1,r,x,y));

}

int main(){

	for(i=0;i<M;i++)V1[i]=V2[i]=1e18;

	scanf("%d%lld%lld",&n,&E,&T);

	for(i=1;i<=n;i++)scanf("%lld",&a[i]);

	for(i=0,k=0;i<=n;i++){

		f[i]=1e18;

		for(;(a[i]-a[k+1])*2>T&&k<i;k++);

		//f[i]=f[k]+max(a[i]-a[k+1]+a[i]-a[k+1],T)+a[i]-a[k];

		//j<=k a[i]-a[j+1*2>T

		//f[i]=qu2(1,0,0,k)

	//	printf("%d %d\n",(a[i]-a[k+1])*2,T);

		if(i==0)f[i]=0;else 

		f[i]=min(qu1(1,0,n,k,i-1)+T+a[i],qu2(1,0,n,0,k-1)+1ll*a[i]*3);

		//printf("%lld %lld\n",qu1(1,0,n,k,i-1)+T+a[i],qu2(1,0,n,0,k-1)+1ll*a[i]*3);

		//printf("%d %d %lld\n",i,k,f[i]);

	//	printf("%lld %lld %d\n",qu1(1,0,n,k,i-1),qu2(1,0,n,0,k-1),T+a[i]);

		//puts("-----------------------");

			//f[i]=min(f[i],f[j]+a[i]-a[j]+max((a[i]-a[j+1])*2,T));

		

		ins(1,0,n,i,f[i]-a[i],f[i]-a[i]-a[i+1]*2);

	}

	printf("%lld\n",f[n]+E-a[n]);

}

// Faster C++ solution for the same problem (measured speedup: 8.652589112991366x):
#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <iostream>

#include <algorithm>

using namespace std;

inline int read()

{

	int res, ok = 1;

	char ch;

	for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())

	if (ch == '-')

	ok = -1;

	res = ch - '0';

	for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())

	res = res * 10 + ch - '0';

	return res * ok;

}

int n, t, e, a[100005], last;

long long ans[100005], minn = 1LL << 60;

int main()

{

	n = read();

	e = read();

	t = read();

	for (int i = 1; i <= n; i++)

	a[i] = read();

	ans[0] = 0;

	ans[1] = t;

	for (int i = 2; i <= n; i++)

	{

		while (2LL * (a[i] - a[last + 1]) > t)

		{

			long long now = ans[last] - 2LL * a[last + 1];

			minn = min (minn, now);

			last++;

		}

		ans[i] = ans[i - 1] + t;

		if (last > 0)

		ans[i] = min (ans[i], minn + 2LL * a[i]);

		ans[i] = min (ans[i], ans[last] + t);

	}

	printf ("%lld\n", ans[n] + e);

	return 0;

}