#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
const long double eps = 1e-11;
const long double pi = acos(-1.0);
int n;
long long d;
long long a[1 << 18];
long long x[1 << 18], y[1 << 18];
const int MAX_N = (1 << 18);
int nn;
pair<long long, long long> dat[2 * MAX_N - 1];
void init() {
  nn = 1;
  while (nn < n) nn *= 2;
  for (int i = 0; i < 2 * nn - 1; i++) dat[i] = {INF, 0};
}
void update(int k, long long a) {
  k += nn - 1;
  dat[k] = {a, k - (nn - 1)};
  while (k > 0) {
    k = (k - 1) / 2;
    if (dat[k * 2 + 1].first < dat[k * 2 + 2].first) {
      dat[k] = dat[k * 2 + 1];
    } else
      dat[k] = dat[k * 2 + 2];
  }
}
pair<long long, long long> query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return {INF, 0};
  if (a <= l && r <= b)
    return dat[k];
  else {
    pair<long long, long long> vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    pair<long long, long long> vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    if (vl.first < vr.first)
      return vl;
    else
      return vr;
  }
}
priority_queue<pair<long long, pair<int, int>>,
               vector<pair<long long, pair<int, int>>>,
               greater<pair<long long, pair<int, int>>>>
    q;
long long ans;
int par[1 << 18];
int rank1[1 << 18];
void initt(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rank1[i] = 0;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rank1[x] < rank1[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rank1[x] == rank1[y]) rank1[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  cin >> n >> d;
  init();
  initt(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x[i] = a[i] + i * d;
    y[i] = a[i] - i * d;
    update(i, x[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    pair<long long, long long> val = query(i + 1, n, 0, 0, nn);
    val.first += y[i];
    q.push({val.first, {i, val.second}});
  }
  for (int i = 0; i < n - 1; i++) {
    pair<long long, pair<int, int>> z = q.top();
    q.pop();
    int fr = z.second.first;
    int to = z.second.second;
    if (same(fr, to)) {
      i--;
      update(to, INF);
      pair<long long, long long> vr = query(fr + 1, n, 0, 0, nn);
      q.push({vr.first + y[fr], {fr, vr.second}});
      continue;
    }
    ans += z.first;
    unite(fr, to);
    update(to, INF);
    pair<long long, long long> vr = query(to + 1, n, 0, 0, nn);
    pair<long long, long long> vl = query(fr + 1, n, 0, 0, nn);
    if (vl.first + y[fr] < vr.first + y[to]) {
      q.push({vl.first + y[fr], {fr, vl.second}});
    } else {
      q.push({vr.first + y[to], {fr, vr.second}});
    }
  }
  cout << ans << endl;
  return 0;
}
