// Slower C++ solution:
/*

 *                             UM.

 *                            J@B@1                                                                    iO@1

 *                           Y@@@B@BB.                                                              7B@B@B@

 *                          :@B@i,B@B@O                                                          ,Z@B@B@B@Br

 *                          @B@q   i@B@BS                                                      7@B@@@O5vMB@q

 *                         8@@B      LB@B@i                                                  FB@@@BNjYjLE@B@

 *                        ,B@B:        0@@@Z                                               P@B@BM1JJ125JPB@B

 *                        B@BB          :@B@B                                            XB@B@Z2LuU52F2u2@B@.

 *                       :@B@             @@@B:                                        v@B@B8uJj51F1525uUB@B7

 *                       @B@O              0@@B.               ..::ir7vvYUuU777r::.   B@B@OULU2F2F151F11Y@B@S

 *                       B@B,               8B@B  :ruXMB@B@B@B@B@B@B@B@B@B@@@B@B@B@B@B@B@5Jj1211F1F1F2FUJO@BB

 *                      U@B@                 @B@B@B@B@B@@@B@B@B@MMqPS5JuYL7rq@B@OBB@B@B8Yu211F1515251515YGB@@

 *                      @B@u                 v@@@@MSur:.                    LB@MvvjJuU5YU252F1F1F25251F2uX@@@

 *                      @@@.                                                N@BML2U2UUU12F15252525251515Jk@@B

 *                     r@B@                                                 YB@Bju52121252515252F15251F2u5@B@

 *                     PB@B                                                  @@@PYUF151F25151F152F2F1F15jF@@B

 *                     @@BS                                                  N@@@UJ2F25252F251525151F1F1u5@B@

 *                     @@@7                                                   B@B@5Yj12F152F1F1F25252515jFB@B

 *                     B@Bi                                                    M@B@O2Luu52525212F151121UY1@B@7

 *                    O@B@:                                                     v@B@BMSuYJJuuUu2u2uujjYJJXB@B@M

 *                  7B@B@,                                                        1B@@@B@GPF1uujuu21PNMB@B@B@B@@

 *                 qB@B2                                                            i8B@B@B@B@B@@@@@B@B@B@q: @@@B

 *                MB@B:                                                                 7SBB@B@B@B@B@Zu:      @B@B

 *               ZB@B.                                              ,v.                                        @B@L

 *              LB@B,                         Y7                    @B@Bu                                      7@B@

 *   :B@B@@B2:  @@B7                         @B@Z                   r@B@B@BP:                                   B@BE

 *    BB@@@B@B@B@BE                        r@B@B                       7@B@B@B@Ou:                              iB@B

 *         :uM@@B@@2.           :7::::ivk@B@B@0                           :5B@B@B@B@B@B@G.                       @B@i

 *            BB@@@B@@         :@B@B@@@B@B@@1                                 .i5M@B@B@@@5                       M@@2

 *            B@B ,@B1          L0EZZG0F7:                                            .:,                        uB@MrP@M7

 *           2@B@                                                                                               ,O@B@B@B@B

 *           @B@1                                                     :@B@@@r                                :@@@@B@BL:,,

 *           B@Bi                         :2ZS;                      :@B@B@B@r                               L@B@B@BU

 *           @B@.                        @@@B@B@                     vB@B@B@B5                                   @B@i

 *           B@B                        7B@B@B@BM                     OB@B@B@                                   ,B@B

 *           @B@                         @B@B@@@i                       rL7.                                    B@BM

 *           B@B7.:                       NB@@M.                                                               .@B@.

 *  .;JEB@@@B@B@B@B@.                                                                                       .  @B@u

 *@@@B@B@B@B@@@B@18U                                                                                      :B@B@B@BU,

 *7@BOui.    ,@@B                                                                                          SP@B@B@B@B@Or

 *            @@@U                                                                                           B@BJ.YO@B@B@i

 *            r@B@                                                                                         :B@Bk     .k@B@

 *             B@B@                                                                                       LB@@k         2i

 *              B@BM                                      .7jXEGqF7:                                     OB@@L

 *              .B@BM                                   .B@B@B@B@B@B@.                                 :@B@B:

 *               .B@B@                                   @@MYr::ivG@B                                .M@B@G

 *                 B@@@S                                                                           ,MB@B@,

 *                  v@@@BF                                                                      .1B@B@Br

 *                    2@@B@BL                                                                ,FB@@@B8,

 *                      r@B@B@BF,                                                        :YBB@B@B@B

 *                         L@B@B@B@P7,                                           .ivXB@B@B@B@B@M@B@

 *                            ,1B@B@B@B@@@BOP2L7i:,.              ..,:i7LSNB@@B@B@@@B@B@B@Z5v;.LB@@

 *                              @B@OEB@B@@@B@B@B@B@B@B@B@B@@@B@B@B@B@B@@@B@B@B@B@BM0SJ7i::::i:,u@B@

 *                              B@Bu ::i;7vu2XNGOMB@B@BMB@B@B@B@B@B@@@B1UFuj77ii:::::::iir;r;i.YB@B

 *                              @B@L.:i:i:i::::::::::..Y@B@BMYi:i;SB@B@N:.::i:iirir;r;rii::::ivO@B@

 *                              B@@X::,::::iirir;riri:E@B@1         ,@B@Br:;;r;rii:i::::i7JEB@@@@@B

 *                              @@@B@BBq5v7ii:::::::.2@@@i  ..,..     @B@@,,:::::irv2XMB@B@B@B@2@B@:

 *                             .B@BBB@@@B@B@B@BMNP5u7@B@1 .,,:,,  :.   @B@P50MB@B@B@B@B@@@BS:   @@B1

 *                             E@B@   ijGB@B@B@B@B@B@B@Bi .,:,,..@@B@7 B@B@B@B@B@B@BM57.        kB@B

 *                            .@B@:          .,ivu5Nq@B@u  ..,.. SB@B@@@B@PL7i,                 ,@B@

 *                            @@@8                   i@B@:    .     :B@B@@                       B@@2

 *                          i@@@@                     0@B@u          B@@B.                       vB@B

 *                         ,@B@G                       L@B@BOv:.:iFB@B@M                          @B@Bi

 *                          vNi                          S@@B@B@B@B@BM:                            MB@N

 *                                                          758BMqJ,

 *

 *                 .  YO.               vq                            :G       Z:

 *        SqOMBB@B@Br @@r rBE           @B     B@@@@@B@ONX8k    i::::.OB1.:::.u@O.::::i           @B@B@U:@@B@@BPEBu

 *        B@@NB@k.    5@i  uB@E.        BM     1U2uUJvirB@@Z   r@@B@B@@@B@B@B@B@B@@@B@Bi   LB@B@1 BX :@k uLLLvr@BJ:

 *            iB      iBi    7@     .@M8@BGMZZ         @@F            ,B       Pi          v@  Bq @i v@        B@

 *       vuL7r8@S7vJL7N@Z7LLri;72.   F7@Bvvv@@       @BX         @@@B@B@@@@@B@@@B@B@B      7@  @F Bi @q  @B@Bu @B

 *       N@B@G@@@8@BBOMB@G@BMNXG@,     B@   @@      .Bk          .:u;    i@:      Zv       7@  Bk @,;@  ,BY @B B@

 *            r@       @G     5.      ,@v   BZ :::,.r@E .::i,      @B     B@    .@BL       7@  @F B:i@. .@  @M @B

 *            7B: ,vO, @@   iB@:      @B   7@:MB@B@B@@@B@B@BM       @@.    B:  2@q         7@  BS @i 0@  B. @O B@

 *       ,r2EBB@B@B@Bi G@  @BB        B@   @B        @S              :    r@   ..          7B  @F @7  B7 @  @B @B

 *       E@B@UOBr       @B@Bi          L@0PB        .BZ        .@B@B@B@B@B@B@B@B@B@B@B@,   r@  BF @i  @G B@B@B B@

 *            7@,      kB@U    ;r        @@@.       .@Z                GBuL@iBBi           vB@B@q BP:5@7 @u,.  @B

 *            LBi   YB@BrB@    @@       @B:L@Br      BM             .M@B  rB  rB@J         v@. Pi @XZ8r  .     B@

 *        .   G@i B@BM.  ,B@,  @B    iB@B    N, 7r..q@k         ,LB@B8    J@,   i@B@B1r           Br           @@

 *        MB@B@B  ,i       B@B@B,    B@:        @B@B@F         .@BB:      P@i      :OBZ          .@U       B@B@B:

 *                          .ll                                           rB.                     :

 */

