#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

const ll INF = 1LL << 60;
int const MAXN = 200005;

struct {
std::vector<ll> bit = vector<ll>(MAXN);

// update bit[j] (j >= i) with max(bit[j], x)
void update(int i, ll x) {
  while (i <= 200000) {
    bit.at(i) = std::max(bit.at(i), x);
    i += i & -i;
  }
}

// get max bit[j] (0 <= j <= i)
ll getmax(int i) {
  ll s = 0;
  while (i>0) {
    s = std::max(bit.at(i), s);
    i -= i & -i;
  }
  return s;
}
} B, C;

vector<P> graph[200005];
vector<bool> used(200005);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  ll d; cin >> d;
  vector<ll> a(n+1);
  rep(i, n) {
    cin >> a[i+1];
  }

  unordered_map<ll, set<int>> mpb;
  for(int i=2; i<=n; i++) {
    ll tmp = LONG_MAX-(a[i]+i*d);
    //debug(i); debugln(tmp);
    B.update(n+1-i, tmp);
    mpb[tmp].insert(i);
  }
  unordered_map<ll, set<int>> mpc;
  for(int i=1; i<=n-1; i++) {
    ll tmp = LONG_MAX-(a[i]+(n-i)*d);
    C.update(i, tmp);
    mpc[tmp].insert(i);
  }

  ll mincost = LONG_MAX;
  ll minu = 0;
  ll minv = 0;

  for(int i=1; i<=n; i++) {
    if (i>1) {
      //debugln("C");
      ll tmp = C.getmax(i-1);
      for(auto pos: mpc[tmp]) {
        if (pos >= i) continue;
        ll cost = a[i] + a[pos] + abs(i-pos)*d;
        graph[i].push_back(P(cost, pos));
        graph[pos].push_back(P(cost, i));
        //debug(i); debug(pos); debugln(cost);
      }
    }
    if (i<n) {
      //debugln("B");
      ll tmp = B.getmax(n-i);
      for(auto pos: mpb[tmp]) {
        if (i >= pos) continue;
        ll cost = a[i] + a[pos] + abs(i-pos)*d;
        graph[i].push_back(P(cost, pos));
        graph[pos].push_back(P(cost, i));
        //debug(i); debug(pos); debugln(cost);
      }
    }
  }

  priority_queue<P, vector<P>, greater<>> que;
  for(auto e: graph[1]) {
    que.push(e);
  }
  used[1] = true;
  ll ans = 0;
  while(que.size()) {
    P pa = que.top(); que.pop();
    ll cost = pa.first;
    int pos = pa.second;
    if (used[pos]) continue;
    used[pos] = true;
    ans += cost;
    for(auto e: graph[pos]) {
      if (used[e.second]) continue;
      que.push(e);
    }
  }

  cout << ans << endl;

}

