#include <bits/stdc++.h>
using namespace std;
double const PI = 3.1415926535;
struct edge {
  long long from;
  long long to;
  long long cost;
  bool operator<(const edge& rhs) const { return cost > rhs.cost; }
};
long long const MAX = 2e5 + 5;
priority_queue<edge> pq;
long long a[MAX], b[MAX], c[MAX];
long long parent[MAX];
long long rk[MAX];
void init(long long n) {
  for (long long i = 1; i <= n; i++) {
    parent[i] = i;
    rk[i] = 1;
  }
}
long long find(long long x) {
  if (parent[x] == x) {
    return x;
  }
  parent[x] = find(parent[x]);
  return parent[x];
}
bool same(long long x, long long y) { return find(x) == find(y); }
void unite(long long x, long long y) {
  if (!same(x, y)) {
    x = parent[x];
    y = parent[y];
    if (rk[x] < rk[y]) {
      parent[x] = y;
    } else {
      parent[y] = x;
      if (rk[x] == rk[y]) {
        rk[x]++;
      }
    }
  }
}
int main() {
  long long n, d;
  cin >> n >> d;
  init(n);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i] + i * d;
    c[i] = a[i] - i * d;
  }
  long long min_c = c[1];
  long long min_j = 1;
  for (long long i = 2; i <= n; i++) {
    pq.push({i, min_j, min_c + b[i]});
    if (min_c > c[i]) {
      min_c = c[i];
      min_j = i;
    }
  }
  long long min_b = b[n];
  long long min_i = n;
  for (long long j = n - 1; j >= 1; j--) {
    pq.push({j, min_i, min_b + c[j]});
    if (min_b > b[j]) {
      min_b = b[j];
      min_i = j;
    }
  }
  long long ans = 0;
  while (!pq.empty()) {
    edge cur = pq.top();
    pq.pop();
    if (same(cur.from, cur.to)) {
      continue;
    } else {
      ans += cur.cost;
      unite(cur.from, cur.to);
    }
  }
  cout << ans << endl;
}