/*

██████████████████████████████████████████████████████████████████████████████

██              ██████    ██████      ██      ██  ██    ██████              ██

██  ██████████  ██  ██      ██      ██████████████  ██████  ██  ██████████  ██

██  ██      ██  ██    ██  ████      ██    ██████████    ██  ██  ██      ██  ██

██  ██      ██  ██    ██  ██      ██  ████        ██  ████  ██  ██      ██  ██

██  ██      ██  ██  ██████  ████  ████████████  ██    ████████  ██      ██  ██

██  ██████████  ██  ████  ██    ████    ████  ██████  ████  ██  ██████████  ██

██              ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██              ██

████████████████████  ██  ██    ██████  ██    ████  ████    ██████████████████

██████  ████          ████        ██    ██    ████  ████████  ██          ████

████  ██      ██  ██      ██  ██████  ████  ████    ██    ████    ████████  ██

██      ██      ██    ██    ████      ████        ██████  ██      ██  ██    ██

██  ██    ████████████  ████  ██  ████            ████  ████████████  ████  ██

██  ██      ██  ██  ████    ████████                ████████      ██  ██    ██

██  ██  ██  ██████████  ████    ██  ████  ██    ████  ████        ████  ██  ██

██    ██  ████  ██████  ██    ******************    ████  ██            ██  ██

██    ██████  ██  ██████      * Scan this QR   *██████    ██  ██  ██  ████████

████  ████  ██  ██████      ██* code to join   *██  ████    ██  ████████  ████

██████      ████████  ██      * in the Three   *██  ████          ████  ██  ██

████              ████  ████  * Body ETO.      *  ████        ██  ████  ██  ██

██████  ██    ████████        *  --ETO manager *██  ██                ██    ██

████    ██  ██  ██    ██████  *    Ye Wenjie   *████  ████  ██  ████  ██  ████

██  ████  ██████    ████  ██  *ETO(C),1988~2018*      ██  ██  ██  ██    ██████

██  ██████  ██  ████    ██  ██******************          ██████    ██████  ██

██  ██  ██    ████    ██        ██  ██        ████████      ████  ██  ██    ██

████████████    ██    ██████  ██████████  ██  ████  ██████████    ██  ██  ████

██████████    ██  ████  ██        ██    ██████████  ██    ██      ██  ██    ██

██    ██  ████    ██  ████  ████      ██████    ██    ██      ██  ██  ████  ██

██████  ██  ██████  ██            ██████████  ██    ██    ████  ████  ██    ██

██      ██████  ████  ████  ████      ████    ████  ████            ██████████

██████████████████      ██  ██  ████  ██    ██  ██    ████  ██████    ██    ██

██              ██        ████████████  ████  ██  ██  ██    ██  ██      ██  ██

██  ██████████  ██    ████  ██████  ██  ██████████████      ██████    ██  ████

██  ██      ██  ████████    ██  ██      ████  ████  ██              ████  ████

██  ██      ██  ████  ████  ████  ██████  ██████████████  ██████████    ██  ██

██  ██      ██  ██    ██████  ██  ██  ██████████  ██  ██      ████    ██    ██

██  ██████████  ██████  ████            ██    ████████  ██  ████    ██████████

██              ██████    ████  ████████  ██  ████    ██    ██  ████  ████  ██

██████████████████████████████████████████████████████████████████████████████

    扫    描    二    维    码    加    入    三    体    E    T    O

*/

