#include <bits/stdc++.h>
using namespace std;
int used[262144];
long long n, d, a[262144], ans = 0, two[20];
pair<long long, long long> p[262144], t[2 * 262144][2];
vector<pair<long long, long long>> g[262144];
void init() {
  for (long long i = 0; i < 2 * 262144; i++) {
    t[i][0] = t[i][1] = make_pair(10000000000, i);
  }
  two[0] = 1;
  for (int i = 1; i < 20; i++) {
    two[i] = two[i - 1] * 2;
  }
}
void change(long long i) {
  long long y = p[i].second + 262144;
  t[y][0].first = d * (y - 262144) + p[i].first;
  t[y][1].first = d * (n - 1 - y + 262144) + p[i].first;
  y /= 2;
  while (y > 0) {
    t[y][0] = min(t[2 * y][0], t[2 * y + 1][0]);
    t[y][1] = min(t[2 * y][1], t[2 * y + 1][1]);
    y /= 2;
  }
}
pair<long long, long long> smq(long long l, long long r, int y) {
  long long cnt = 1, x = l;
  if (l == r) {
    return t[l][y];
  }
  while (x > 0) {
    if (x / 2 * two[cnt] == l && (x / 2 + 1LL) * two[cnt] - (1LL) == r) {
      return t[x / 2][y];
    } else if (x / 2 * two[cnt] < l || (x / 2 + 1LL) * two[cnt] - (1LL) > r) {
      return min(t[x][y], smq((x + 1LL) * two[cnt - 1], r, y));
    }
    x /= 2;
    cnt++;
  }
  return t[x][y];
}
int main() {
  pair<long long, long long> x;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  scanf("%lld %lld", &n, &d);
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    p[i] = make_pair(a[i], i);
  }
  init();
  sort(p, p + n);
  change(0);
  for (long long i = 1; i < n; i++) {
    x = smq(p[i].second + 262144, n - 1 + 262144, 0);
    if (x.first < 10000000000) {
      g[p[i].second].push_back(
          make_pair(x.first - d * p[i].second + p[i].first, x.second - 262144));
      g[x.second - 262144].push_back(
          make_pair(x.first - d * p[i].second + p[i].first, p[i].second));
    }
    x = smq(262144, p[i].second + 262144, 1);
    if (x.first < 10000000000) {
      g[p[i].second].push_back(make_pair(
          x.first - d * (n - 1 - p[i].second) + p[i].first, x.second - 262144));
      g[x.second - 262144].push_back(make_pair(
          x.first - d * (n - 1 - p[i].second) + p[i].first, p[i].second));
    }
    change(i);
  }
  used[p[n - 1].second] = 1;
  for (int i = 0; i < g[p[n - 1].second].size(); i++) {
    q.push(g[p[n - 1].second][i]);
  }
  while (!q.empty()) {
    x = q.top();
    q.pop();
    if (used[x.second] == 0) {
      ans += x.first;
      for (int i = 0; i < g[x.second].size(); i++) {
        q.push(g[x.second][i]);
      }
      used[x.second] = 1;
    }
  }
  printf("%lld\n", ans);
}
