#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
template <class S, class T>
istream& operator>>(istream& is, pair<S, T>& p) {
  return is >> p.first >> p.second;
}
template <class T>
istream& operator>>(istream& is, vector<T>& xs) {
  for (auto& x : xs) is >> x;
  return is;
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << p.first << " " << p.second;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& xs) {
  for (unsigned int i = 0; i < xs.size(); ++i) os << (i ? " " : "") << xs[i];
  return os;
}
template <class T>
void maxi(T& x, T y) {
  if (x < y) x = y;
}
template <class T>
void mini(T& x, T y) {
  if (x > y) x = y;
}
void debug(istringstream&) {}
template <char sep = ',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail) {
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const int INF = 1e9;
class UnionFind {
 private:
  vector<int> par, rank;

 public:
  UnionFind(int n) {
    par.assign(n, 0);
    rank.assign(n, 0);
    for (int i = 0; i < n; ++i) par[i] = i;
  }
  int find(int x) {
    if (par[x] == x) return x;
    return (par[x] = find(par[x]));
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) ++rank[x];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  LL N, D;
  cin >> N >> D;
  VL xs(N);
  cin >> xs;
  vector<PLL> pos(N), neg(N);
  for (int i = (0); i < (N); ++i) {
    pos[i] = make_pair(xs[i] + i * D, i);
    neg[i] = make_pair(xs[i] - i * D, i);
  }
  sort(begin(((pos))), end(((pos))));
  sort(begin(((neg))), end(((neg))));
  UnionFind uf(N);
  LL ans = 0;
  VI iter(N);
  priority_queue<PLL, vector<PLL>, greater<PLL>> pq;
  for (int i = (0); i < (N); ++i) {
    int& ix = iter[i];
    while (ix < N && neg[ix].second >= pos[i].second) ++ix;
    if (ix < N) {
      pq.push(make_pair(pos[i].first + neg[ix].first, i));
    }
  }
  int cnt = 0;
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    int i = p.second;
    int& ix = iter[i];
    if (uf.find(pos[i].second) != uf.find(neg[ix].second)) {
      ans += p.first;
      uf.unite(pos[i].second, neg[ix].second);
      ++cnt;
      if (cnt == N - 1) {
        break;
      }
    }
    ++ix;
    while (ix < N && neg[ix].second >= pos[i].second) ++ix;
    if (ix < N) pq.push(make_pair(pos[i].first + neg[ix].first, i));
  }
  cout << ans << endl;
  return 0;
}
