#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T>
class segtree {
 private:
  int n, sz;
  vector<pair<T, int>> node;

 public:
  segtree(vector<T>& v) : sz((int)v.size()) {
    n = 1;
    while (n < sz) {
      n *= 2;
    }
    node.resize(2 * n, make_pair(numeric_limits<T>::max(), sz));
    for (int i = 0; i < sz; i++) {
      node[i + n] = make_pair(v[i], i);
    }
    for (int i = n - 1; i >= 1; i--) {
      node[i] = min(node[2 * i], node[2 * i + 1]);
    }
  }
  void update(int k, T a) {
    node[k + n] = make_pair(a, k);
    k += n;
    while (k >>= 1) {
      node[k] = min(node[2 * k], node[2 * k + 1]);
    }
  }
  pair<T, int> query(int a, int b, int k = 0, int l = 0, int r = -1) {
    pair<T, int> res1 = make_pair(numeric_limits<T>::max(), sz);
    pair<T, int> res2 = make_pair(numeric_limits<T>::max(), sz);
    a += n, b += n;
    while (a != b) {
      if (a % 2) res1 = min(res1, node[a++]);
      if (b % 2) res2 = min(res2, node[--b]);
      a >>= 1, b >>= 1;
    }
    return min(res1, res2);
  }
  void print() {
    for (int i = 0; i < sz; i++) {
      pair<T, int> p;
      p = query(i, i + 1);
      cout << "st[" << i << "]: " << p.first << " " << p.second << endl;
    }
  }
};
class UnionFind {
 private:
  int sz;
  vector<int> par, nrank;

 public:
  UnionFind() {}
  UnionFind(int node_size) : sz(node_size), par(sz), nrank(sz, 0) {
    iota(par.begin(), par.end(), 0);
  }
  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 (nrank[x] < nrank[y]) swap(x, y);
    par[y] = x;
    if (nrank[x] == nrank[y]) nrank[x]++;
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
struct edge {
  int a, b;
  ll cost;
  edge(int a, int b, ll cost) : a(a), b(b), cost(cost) {}
};
bool operator<(const edge& a, const edge& b) { return a.cost < b.cost; }
int main() {
  int n;
  ll d;
  cin >> n >> d;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> a(n);
  vector<ll> vec1(n), vec2(n);
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a[i];
    vec1[i] = a[i] - i * d;
    vec2[i] = a[i] + i * d;
  }
  segtree<ll> seg1(vec1), seg2(vec2);
  vector<edge> e;
  const ll inf = 1LL << 60;
  const int sz = 15;
  for (int i = 0; i < (int)(n); ++i) {
    if (i == 0) {
      vector<pair<int, ll>> b;
      for (int j = 0; j < (int)(sz); ++j) {
        auto x = seg2.query(1, n);
        e.emplace_back(i, x.second, x.first - i * d + a[i]);
        seg2.update(x.second, inf);
        b.emplace_back(x.second, x.first);
      }
      for (int j = 0; j < (int)(sz); ++j) {
        seg2.update(b[j].first, b[j].second);
      }
    } else if (i == n - 1) {
      vector<pair<int, ll>> b;
      for (int j = 0; j < (int)(sz); ++j) {
        auto x = seg1.query(0, n - 1);
        e.emplace_back(i, x.second, x.first + i * d + a[i]);
        seg1.update(x.second, inf);
        b.emplace_back(x.second, x.first);
      }
      for (int j = 0; j < (int)(sz); ++j) {
        seg1.update(b[j].first, b[j].second);
      }
    } else {
      {
        vector<pair<int, ll>> b;
        for (int j = 0; j < (int)(sz); ++j) {
          auto x = seg2.query(i + 1, n);
          e.emplace_back(i, x.second, x.first - i * d + a[i]);
          seg2.update(x.second, inf);
          b.emplace_back(x.second, x.first);
        }
        for (int j = 0; j < (int)(sz); ++j) {
          seg2.update(b[j].first, b[j].second);
        }
      }
      {
        vector<pair<int, ll>> b;
        for (int j = 0; j < (int)(sz); ++j) {
          auto x = seg1.query(0, i);
          e.emplace_back(i, x.second, x.first + i * d + a[i]);
          seg1.update(x.second, inf);
          b.emplace_back(x.second, x.first);
        }
        for (int j = 0; j < (int)(sz); ++j) {
          seg1.update(b[j].first, b[j].second);
        }
      }
    }
  }
  sort(e.begin(), e.end());
  UnionFind uf(n);
  ll ans = 0;
  for (auto& x : e) {
    if (!uf.same(x.a, x.b)) {
      ans += x.cost;
      uf.unite(x.a, x.b);
    }
  }
  cout << ans << endl;
}
