#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const ll oo = 1E17;

const int MAX = 2 * 1E5 + 10;
const int BLOCK = 400;
const int TOT = MAX / BLOCK + 1;

struct DS {
  ll val[MAX], best[MAX];
  ll glob[TOT], mini[TOT], cand[TOT];

  void Eval(int bl){
    cand[bl] = oo;
    mini[bl] = oo;
    auto lh = Limits(bl);
    for(int i = lh.fi;i < lh.se;++i){
      relaxMin(cand[bl], val[i]);
      relaxMin(mini[bl], best[i]);
    }
  }

  void Init(){
    for(int i = 0;i < MAX;++i) best[i] = oo;
    for(int i = 0;i < TOT;++i){
      glob[i] = oo;
      Eval(i);
    }
  }

  pii Limits(int bl){
    return mp(bl * BLOCK,
              min(MAX, (bl + 1) * BLOCK));
  }

  void PushDown(int bl){
    if(glob[bl] >= oo) return;
    auto lh = Limits(bl);
    for(int i = lh.fi;i < lh.se;++i)
      relaxMin(best[i], val[i] + glob[bl]);
    glob[bl] = oo;
  }

  pair<int, ll> GetMin(){
    ll val = mini[0];
    for(int i = 1;i < TOT;++i) relaxMin(val, mini[i]);
    if(val >= oo) return mp(0, oo);
    for(int i = 0;i < TOT;++i)
      if(val == mini[i]){
        PushDown(i);
        auto lh = Limits(i);
        for(int j = lh.fi;j < lh.se;++j)
          if(best[j] == val)
            return mp(j, val);
      }
  }

  void Deactivate(int pos){
    int bl = pos / BLOCK;
    PushDown(bl);
    val[pos] = best[pos] = oo;
    Eval(bl);
  }

  void UpdateWhole(int bl, ll w){
    if(w < glob[bl]){
      glob[bl] = w;
      relaxMin(mini[bl], cand[bl] + w);
    }
  }

  void UpdateBetween(int lo, int hi, int bl, ll w){
    for(int i = lo;i < hi;++i)
      relaxMin(best[i], val[i] + w),
      relaxMin(mini[bl], best[i]);
  }

  void Update(int l, int h, ll w){
    int bl = l / BLOCK;
    int bh = h / BLOCK;

    if(bl == bh){
      UpdateBetween(l, h + 1, bl, w);
    } else {
      auto llh = Limits(bl);
      auto rlh = Limits(bh);
      UpdateBetween(l, llh.se, bl, w);
      UpdateBetween(rlh.fi, h + 1, bh, w);
    }

    for(int i = bl + 1;i < bh;++i)
      UpdateWhole(i, w);
  }
};

DS le, re;

int n, d;
vi in;

void Process(int p){
  le.Update(0, p, in[p] + p * 1LL * d);
  re.Update(p, n - 1, in[p] - p * 1LL * d);
}

int main(){
  scanf("%d%d", &n, &d);
  in.resize(n);
  for(int& e : in) scanf("%d", &e);

  //n = 200000;
  //d = 13331;
  //in.resize(n);
  //for(int& e : in) e = rand() + 1;

  for(int i = 0;i < n;++i){
    le.val[i] = in[i] - i * 1LL * d;
    re.val[i] = in[i] + i * 1LL * d;
  }
  for(int i = n;i < MAX;++i)
    le.val[i] = re.val[i] = oo;
  le.Init();
  re.Init();

  le.Deactivate(0);
  re.Deactivate(0);

  Process(0);

  ll ans = 0;
  for(int s = 1;s < n;++s){
    auto vr_val_1 = le.GetMin();
    auto vr_val_2 = re.GetMin();

    int vr;
    ll val;
    if(vr_val_1.se < vr_val_2.se)
      vr = vr_val_1.fi,
      val = vr_val_1.se;
    else
      vr = vr_val_2.fi,
      val = vr_val_2.se;

    //cout << vr << ' ' << val << endl;
    ans += val;

    le.Deactivate(vr);
    re.Deactivate(vr);
    Process(vr);
  }

  //printf("%.3f\n", (clock() - 0.0) / CLOCKS_PER_SEC);
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 7296