#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9 + 10;
const int N = (int)2e5 + 10;
int a[N], b[N], n, d, x;
long long sum;
struct data {
  int minA, minB;
  pair<int, int> bestPair;
  data() : minA(-1), minB(-1), bestPair(make_pair(-1, -1)) {}
  data(int minAValue, int minBValue, pair<int, int> bestPairValue)
      : minA(minAValue), minB(minBValue), bestPair(bestPairValue) {}
  int getDiff() const {
    return (bestPair == make_pair(-1, -1))
               ? INF
               : (b[bestPair.second] + a[bestPair.first]);
  }
  int getMinA() const { return (minA == -1) ? INF : a[minA]; }
  int getMinB() const { return (minB == -1) ? INF : b[minB]; }
} rmq[4 * N];
data operator+(const data& l, const data& r) {
  if (l.minA == -1) return r;
  if (r.minB == -1) return l;
  data res;
  res.minA = (l.getMinA() < r.getMinA()) ? l.minA : r.minA;
  res.minB = (l.getMinB() < r.getMinB()) ? l.minB : r.minB;
  res.bestPair = (l.getDiff() < r.getDiff()) ? l.bestPair : r.bestPair;
  if (res.getDiff() > b[r.minB] + a[l.minA])
    res.bestPair = make_pair(l.minA, r.minB);
  return res;
}
void update(int t, int l, int r, int i) {
  if (l == r - 1) {
    rmq[t] = data(l, l, make_pair(-1, -1));
  } else {
    int m = (l + r) / 2;
    if (i < m) {
      update(t * 2 + 1, l, m, i);
    } else {
      update(t * 2 + 2, m, r, i);
    }
    rmq[t] = rmq[t * 2 + 1] + rmq[t * 2 + 2];
  }
}
void build(int t, int l, int r) {
  if (l == r - 1) {
    rmq[t] = data(l, l, make_pair(-1, -1));
  } else {
    int m = (l + r) / 2;
    build(t * 2 + 1, l, m);
    build(t * 2 + 2, m, r);
    rmq[t] = rmq[t * 2 + 1] + rmq[t * 2 + 2];
  }
}
data get(int t, int l, int r, int x, int y) {
  if ((y <= l) || (r <= x)) return data(-1, -1, make_pair(-1, -1));
  if ((x <= l) && (r <= y)) return rmq[t];
  int m = (l + r) / 2;
  return get(t * 2 + 1, l, m, x, y) + get(t * 2 + 2, m, r, x, y);
}
void solve(int l, int r) {
  if (l == r - 1) return;
  pair<int, int> bestPair = get(0, 0, n, l, r).bestPair;
  int minA = bestPair.first, minB = bestPair.second;
  sum += b[minB] + a[minA];
  for (int i = minA + 1; i < minB; ++i) {
    sum += min(b[i] + a[minA], a[i] + b[minB]);
  }
  b[minA] = min(b[minA], b[minB]), a[minB] = min(a[minA], a[minB]);
  update(0, 0, n, minA);
  update(0, 0, n, minB);
  if (l < minA) {
    solve(l, minA + 1);
  }
  if (minB < r) {
    solve(minB, r);
  }
}
int main() {
  scanf("%d%d", &n, &d);
  build(0, 0, n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    a[i] = x - i * (long long)d;
    b[i] = x + i * (long long)d;
    update(0, 0, n, i);
  }
  solve(0, n);
  printf("%lld\n", sum);
  return 0;
}