/*****************

 *   I<3   C++   *

 *  IWANT ANYAC  *

 * ILOVEPROGRAM! *

 *IT'SINTERESTING*

 * ILOVEPROGRAM! *

 *  INCONTESTS   *

 *   GETSCORE    *

 *    ACCODE     *

 *     LETS      *

 *      GO       *

 *Written by:    *

 *    charlieyan *

 *****************/

#include <assert.h>

#include <ctype.h>

#include <errno.h>

#include <float.h>

#include <fstream>

#include <iomanip>

#include <iostream>

#include <limits>

#include <locale>

#include <math.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <time.h>

#include <wchar.h>

#include <wctype.h>

#include <algorithm>

#include <bitset>

#include <cctype>

#include <cerrno>

#include <clocale>

#include <cmath>

#include <complex>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <ctime>

#include <deque>

#include <exception>

#include <fstream>

#include <functional>

#include <limits>

#include <map>

#include <iomanip>

#include <ios>

#include <iosfwd>

#include <istream>

#include <ostream>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <stdexcept>

#include <streambuf>

#include <string>

#include <utility>

#include <vector>

#include <cwchar>

#include <cwctype>

#include <numeric>

#include <list>

#define LL long long

#define pb push_back

#define pob pop_back

#define mp make_pair

#define FILL(a,v) memset((void*)a,v,sizeof(a))

#define FILL0(a) FILL(a,0)

#define FILL1(a) FILL(a,-1)

#define FILLBIG(a) FILL(a,0x3f)

#define ALL(a) (a).begin(),(a).end()

#define Inf ((int)0x3f3f3f3f)

#define INF ((long long)0x3f3f3f3f3f3f3f3f)

#define Mod 1000000007

#define foreach(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)

#define FOR(i,x) for(int i=0;i<x;i++)

#define RFOR(i,x) for(int i=x-1;i>=0;i--)

#define FFOR(i,a,b) for(int i=a;i<b;i++)

#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)

#define SZ(a) ((int)(a).size())

#define FI first

#define SE second

#define OVER(...) return printf(__VA_ARGS__),0

#define fastio ios::sync_with_stdio(0)

#define filei(f) freopen(f,"r",stdin)

#define fileo(f) freopen(f,"w",stdout)

#define eprintf(...) fprintf(stderr,__VA_ARGS__)

#define MASK(a) (1<<(a))

#define MASKX(x,a) ((x)<<(a))

#define BIT(a,b) (((a)>>(b))&1)

#define cddx(a) priority_queue<a >

#define cxdd(a) priority_queue<a,vector<a >,greater<a > >

#define deval(a) {cerr<<#a<<" = "<<a<<endl;}

#define dearr(be,en) {cerr<<#be;cerr<<" = {";for(auto i=be;i!=en;i++)cerr<<' '<<*i;cerr<<" }\n";}

#define reg register

#define prtime eprintf("\n\nTime used: %dms\n",clock());

#define PI 3.1415926535897932384626

#define TODEG(a) (a*180/PI)

#define y0 ykangjimutigeidiqiuyipianjingtu

#define y1 yxiaomiexuduhuanrenleiwannianankang

#define endl '\n'

#define left leftxiaomiexudurenrenyouze

#define hash hashxushibingduyouweilifushiyiqiedewuti

//抗击母体，给地球一片净土

//消灭徐毒，还人类万年安康

using namespace std;

typedef pair<int,int> pii;

typedef unsigned long long UINT;

typedef unsigned int uint;

typedef long long INT;

typedef long double ldouble;

typedef pair<INT,INT> PII;

typedef stringstream sst;

typedef istringstream iss;

typedef vector<int> vint;

typedef vector<INT> VINT;

typedef vector<pii> vpii;

typedef vector<PII> VPII;

typedef priority_queue<int> pqi;

typedef priority_queue<INT> PQI;

typedef priority_queue<pii> pqp;

typedef priority_queue<PII> PQP;

typedef priority_queue<int,vint,greater<int> > xqi;

typedef priority_queue<INT,VINT,greater<INT> > XQI;

typedef priority_queue<pii,vpii,greater<pii> > xqp;

typedef priority_queue<PII,VPII,greater<PII> > XQP;

struct fastIO

{

	inline fastIO operator>>(int& num)

	{

		num=0;

		char c=getchar();

		while(c!='-'&&(c<'0'||c>'9'))c=getchar();

		bool foo=0;

		if(c=='-')

		{

			foo=1;

			c=getchar();

		}

		while(c>='0'&&c<='9')

		{

			num=(num<<3)+(num<<1)+c-'0';

			c=getchar();

		}

		if(foo)num=-num;

		return *this;

	}

	inline fastIO operator>>(INT& num)

	{

		num=0;

		char c=getchar();

		while(c!='-'&&(c<'0'||c>'9'))c=getchar();

		bool foo=0;

		if(c=='-')

		{

			foo=1;

			c=getchar();

		}

		while(c>='0'&&c<='9')

		{

			num=(num<<3)+(num<<1)+c-'0';

			c=getchar();

		}

		if(foo)num=-num;

		return *this;

	}

	inline fastIO operator>>(float& num)

