#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
long long lowbit(long long x) { return x & -x; }
const long long N = 200000;
long long n, d;
long long a[N + 1];
pair<long long, long long> p[N + 1];
struct bitree {
  pair<long long, long long> mn[N + 1];
  void init() {
    for (long long i = 1; i <= n; i++) mn[i] = make_pair(inf, 0);
  }
  void chkmn(long long x, pair<long long, long long> v) {
    while (x <= n) mn[x] = min(mn[x], v), x += lowbit(x);
  }
  long long Mn(long long x) {
    pair<long long, long long> res(inf, 0);
    while (x) res = min(res, mn[x]), x -= lowbit(x);
    return res.second;
  }
} bit, bit_r;
vector<pair<long long, long long> > eg;
struct ufset {
  long long fa[N + 1];
  void init() { memset(fa, 0, sizeof(fa)); }
  long long root(long long x) { return fa[x] ? fa[x] = root(fa[x]) : x; }
  bool mrg(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    return fa[x] = y, true;
  }
} ufs;
long long cst(pair<long long, long long> x) {
  if (x.first > x.second) swap(x.first, x.second);
  return a[x.first] + a[x.second] + (x.second - x.first) * d;
}
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  return cst(x) < cst(y);
}
long long kruskal() {
  sort(eg.begin(), eg.end(), cmp);
  long long ans = 0;
  for (long long i = 0; i < eg.size(); i++)
    ans += ufs.mrg(eg[i].first, eg[i].second) * cst(eg[i]);
  return ans;
}
signed main() {
  cin >> n >> d;
  for (long long i = 1; i <= n; i++)
    scanf("%lld", a + i), p[i] = make_pair(a[i], i);
  sort(p + 1, p + n + 1);
  bit.init();
  bit_r.init();
  for (long long i = 1; i <= n; i++) {
    long long mn1 = bit.Mn(p[i].second - 1), mn2 = bit_r.Mn(n - p[i].second);
    if (mn1) eg.push_back(make_pair(p[i].second, mn1));
    if (mn2) eg.push_back(make_pair(p[i].second, mn2));
    bit.chkmn(p[i].second,
              make_pair(p[i].first - p[i].second * d, p[i].second));
    bit_r.chkmn(n - p[i].second + 1,
                make_pair(p[i].first + p[i].second * d, p[i].second));
  }
  cout << kruskal();
  return 0;
}
