#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
#pragma GCC optimize("-O2")
template <class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >;
const int LM = 1e5;
long long n, d, a[LM + 2], INF = 1e18;
pair<long long, long long> sg1[4 * LM + 5], sg2[4 * LM + 5];
int sz[LM + 2], p[LM + 2], siz = 1;
vector<pair<long long, pair<int, int> > > edges;
vector<pair<long long, long long> > v;
int find(int x) {
  while (p[x] != x) x = p[x];
  return x;
}
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  if (sz[a] < sz[b]) swap(a, b);
  p[b] = a;
  sz[a] += sz[b];
}
void init(pair<long long, long long> sg[]) {
  while (siz < n) siz *= 2;
  for (int i = 1; i <= 2 * siz - 1; i++) sg[i] = make_pair(INF, 1);
}
void update(int x, long long val, pair<long long, long long> sg[]) {
  sg[x + siz - 1] = make_pair(val, x);
  x += siz - 1;
  x /= 2;
  while (x != 0) {
    sg[x] = min(sg[2 * x], sg[2 * x + 1]);
    x /= 2;
  }
}
pair<long long, long long> query(int l, int r,
                                 pair<long long, long long> sg[]) {
  l += siz - 1;
  r += siz - 1;
  pair<long long, long long> ret = make_pair(INF, 1);
  while (r >= l) {
    if (l % 2 == 1) {
      ret = min(ret, sg[l++]);
    }
    if (r % 2 == 0) {
      ret = min(ret, sg[r--]);
    }
    l /= 2;
    r /= 2;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> d;
  init(sg1);
  init(sg2);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    v.push_back(make_pair(a[i], i));
  }
  sort(v.begin(), v.end());
  for (auto u : v) {
    auto t1 = query(1, u.second - 1, sg1);
    auto t2 = query(u.second + 1, n, sg2);
    int i1 = t1.second, i2 = t2.second;
    long long w1 = u.first + d * u.second + t1.first;
    long long w2 = u.first - d * u.second + t2.first;
    edges.push_back(make_pair(w1, make_pair(u.second, i1)));
    edges.push_back(make_pair(w2, make_pair(u.second, i2)));
    update(u.second, u.first - d * u.second, sg1);
    update(u.second, u.first + d * u.second, sg2);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= n; i++) sz[i] = 1;
  sort(edges.begin(), edges.end());
  for (auto u : edges) {
    if (find(u.second.first) == find(u.second.second))
      continue;
    else {
      unite(u.second.first, u.second.second);
      ans += u.first;
    }
  }
  cout << ans << endl;
}
