#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "{";
  for (long long i = 0; i < (long long)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
long long q, m, n, k, res, tmp, tmp2, tmp3;
vector<pair<long long, long long>> a;
long long dist[100002];
deque<pair<long long, long long>> que;
string s;
vector<pair<long long, long long>> g[200010];
long long d;
class UnionFind {
 private:
  long long n;
  vector<long long> uni;

 public:
  UnionFind(long long _n) {
    n = _n;
    uni.clear();
    uni.resize(n, -1);
  }
  long long root(long long x) {
    if (uni[x] < 0) return x;
    return uni[x] = root(uni[x]);
  }
  bool same(long long x, long long y) { return root(x) == root(y); }
  void unite(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (uni[x] > uni[y]) swap(x, y);
    uni[x] += uni[y];
    uni[y] = x;
  }
  long long getSize(long long x) { return -uni[root(x)]; }
  void print() {
    for (auto x : uni) cout << x << " ";
    cout << endl;
  }
};
class SegmentTree {
  const static long long inf = (1LL << 31) - 1;
  long long N, N0;
  long long data[4 * 200005][2];

 public:
  SegmentTree(long long N) {
    N0 = 1;
    while (N0 < N) N0 <<= 1;
    for (long long j = 0; j < 2; j++) {
      for (long long i = 0; i < 2 * N0 + 4; i++) {
        data[i][j] = inf;
      }
    }
  }
  void update(long long k, long long x, long long y) {
    k += N0 - 1;
    data[k][0] = x;
    data[k][1] = y;
    while (k > 0) {
      k = (k - 1) / 2;
      if (data[2 * k + 1][0] > data[2 * k + 2][0]) {
        data[k][0] = data[2 * k + 2][0];
        data[k][1] = data[2 * k + 2][1];
      } else {
        data[k][0] = data[2 * k + 1][0];
        data[k][1] = data[2 * k + 1][1];
      }
    }
  }
  tuple<long long, long long> __query(long long a, long long b, long long k,
                                      long long l, long long r) {
    if (a <= l && r <= b) {
      return forward_as_tuple(data[k][0], data[k][1]);
    }
    if (r <= a || b <= l) {
      return forward_as_tuple(inf, inf);
    }
    long long lv, lc, rv, rc;
    tie(lv, lc) = __query(a, b, 2 * k + 1, l, (l + r) / 2);
    tie(rv, rc) = __query(a, b, 2 * k + 2, (l + r) / 2, r);
    if (lv > rv)
      return forward_as_tuple(rv, rc);
    else
      return forward_as_tuple(lv, lc);
  }
  tuple<long long, long long> query(long long a, long long b) {
    return __query(a, b, 0, 0, N0);
  }
  void print() {
    for (long long i = 0; i < N0; i++)
      cout << data[i][0] << " " << data[i][1] << " ";
    cout << endl;
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cin >> n >> d;
  for (long long i = 0; i < n; i++) {
    cin >> tmp;
    a.push_back({tmp, i});
  }
  vector<pair<long long, long long>> b = a;
  sort((a).begin(), (a).end());
  res = 0;
  UnionFind UF(n);
  SegmentTree STR(n);
  SegmentTree STL(n);
  vector<pair<long long, pair<long long, long long>>> kore;
  long long inf = (1LL << 31) - 1;
  for (long long i = 0; i < n; i++) {
    pair<long long, long long> c = a[i];
    STL.update(c.second, c.first + (n - c.second) * d, c.second);
    STR.update(c.second, c.first + c.second * d, c.second);
  }
  sort((a).rbegin(), (a).rend());
  for (long long i = 0; i < n; i++) {
    pair<long long, long long> c = a[i];
    long long hi1, hi2, mi1, mi2;
    tie(hi1, hi2) = STL.query(0, c.second);
    tie(mi1, mi2) = STR.query(c.second, n);
    if (hi2 != inf) {
      kore.push_back({b[c.second].first + d * (-hi2 + c.second) + b[hi2].first,
                      {c.second, hi2}});
    }
    if (mi2 != inf) {
      kore.push_back({b[c.second].first + d * (mi2 - c.second) + b[mi2].first,
                      {c.second, mi2}});
    }
  }
  sort((kore).begin(), (kore).end());
  for (auto i : kore) {
    if (UF.same(i.second.first, i.second.second)) {
      continue;
    }
    UF.unite(i.second.first, i.second.second);
    res += i.first;
  }
  cout << res << endl;
}