	{

		scanf("%f",&num);

		return *this;

	}

	inline fastIO operator>>(double& num)

	{

		scanf("%lf",&num);

		return *this;

	}

	inline fastIO operator>>(long double& num)

	{

		scanf("%Lf",&num);

		return *this;

	}

	inline fastIO operator>>(char& num)

	{

		num=getchar();

		while(num==' '||num=='\n')num=getchar();

		return *this;

	}

	inline fastIO operator>>(char* num)

	{

		int cnt=0;

		char c=getchar();

		while(c==' '||c=='\n')c=getchar();

		while(c!=' '&&c!='\n')

		{

			num[cnt++]=c;

			c=getchar();

		}

		num[cnt]=0;

		return *this;

	}

	inline fastIO operator>>(string& num)

	{

		cin>>num;

		return *this;

	}

	inline void printInt(const int& num)

	{

		if(num<10)

		{

			putchar(num+'0');

			return;

		}

		printInt(num/10);

		putchar((num%10)+'0');

	}

	inline void printINT(const INT& num)

	{

		if(num<10)

		{

			putchar(num+'0');

			return;

		}

		printINT(num/10);

		putchar((num%10)+'0');

	}

	inline fastIO operator<<(const int& num)

	{

		if(num<0)putchar('-'),printInt(-num);

		else printInt(num);

		return *this;

	}

	inline fastIO operator<<(const INT& num)

	{

		if(num<0)putchar('-'),printINT(-num);

		else printINT(num);

		return *this;

	}

	inline fastIO operator<<(const float& num)

	{

		printf("%.10f",num);

		return *this;

	}

	inline fastIO operator<<(const double& num)

	{

		printf("%.16lf",num);

		return *this;

	}

	inline fastIO operator<<(const long double& num)

	{

		printf("%.20Lf",num);

		return *this;

	}

	inline fastIO operator<<(const char& num)

	{

		putchar(num);

		return *this;

	}

	inline fastIO operator<<(const char* num)

	{

		for(int i=0;num[i];i++)

			putchar(num[i]);

		return *this;

	}

	inline fastIO operator<<(const string& num)

	{

		cout<<num;

		return *this;

	}

}fio;

//Coded by Charlieyan

//版权所有，翻印必究



struct{

	int fa[200005];

	void init(){

		for(int i=0;i<200005;i++){

			fa[i]=i;

		}

	}

	int root(int x){

		return fa[x]==x?x:(fa[x]=root(fa[x]));

	}

	bool conn(int x,int y){

		x=root(x);

		y=root(y);

		if(x==y){

			return 0;

		}

		fa[x]=y;

		return 1;

	}

}dsu;



INT a[200005];

INT n,d;

vector<pair<INT,PII> > egs;



void solve(int l,int r){

	if(l==r){

		return;

	}

	int m=(l+r)>>1;

	int wrl;

	INT mn=INF;

	for(int i=l;i<=m;i++){

		INT val=a[i]-d*i;

		if(val<mn){

			mn=val;

			wrl=i;

		}

	}

	int wrr;

	mn=INF;

	for(int i=m+1;i<=r;i++){

		INT val=a[i]+d*i;

		if(val<mn){

			mn=val;

			wrr=i;

		}

	}

	for(int i=l;i<=m;i++){

		INT val=a[i]-d*i;

		INT var=a[wrr]+d*wrr;

		egs.pb(mp(val+var,mp(i,wrr)));

	}

	for(int i=m+1;i<=r;i++){

		INT val=a[wrl]-d*wrl;

		INT var=a[i]+d*i;

		egs.pb(mp(val+var,mp(wrl,i)));

	}

	solve(l,m);

	solve(m+1,r);

}



int main(){

	fio>>n>>d;

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

		fio>>a[i];

	}

	solve(0,n-1);

	sort(ALL(egs));

	dsu.init();

	INT ans=0;

	for(int i=0;i<SZ(egs);i++){

		PII p=egs[i].second;

		if(dsu.conn(p.first,p.second)){

			ans+=egs[i].first;

		}

	}

	fio<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.809056671896733x):
