#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e5 + 5;
long long id[MAX], nodes, edges;
pair<long long, pair<long long, long long> > p[MAX];
void initialize() {
  for (long long i = 0; i < MAX; ++i) id[i] = i;
}
long long root(long long x) {
  while (id[x] != x) {
    id[x] = id[id[x]];
    x = id[x];
  }
  return x;
}
void union1(long long x, long long y) {
  long long p = root(x);
  long long q = root(y);
  id[p] = id[q];
}
long long kruskal(vector<pair<long long, pair<long long, long long> > > p) {
  long long x, y;
  long long cost, minimumCost = 0;
  edges = p.size();
  for (long long i = 0; i < edges; ++i) {
    x = p[i].second.first;
    y = p[i].second.second;
    cost = p[i].first;
    if (root(x) != root(y)) {
      minimumCost += cost;
      union1(x, y);
    }
  }
  return minimumCost;
}
long long n, D;
long long a[200005];
const long long inf = 1e16;
map<long long, long long> mp;
map<long long, long long> rmp;
long long N;
void solve(long long l, long long r,
           vector<pair<long long, pair<long long, long long> > > &e) {
  long long mid = (l + r) / 2;
  long long id1 = -1;
  long long id2 = -1;
  if (l == r) return;
  long long mnm = 1e16;
  for (long long i = l; i <= mid; i++) {
    if (mnm > a[i] - i * D) {
      mnm = a[i] - i * D;
      id1 = i;
    }
  }
  mnm = 1e16;
  for (long long i = mid + 1; i <= r; i++) {
    if (mnm > a[i] - i * D) {
      mnm = a[i] + i * D;
      id2 = i;
    }
  }
  for (long long i = mid + 1; i <= r; i++) {
    e.push_back(make_pair(a[i] + a[id1] + (i - id1) * D, make_pair(i, id1)));
  }
  for (long long i = l; i <= mid; i++) {
    e.push_back(make_pair(a[i] + a[id2] + (id2 - i) * D, make_pair(i, id2)));
  }
  solve(l, mid, e);
  solve(mid + 1, r, e);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> D;
  initialize();
  vector<pair<long long, long long> > v;
  vector<long long> aa;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    v.push_back(make_pair(a[i], i));
    aa.push_back(a[i]);
  }
  sort(aa.begin(), aa.end());
  long long sz = unique(aa.begin(), aa.end()) - aa.begin();
  aa.resize(sz);
  for (long long i = 0; i < sz; i++) {
    mp[aa[i]] = i + 1;
    rmp[i + 1] = aa[i];
  }
  N = 5 * sz;
  sort(v.begin(), v.end());
  vector<pair<long long, pair<long long, long long> > > e;
  solve(1, n, e);
  sort(e.begin(), e.end());
  long long ans = kruskal(e);
  cout << ans << endl;
  return 0;
}
