#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long inf = 1e18 + 123;
int n, a[N], d;
long long ans;
vector<pair<int, int> > vec;
vector<pair<long long, pair<int, int> > > edge;
struct Bit1 {
  vector<pair<long long, int> > node;
  Bit1(int sz = 0) { node.assign(sz + 5, pair<long long, int>(inf, 0)); }
  void update(int pos, pair<long long, int> val) {
    for (; pos < (int)node.size(); pos += pos & -pos)
      node[pos] = min(node[pos], val);
  }
  pair<long long, int> get(int pos) {
    pair<long long, int> ret = pair<long long, int>(inf, 0);
    for (; pos > 0; pos -= pos & -pos) ret = min(ret, node[pos]);
    return ret;
  }
};
struct Bit2 {
  vector<pair<long long, int> > node;
  Bit2(int sz = 0) { node.assign(sz + 5, pair<long long, int>(inf, 0)); }
  void update(int pos, pair<long long, int> val) {
    pos = (int)node.size() - pos;
    for (; pos < (int)node.size(); pos += pos & -pos)
      node[pos] = min(node[pos], val);
  }
  pair<long long, int> get(int pos) {
    pos = (int)node.size() - pos;
    pair<long long, int> ret = pair<long long, int>(inf, 0);
    for (; pos > 0; pos -= pos & -pos) ret = min(ret, node[pos]);
    return ret;
  }
};
struct Dsu {
  vector<int> pSet, szSet;
  Dsu(int _n = 0) {
    pSet.assign(_n + 5, 0);
    for (int i = 0; i < (int)pSet.size(); ++i) pSet[i] = i;
    szSet.assign(_n + 5, 1);
  }
  int findSet(int i) { return i == pSet[i] ? i : pSet[i] = findSet(pSet[i]); }
  bool unionSet(int i, int j) {
    i = findSet(i);
    j = findSet(j);
    if (i == j) return false;
    if (szSet[i] > szSet[j]) swap(i, j);
    szSet[j] += szSet[i];
    pSet[i] = j;
    return true;
  }
};
long long cost(int i, int j) { return 1LL * abs(i - j) * d + a[i] + a[j]; }
int main() {
  scanf("%d %d", &n, &d);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    vec.push_back(pair<int, int>(a[i], i));
  }
  sort(vec.begin(), vec.end());
  Bit1 bit1(n);
  Bit2 bit2(n);
  for (auto _ : vec) {
    int i = _.second;
    pair<long long, int> tmp1 = bit1.get(i), tmp2 = bit2.get(i);
    if (tmp1.second)
      edge.push_back(pair<long long, pair<int, int> >(
          cost(tmp1.second, i), pair<int, int>(tmp1.second, i)));
    if (tmp2.second)
      edge.push_back(pair<long long, pair<int, int> >(
          cost(tmp2.second, i), pair<int, int>(tmp2.second, i)));
    bit1.update(i, pair<long long, int>(a[i] - 1LL * i * d, i));
    bit2.update(i, pair<long long, int>(a[i] + 1LL * i * d, i));
  }
  sort(edge.begin(), edge.end());
  Dsu dsu(n);
  for (auto _ : edge) {
    if (dsu.unionSet(_.second.first, _.second.second)) ans += _.first;
  }
  printf("%I64d", ans);
  return 0;
}