/*&@@@@@@@@&&&&&&&&&&&@@@@@@@@&%$$!'''..                                   .!&&&&&&&$$$$$$$$$$$%%%%%%%%%%%%%%%%%%%%%%%|

@@@@@@@@@@@@@@@@&&&&&@@@@&&&&&%%|:`.                                          `|$$$$$$$%%%%%%%%%%||||||||||||||||||||||

@@@@@@@@@@@@@@@@@@&@@@&&$&&$!;:.                                                .;%%%%%%%%||||||||||!!!!|||||||||||||||

@@@@@@@@@@@@@@@@@@@&&&$%$&$%;.                                                    .:|||||||||!!!!!!!!!!!!!!!|||||||||||

@@@@@@@@@@@@@@&&&&&$$$$$$|'                                                          '||||||!!!!!!!!!!!!!!!!!!|||||||||

@@@@@@@@&&&&&&&&&&&$%|%!`        ....                                                 .'||||!!!!!!!!!!!!!!!!!!|||||||||

&&&&&&&&&&&&&$$$$$$$%!'         ...                                                     .;|||!!!!!!!!!!!!!!!!!!!|||||||

&&&&&&$$$$$$$$$$$$%|:.         ...                                                      ..'!|||||||||||||||||||||||||||

$$$$$$$$$$$$%%%%%|;`          ....            ......                                     ..`;||||||||||||||||||||||||||

%%%%%%%%%%%%%%%|!:..         ..`..    ..........   .                               ....     `;|||||||||||||||||||||||||

%%||%||%|%%%%||!:`.          .``..        ..........                          .        ....  `;||||||||||||||||||||||||

||||||||||||%|!;'.          ..``...      .....  ........                      ......    ..... .:|||||||||||||||||||||||

|||||||||||||!;:`        ....```..    ..............                          .  ...............:||||||||||||||||||||||

||||||||||%||!:'.      .   ..`'`.......................  .    .....              ......... ......:|%|||||||||||||||||||

|||||||||%||!;'.          ..````..........................               ....       ..............:|%%%||||||||||||||||

||||||||%||!;:`. ..      ...`'''``...............................                       ........  `;%||||||||||||||||||

||||||%%%||!;:..... .......``''''```..........................................  `:;;;'.   ........ `;%|||||||||||||||||

|||||||||%|!:`.............`''''''''`````````````.................................````...  ........ `;|||||||||||||||||

||||||||||!:`............``'::::::::'''``'''``````````.............    ........`....```...   ........'!||||||||||||||||

||||||||||;`............``':;;;;!;;;::::'''::'''``....................     ...`'````````....   .......:||||||||||||||||

|||||||||;`....     ...``':;;!!!!!!!!;;;:::::::::''`````.....................':::'``````'``..   ..  ...:|||||||||||||||

|||||||!'..         ..``':;;!!!!!!!!!!!;;;;;;;:::::'''```````````....```````'::::''''''''''``..   .  ...:||||||||||||||

|||||!:'`.          .`'':;;!!!!!!||!!!!!!!!!;;;;;;::::::'''''''''''''''`''''''':::'''''''::`....       ..:|||||||||||||

|||!;;'..          .`''::;;!!!!!|||||||!!!!!!!!!!!!;;;;;;;;;;;;;;;;;;;;;;;:::;:::::'''';;;:'.   .    .   .:||||||||||||

||;!;:'`            `'::;;;!!!!!||||||||!!!!!!!!!!!!!!!!!!!!!!!!!||||||!;;;::::;;;::'':;:::'.             .:||||||||||!

|!!!:'`.            .'::;;;!!!!!!|||||||||!!!!!!!!|!!!!!!!!!!!|||||%%%%||!;;;::::::::::::;:`..             .:|||||||||!

!!!;''`.            .'::;;;!!!!!!!!||||!!!!||||!!!!!!;;;!!!!!!||||%%%|||||!!;;:;;;;:'':::'.                  :||||||||!

!|!:''`.             `'::;;;!!!!!!!!!!!!!!!!!!!;::'':;;!!!!!!!|||||||||||||!!;;;;;;;:::''`.                   '!||||||!

!!!:''`.             .`':;;;!!!!!!!!!!!!!!;:''''':;;;;;;;;!!!!||||||||||||!!!;;;;;;;:::''`..                   `;|!!!|!

!!!:'`.               .'::;;;;!!!!!!!!;:''``':;;;;;;;;;;;;;!!|||||||||||||!!!!!;;;;;;:::''`..                   .:|||!!

||!:'`..               `'::;;;;;;!;;;;:''':;;;;;;;;;::'`';!!||||||||||||||!!!!!!!!!;;;:::'`..                     '!|||

|!!:'`..                `:::::;;;;;;;;;;::;;;::::::''``';!!|||||||||||||||!!!!!!!!!!;;;;::'`.                      `;||

||!;'.                   ....``'::;;;!!;;;;;::'''`...`:;!!!|||||||||||||||!!!!!!!!!!!;;;;::'`..                 .   .'!

%||;'..  ..               .`''::::::;!!!!!!;;;::''`::;;!!!||||||||||||||||||||||||!!!!!;;;;::'`.                      '

|%|!:`.                     `'':::'::;!||||!!!!!!;;;;!!!!!||||||||||||||||||||||||||!!!!!;;;;;:'`.                    .

||%|;`                        `````..`;|||||||||||!!!!!!!!|||||||||||||||||||||%||||||!!!!!!!!;::'`..                 .

%|%%|'.  ..                    .....`':!||||||||||||!!||||||||||!!!|||||||%%%%%%%||||||!!|||||!!;:''`.                .

|||%|;.                         .`''::;;|||||||||||!!!!|||||!!!!!!!|||||||%%%%%%|%%%||||||||||||!!;;:'`..             .

|||%|!'.  ..                     `':::;;!|%|||||||!!!!!!!!!!!!!!!!!||||||%%%%%%%%%%%%|||||%%%|||||!!!;;:'`.           .

||||||;`   ..                     `::;;;!|||||||||||!!!!!!!!!!!!!!!!!||||%%%%%%%$$%%%|||||%%%%%||||||||!!;:'`.        .

||||||!:`  ...                     .::;;;!|||||||||||!!!!!!!!!!!!!!!!!||||||%%%%$$%%%||||%%%%%%%%||||%%%||!;;:'.      .

|||||||;`     ..                    .':;;!|||||||||!!!;!!!!!!!!!!!!!!!!||||||%%%%%%%%||||%%%%%%%%%%%%%%%%%%%||!;:''`. .

!!!!!!||;`.    ..              .      `:;;;!!!!!!;::;;!!!!!!!!!!!!!!!!!!|||||||||%%%||||%%%%%%%%||||%%%%%%%%%%%||!;;;::

!!!!!!!!!:.  .......                    `::;;;;;;:;;;!!!||!!!;;;;:;;;!!!!!|||!!!|||||||%%%%%%%|||!||||%%%$$$%%%|||!!!!!

!!!!!!!!!!:.  .......          .          `:::;;;;;;!!!!!!;;;:::;;;;;;!!!!!!!!!!!||||||%%%%%%%%|||!!!||||||||||||||!!!!

;;;;;;!!!!!:`..........       ...           .`:::::;;;;;:'``':;!!!!!!!!!!|!!!!!!!||||||||%%%%%%%%%|||!!!!!!!!!!!!!!!!!!

;;;;;;;!!!!!:`..........        .              .`::::''''':;;!!!!!!!!!|||||!!!!!!!!!!!||||||%%%$$$$%%|||!!!!!!!!!!!!!!!

;;;;;!!!!!!!!;`............. ..                   .`::::;;;;;;;;;;!!!||%%||!!!!!!!;;;!!!!||||%%$$&&&$$%%%|||||||||||||!

!!!!!!!!!!!!!!!:`............        ..               .':::::::;;!!|||%%%||!!!!;;;;;;;;;!!!!||%%$&&&&&$$$$$%%%%||||||||

!!!!!!!!!!|!!!!!:`...............     .      ....        `::;;;!!||||||%||!!!:''::::;;;;;!!!!!|%$&&&&&&&$$$$%%%||||||||

!!!!!!|||||||||!;`............         ...........         .';;!!!!!!!!!!!!;::::::::;;;;;!!!!!!|%$&&&&&&&$$$$%%%|||||||

||||||||||||||||;`........... ...      .......`...           .';;;;;;;!!:``'':::;;;;;;!!!!|||||||$&@@@&&&&$$$$%%%%|||||

||||||||||||||||:``.............       .............            .`':'`.....`':::;;;!!!!||%%%%%%||$@@@@@@&&&$$$%%%%%%%%|

|||||||||||||%|!:'`.............      . ............                   ....`':::;;!|%$$$$$$$$$%%|%&@##@@@&&$$$$$$$$%%$%

||||||||||%%%%|;;;`......  ....      ... ....     ...        ..       .....`':::;;!%$&&&&&&&&&&$%$&@@@@@@&&$$$$$$$$$$$$

||||||%%%%%%%%%!;:'`.....   ...             ..     .......    ..   .....```''::;;!|%$&&@@@@@@@&&$$&&@@@@@&$$%%%%%%%$$$$

%%%%%%%%%%%%%%%!!;'`...........               ...... ..........   ..``````'':;!%%$$$&&@@@###@@@@&&&&&&&$$%%%|||||%$$$&$

%%%%%%%%%%%%%%%|!;'.....`''`..      .          ...............    .``````':!%%||||%$&@@######@@@&&&$$%%%||||||||%$&&&&&

%%%%%%%%%%%%%%%|!:`.......`...     ...````''``````````````.......``''':;|%%|!!!!!!|%$@########@@@&$%%||||||||%%%$&&&@@@

|%%%%%%%%%%%%%%%|;'`.`'`. .....`''''''::::::::::::::::;;:::'::::::;;;;!%%||!!!!!!!||$&########@&$%%|||||||%%$$$&@@@@@#@

Coded by Shinmurn Shar, a 21-yr-old beautiful girl.

*/

