#include <bits/stdc++.h>
using namespace std;
void Debug() { cout << '\n'; }
template <class FIRST, class... REST>
void Debug(FIRST arg, REST... rest) {
  cout << arg << " ";
  Debug(rest...);
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  if (!v.empty()) {
    for (int i = int(0); i < int((int)(v).size() - 1); i++) out << v[i] << ", ";
    out << v.back();
  }
  out << "]";
  return out;
}
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& v) {
  out << "(" << v.first << ", " << v.second << ")";
  return out;
}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const long long mod = 1000000007;
const int inf = 1 << 30;
const long long linf = 1LL << 60;
const double PI = 3.14159265358979323846;
struct UF {
  vector<int> par, ran;
  void init(int n) {
    par.resize(n);
    ran.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      ran[i] = 0;
    }
  }
  UF(int mx = 0) { init(mx); }
  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 (ran[x] < ran[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (ran[x] == ran[y]) ran[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
struct edge {
  int u, v;
  long long cost;
};
bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int N, E;
edge es[100010];
long long kruskal() {
  sort(es, es + E, comp);
  UF uf(N);
  long long res = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!uf.same(e.u, e.v)) {
      uf.unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}
void add_edge(int s, int t, long long cost) { es[E++] = edge{s, t, cost}; }
struct T {
  pair<long long, long long> v;
  T(pair<long long, long long> v = pair<long long, long long>(linf, -1))
      : v(v) {}
  T operator+(const T& t) { return T(min(v, t.v)); }
  friend ostream& operator<<(ostream& out, const T& t) {
    out << t.v;
    return out;
  }
};
struct segtree {
  int n;
  vector<T> seg;
  void init(int mx) {
    n = 1;
    while (n < mx) n *= 2;
    seg = vector<T>(n * 2);
  }
  segtree(int mx = 0) { init(mx); }
  void update(int i, T x) {
    i += n - 1;
    seg[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      seg[i] = seg[i * 2 + 1] + seg[i * 2 + 2];
    }
  }
  T ga(int a, int b, int k, int l, int r) {
    if (b <= l || r <= a) return T();
    if (a <= l && r <= b)
      return seg[k];
    else {
      T lv = ga(a, b, k * 2 + 1, l, (l + r) / 2);
      T rv = ga(a, b, k * 2 + 2, (l + r) / 2, r);
      return lv + rv;
    }
  }
  void show() {
    vector<T> tmp;
    for (int i = int(0); i < int(n); i++) tmp.push_back(get(i, i + 1));
    Debug(145, ":", tmp);
  }
  T get(int a, int b) { return ga(a, b, 0, 0, n); }
};
long long D;
long long A[MAX_N];
int idx[MAX_N];
void solve() {
  cin >> N >> D;
  for (int i = int(0); i < int(N); i++) cin >> A[i];
  for (int i = int(0); i < int(N); i++) idx[i] = i;
  sort(idx, idx + N, [&](int a, int b) { return A[a] < A[b]; });
  segtree seg1(N);
  segtree seg2(N);
  for (int j = int(0); j < int(N); j++) {
    int i = idx[j];
    pair<long long, long long> lp = seg1.get(0, i).v;
    pair<long long, long long> rp = seg2.get(i + 1, N).v;
    if (lp.first != linf) {
      add_edge(i, lp.second, A[lp.second] + A[i] + D * (i - lp.second));
    }
    if (rp.first != linf) {
      add_edge(i, rp.second, A[i] + A[rp.second] + D * (rp.second - i));
    }
    seg1.update(i, T(pair<long long, long long>(A[i] - D * i, i)));
    seg2.update(i, T(pair<long long, long long>(A[i] + D * i, i)));
  }
  cout << kruskal() << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed;
  cout.precision(20);
  srand((unsigned int)time(NULL));
  solve();
  return 0;
}
