#include <bits/stdc++.h>
using namespace std;
long long mod(long long a) {
  long long c = a % (long long)(1E9 + 7);
  if (c >= 0) return c;
  return c + (long long)(1E9 + 7);
}
long long inf = (long long)1E16;
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
void Max(long long &pos, long long val) { pos = max(pos, val); }
void Min(long long &pos, long long val) { pos = min(pos, val); }
void Add(long long &pos, long long val) { pos = mod(pos + val); }
long double EPS = 1E-9;
long long par[1000000], dep[1000000];
void init(long long n) {
  for (long long i = 0; i <= n - 1; i++) {
    par[i] = i;
    dep[i] = 0;
  }
}
long long find(long long x) { return par[x] == x ? x : par[x] = find(par[x]); }
void unite(long long x, long long y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (dep[x] < dep[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (dep[x] == dep[y]) dep[x]++;
  }
}
bool same(long long x, long long y) { return find(x) == find(y); }
struct edge {
  long long u, v, cost;
};
bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }
vector<edge> es;
long long v;
long long kruskal() {
  sort(es.begin(), es.end(), comp);
  init(v);
  long long res = 0;
  for (auto e : es) {
    if (!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, d;
  cin >> n >> d;
  v = n;
  long long a[n];
  for (long long i = 0; i <= n - 1; i++) cin >> a[i];
  long long sr[n];
  for (long long i = 0; i <= n - 1; i++) sr[i] = a[i] + d * i;
  long long mini = n - 1;
  for (long long i = n - 2; i >= 0; i--) {
    edge e = {i, mini, a[i] + a[mini] + abs(mini - i) * d};
    es.push_back(e);
    if (sr[i] < sr[mini]) {
      mini = i;
    }
  }
  long long sl[n];
  for (long long i = 0; i <= n - 1; i++) sl[i] = a[i] + d * (n - i);
  mini = 0;
  for (long long i = 1; i <= n - 1; i++) {
    edge e = {i, mini, a[i] + a[mini] + abs(mini - i) * d};
    es.push_back(e);
    if (sl[i] < sl[mini]) {
      mini = i;
    }
  }
  cout << kruskal() << endl;
  return 0;
}