#include <bits/stdc++.h>

using namespace std;

#define loop(i,n) for(int i=0;i<(n);i++)

#define pool(i,n) for(int i=(n)-1;i>=0;i--)

#define cont(i,n) for(int i=1;i<=(n);i++)

#define tnoc(i,n) for(int i=(n);i>=1;i--)

#define circ(i,a,b) for(int i=(a);i<=(b);i++)

#define cric(i,a,b) for(int i=(b);i>=(a);i--)

#define sub(i,a) for(int i=a;i;i=((i-1)&(a)))

#define subs(i,a) for(int i=a;i>=0;i=(!i?-1:((i-1)&(a))))

#define range(i,a,b,c) for(int i=(a);((c)>0?i<=(b):i>=(b));i+=(c))

#define foreach(it,v) for(__typeof((v).begin()) it=(v).begin(),_e_D_=(v).end();it!=_e_D_;it++)

#define parse(i,s) for(int i=0;s[i];i++)

#define ln '\n'

#define all(a) a.begin(),a.end()

#define OVER(...) return printf(__VA_ARGS__),0;

#define FILL0(a) memset(a,0,sizeof(a))

#define FILL1(a) memset(a,-1,sizeof(a))

#define FILLBIG(a) memset(a,0x3f,sizeof(a))

#define Mask(a) (1ll<<(a))

#define Maskx(a,x) ((a)<<(x))

#define Full(a) ((1ll<<(a))-1)

#define Bit(a,x) (((a)>>(x))&1)

#define SZ(a) ((int)((a).size()))

#define filei(a) freopen(a,"r",stdin);

#define fileo(a) freopen(a,"w",stdout);

#define fileio(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)

#define Floyd(a,n) cont(k,n)cont(i,n)cont(j,n)chmin(a[i][j],a[i][k]+a[k][j])

#define Floyd0(a,n) loop(k,n)loop(i,n)loop(j,n)chmin(a[i][j],a[i][k]+a[k][j])

#define Floydlr(a,l,r) circ(k,l,r)circ(i,l,r)circ(j,l,r)chmin(a[i][j],a[i][k]+a[k][j])

#define eprintf(...) fprintf(stderr,__VA_ARGS__)

#define y0 y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0

#define y1 y1II11II11III11I1III11II111IIII1II1I1

#define ws WSrAkIoi2333wSraKIoIWSraKiOi

#define pub push_back

#define pob pop_back

#define puf push_front

#define pof pop_front

#define mak make_pair

#define emb emplace_back

#define emf emplace_front

#define emp emplace

#define popcnt __builtin_popcount

#define Popcnt __builtin_popcountll

template<typename _T>

using pair2=pair<_T,_T>;

template<typename _T>

using pair3=pair<pair<_T,_T>,_T>;

template<typename _T>

using pair4=pair<pair<_T,_T>,pair<_T,_T> >;

#define mak3(a,b,c) make_pair(make_pair(a,b),c)

#define mak4(a,b,c,d) make_pair(make_pair(a,b),make_pair(c,d))

