#include <bits/stdc++.h>
using namespace std;
int par[200010];
int depth[200010];
int size[200010] = {};
int N;
long long D, ans, A[200010], L[200010], R[200010];
vector<pair<long long, pair<int, int>>> E;
void init() {
  for (int i = 0; i < N; i++) {
    par[i] = i;
    depth[i] = 0;
    size[i] = 1;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  else if (depth[x] < depth[y]) {
    par[x] = y;
    size[y] += size[x];
  } else {
    par[y] = x;
    size[x] += size[y];
    if (depth[x] == depth[y]) depth[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int siz(int x) { return size[find(x)]; }
int main() {
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    L[i] = A[i] + D * i;
    R[i] = A[i] + D * (N - 1 - i);
  }
  long long int mx = L[N - 1];
  int idx = N - 1;
  for (int i = N - 2; i >= 0; i--) {
    long long cost = mx - D * i + A[i];
    E.push_back(make_pair(cost, make_pair(i, idx)));
    if (L[i] < mx) {
      mx = L[i];
      idx = i;
    }
  }
  mx = R[0];
  idx = 0;
  for (int i = 1; i <= N - 1; i++) {
    long long cost = mx - D * (N - 1 - i) + A[i];
    E.push_back(make_pair(cost, make_pair(i, idx)));
    if (R[i] < mx) {
      mx = R[i];
      idx = i;
    }
  }
  sort(E.begin(), E.end());
  init();
  for (int i = 0; i < E.size(); i++) {
    int a = E[i].second.first;
    int b = E[i].second.second;
    if (same(a, b)) continue;
    unite(a, b);
    ans += E[i].first;
  }
  cout << ans << endl;
}
