#include <bits/stdc++.h>
using namespace std;
int N;
long long D;
const int MAX_N = 2 * 1e5 + 100;
pair<long long, int> p[MAX_N];
int fa[MAX_N];
struct Po {
  long long val;
  int first, second;
  bool operator<(const Po &b) const { return val > b.val; }
};
int findd(int first) {
  return fa[first] == first ? first : fa[first] = findd(fa[first]);
}
void unite(int first, int second) {
  first = findd(first);
  second = findd(second);
  fa[first] = second;
}
bool same(int first, int second) { return findd(first) == findd(second); }
inline long long get(int i, int j, long long a, long long b) {
  return 1LL * abs(i - j) * D + a + b;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> D;
  for (int i = 1; i <= N; ++i) fa[i] = i;
  priority_queue<Po> que;
  for (int i = 1; i <= N; ++i) {
    cin >> p[i].first;
    p[i].second = i;
  }
  sort(p + 1, p + N + 1);
  for (int i = 2; i <= N; ++i) {
    long long first = get(p[1].second, p[i].second, p[1].first, p[i].first);
    que.push((Po){first, p[1].second, p[i].second});
  }
  int first = N - 1;
  long long ans = 0;
  int from = 2, to = 3;
  while (first) {
    Po q = que.top();
    que.pop();
    int u = q.first, v = q.second;
    long long val = q.val;
    if (!same(u, v)) {
      unite(u, v);
      ans += val;
      --first;
      cerr << "u"
              "="
           << u << endl;
      ;
      cerr << "v"
              "="
           << v << endl;
      ;
      cerr << "val"
              "="
           << val << endl;
      ;
      cout << endl;
    }
    long long tmp =
        get(p[from].second, p[to].second, p[from].first, p[to].first);
    que.push((Po){tmp, p[from].second, p[to].second});
    ++to;
    if (to > N) {
      from++;
      to = from + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