template<typename _T>

using priq=priority_queue<_T>;

template<typename _T>

using qrip=priority_queue<_T,vector<_T>,greater<_T> >;

#define ST first

#define ND second

#define FST first.first

#define SND first.second

#define RD second

#define SRD second.first

#define FTH second.second

#ifndef JTAKIOI

#define cerr if(0)cout

#define tctest(clas,meth,...)

#else

#define tctest(clas,meth,...) int main(){fio<<(new clas)->meth(__VA_ARGS__)<<ln;}

#endif

typedef long long ll;

typedef long double lf;

typedef istringstream iss;

typedef stringstream sst;

const lf pi=acosl(-1);

const int Inf=0x3f3f3f3f;

const ll INF=0x3f3f3f3f3f3f3f3fll;

const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,1,0,-1,1,-1,1,-1};

unsigned Rand(){return rand()*32768+rand();}

int rand(int a,int b){return Rand()%(b-a+1)+a;}

template<typename _T>

inline _T chmin(_T &a,_T b){return a>b?(a=b):a;}

template<typename _T>

inline _T chmax(_T &a,_T b){return a<b?(a=b):a;}

template<typename _T,int len>

struct BIT{

	_T dt[len];

	inline void add(int a,_T x){while(a<len){dt[a]+=x;a+=a&-a;}}

	inline void add(int l,int r,_T x){add(l,x);add(r+1,-x);}

	inline _T get(int a){_T ans=0;while(a){ans+=dt[a];a-=a&-a;}return ans;}

	inline _T get(int l,int r){return get(r)-get(l-1);}

};

template<typename _T,int len>

struct segbit{

	_T dt[2][len];

	inline void add(int a,_T x){int b=a;while(a<len){dt[0][a]+=x;dt[1][a]+=x*b;a+=a&-a;}}

	inline void add(int l,int r,_T x){add(l,x);add(r+1,-x);}

	inline _T sum(int a){_T ans=0;int b=a;while(a){ans+=(b+1)*dt[0][a]-dt[1][a];a-=a&-a;}return ans;}

	inline _T sum(int l,int r){return sum(r)-sum(l-1);}

};

struct fastIO{

	inline fastIO operator>>(int& num){

		num=0;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();

		bool foo=0;if(c=='-'){foo=1;c=getchar();}

		while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+c-'0';c=getchar();}

		if(foo)num=-num;return *this;

	}

	inline fastIO operator>>(ll& num){

		num=0;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();

		bool foo=0;if(c=='-'){foo=1;c=getchar();}

		while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+c-'0';c=getchar();}

		if(foo)num=-num;return *this;

	}

	inline fastIO operator>>(float& num){scanf("%f",&num);return *this;}

	inline fastIO operator>>(double& num){scanf("%lf",&num);return *this;}

	inline fastIO operator>>(long double& num){scanf("%Lf",&num);return *this;}

	inline fastIO operator>>(char& num){num=getchar();while(num==' '||num=='\n')num=getchar();return *this;}

	inline fastIO operator>>(char* num){

		int cnt=0;char c=getchar();while(c==' '||c=='\n')c=getchar();

		while(c!=' '&&c!='\n'){num[cnt++]=c;c=getchar();}num[cnt]=0;return *this;

	}

	inline fastIO operator>>(string& num){cin>>num;return *this;}

	inline void printInt(const int& num){if(num<10){putchar(num+'0');return;}printInt(num/10);putchar((num%10)+'0');}

	inline void printll(const ll& num){if(num<10){putchar(num+'0');return;}printll(num/10);putchar((num%10)+'0');}

	inline fastIO operator<<(const int& num){if(num<0)putchar('-'),printInt(-num);else printInt(num);return *this;}

	inline fastIO operator<<(const ll& num){if(num<0)putchar('-'),printll(-num);else printll(num);return *this;}

	inline fastIO operator<<(const float& num){printf("%.10f",num);return *this;}

	inline fastIO operator<<(const double& num){printf("%.16lf",num);return *this;}

	inline fastIO operator<<(const long double& num){printf("%.20Lf",num);return *this;}

	inline fastIO operator<<(const char& num){putchar(num);return *this;}

	inline fastIO operator<<(const char* num){for(int i=0;num[i];i++)putchar(num[i]);return *this;}

	inline fastIO operator<<(const string& num){cout<<num;return *this;}

	template<typename _T> inline fastIO operator<<(const vector<_T> &vec){printf("{ ");foreach(i,vec)operator<<(*i)<<' ';printf("}");return *this;}

}fio;

const lf eps=1e-10;

struct point{

	lf x,y;

	lf ang;

	point(){}

	point(lf x,lf y):x(x),y(y){ang=atan2l(y,x);}

	inline point operator=(const point &pt){x=pt.x;y=pt.y;return *this;}

	inline point operator-()const{return point(-x,-y);}

	inline point operator+(const point &pt)const{return point(x+pt.x,y+pt.y);}

	inline point operator-(const point &pt)const{return point(x-pt.x,y-pt.y);}

	inline point operator*(const lf &a)const{return point(x*a,y*a);}

	inline point operator/(const lf &a)const{return point(x/a,y/a);}

	inline point operator^(const lf &ang)const{return point(x*cosl(ang)-y*sinl(ang),x*sinl(ang)+y*cosl(ang));}

	inline point operator+=(const point &pt){return *this=point(x+pt.x,y+pt.y);}

	inline point operator-=(const point &pt){return *this=point(x-pt.x,y-pt.y);}

	inline point operator*=(const lf &a){return *this=point(x*a,y*a);}

	inline point operator/=(const lf &a){return *this=point(x/a,y/a);}

	inline point operator^=(const lf &ang){return *this=point(x*cosl(ang)-y*sinl(ang),x*sinl(ang)+y*cosl(ang));}

	inline lf operator*(const point &pt)const{return x*pt.x+y*pt.y;}//dot

	inline lf operator%(const point &pt)const{return x*pt.y-y*pt.x;}//det

	inline lf length()const{return x*x+y*y;}

	inline lf size()const{return sqrtl(x*x+y*y);}

	inline lf operator^(const point &pt)const{return acosl(*this*pt)/length()/pt.length();}

	inline lf getangle(){return ang=atan2l(y,x);}

	inline lf angle()const{return atan2l(y,x);}

	inline bool operator<(const point &p)const{return ang<p.ang;}

};

inline bool xsmaller(const point &x,const point &y){return fabs(x.x-y.x)<1e-10?x.y<y.y:x.x<y.x;}

inline bool ysmaller(const point &x,const point &y){return fabs(x.y-y.y)<1e-10?x.x<y.x:x.y<y.y;}

struct line{

	point a,b;

	line(){}

	line(point a,point b):a(a),b(b){}

};

point intersect(line x,line y){

	point p1=x.a,v1=x.b-x.a;

	point p2=y.a,v2=y.b-y.a;

	return p1+v1*(((p2-p1)%v2)/(v1%v2));

}

const int jt=998244353;

inline int &Add(int &a,int b){

	a+=b;

	if(a>jt){a-=jt;}

	if(a<0){a+=jt;}

	return a;

}

inline int &Sub(int &a,int b){

	a-=b;

	if(a>jt){a-=jt;}

	if(a<0){a+=jt;}

	return a;

}

inline int &Mul(int &a,int b){

	a=1ll*a*b%jt;

	if(a<0){a+=jt;}

	return a;

}

inline int Jar(int a,int b){

	a+=b;

	if(a>jt){a-=jt;}

	if(a<0){a+=jt;}

	return a;

}

inline int Jan(int a,int b){

	a-=b;

	if(a>jt){a-=jt;}

	if(a<0){a+=jt;}

	return a;

}

inline int Churn(int a,int b){

	a=1ll*a*b%jt;

	if(a<0){a+=jt;}

	return a;

}

inline int ksmii(int a,int b=jt-2){

	if(b<0){return ksmii(ksmii(a),-b);}

	if(!b){return 1;}

	int x=ksmii(a,b>>1);x=1ll*x*x%jt;

	if(b&1)x=1ll*x*a%jt;return x;

}

template<int len>

struct bitmod{

	int dt[len];

	inline void add(int a,int x){while(a<len){dt[a]=(dt[a]+x)%jt;a+=a&-a;}}

	inline void add(int l,int r,int x){add(l,x%jt);add(r+1,jt-x%jt);}

	inline int get(int a){int ans=0;while(a){ans=(ans+dt[a])%jt;a-=a&-a;}return ans;}

	inline int get(int l,int r){return (get(r)-get(l-1)+jt)%jt;}

};

template<int len>

struct DSU{

	int fa[len],sz[len];

	DSU(){loop(i,len)fa[i]=i,sz[i]=1;}

	void init(){loop(i,len)fa[i]=i,sz[i]=1;}

	int root(int x){return fa[x]==x?x:(fa[x]=root(fa[x]));}

	bool conn(int a,int b){a=root(a);b=root(b);if(a==b)return 0;fa[a]=b;sz[b]+=sz[a];return 1;}

};

template<typename _T>

inline _T qp(_T a,int b){

	if(!b){return 1;}

	_T x=qp(a,b>>1);x=x*x;

	if(b&1){x=x*a;}return x;

}

template<int R,int C=R>

struct matrix{

	int mat[R][C];

	int* operator[](int x){

		return mat[x];

	}

	matrix(){loop(i,R)loop(j,C)mat[i][j]=0;}

	matrix(int x){loop(i,R)loop(j,C)mat[i][j]=(i==j?x:0);}

	matrix<R,C> operator+(const matrix<R,C> m){

		matrix<R,C> ans;

		loop(i,R)loop(j,C)ans.mat[i][j]=(mat[i][j]+m.mat[i][j])%jt;

		return ans;

	}

	template<int D>

	matrix<R,D> operator*(const matrix<C,D> m){

		matrix<R,D> ans;

		loop(i,R)loop(j,C)loop(k,D)ans.mat[i][k]=(ans.mat[i][k]+((ll)mat[i][j])*m.mat[j][k])%jt;

		return ans;

	}

	matrix<R,C> operator+=(const matrix<R,C> m){

		matrix<R,C> ans;

		loop(i,R)loop(j,C)ans.mat[i][j]=(mat[i][j]+m.mat[i][j])%jt;

		return ans;

	}

	matrix<R,C> operator-=(const matrix<R,C> m){

		matrix<R,C> ans;

		loop(i,R)loop(j,C)ans.mat[i][j]=(mat[i][j]-m.mat[i][j]+jt)%jt;

		return ans;

	}

	void debug(){

		loop(i,R){loop(j,C)cerr<<mat[i][j]<<' ';cerr<<endl;}cerr<<endl;

	}

};



int n;

ll d;

ll qz[200005],hz[200005];

ll a[200005];



int main(){

	fio>>n>>d;

	ll ans=0;

	cont(i,n){

		fio>>a[i];

		ans+=a[i];

	}

	qz[1]=a[1];

	hz[n]=a[n];

	circ(i,2,n){

		qz[i]=min(qz[i-1]+d,a[i]);

	}

	cric(i,1,n-1){

		hz[i]=min(hz[i+1]+d,a[i]);

	}

	circ(i,2,n-1){

		ans+=min(qz[i],hz[i]);

	}

	fio<<ans+d*(n-1)<<ln;

	return 0;

}