#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e15;
class Unionfind {
 public:
  vector<int> par, rank;
  Unionfind(int n) {
    par.resize(n);
    rank.resize(n);
    for (int(i) = (0); (i) < (n); (i)++) {
      par[i] = i;
      rank[i] = 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 (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); }
};
struct RMQ {
  vector<pair<ll, int> > node;
  int n = 1;
  void init(int x) {
    while (n < x) {
      n *= 2;
    }
    node.resize(4 * n, {1000000000000000, -1});
  }
  void update(int s, ll x) {
    int i = s + n - 1;
    node[i].first = x;
    node[i].second = s;
    while (i > 0) {
      i = (i - 1) / 2;
      node[i].first = min(node[2 * i + 1].first, node[2 * i + 2].first);
      if (node[2 * i + 1].first > node[2 * i + 2].first)
        node[i].second = node[2 * i + 2].second;
      else
        node[i].second = node[2 * i + 1].second;
    }
  }
  pair<ll, int> getMin(int a, int b) { return getMin(a, b, 0, 0, n - 1); }
  pair<ll, int> getMin(int a, int b, int k, int l, int r) {
    if (r < a || b < l) return make_pair<ll, int>(1e15, -1);
    if (a <= l && r <= b) {
      return node[k];
    } else {
      pair<ll, int> vl = getMin(a, b, 2 * k + 1, l, (l + r) / 2);
      pair<ll, int> vr = getMin(a, b, 2 * k + 2, (l + r) / 2 + 1, r);
      if (vl.first > vr.first) return vr;
      return vl;
    }
  }
};
struct edge {
  int u, v;
  ll cost;
};
bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
vector<edge> es;
int main() {
  int n;
  ll d;
  cin >> n >> d;
  if (n <= 1) {
    cout << "0" << endl;
    return 0;
  }
  RMQ seg, seg2;
  seg.init(n);
  seg2.init(n);
  Unionfind uf(n);
  vector<ll> A(n);
  for (int(i) = (0); (i) < (n); (i)++) {
    cin >> A[i];
    seg.update(i, A[i] + i * d);
    seg2.update(i, A[i] + (n - i - 1) * d);
  }
  es.push_back(
      {0, seg.getMin(1, n - 1).second, seg.getMin(1, n - 1).first + A[0]});
  for (int(i) = (1); (i) < (n); (i)++) {
    es.push_back({i, seg2.getMin(0, i - 1).second,
                  seg2.getMin(0, i - 1).first + A[i] - (n - i - 1) * d});
    if (i < n - 1) {
      es.push_back({i, seg.getMin(i + 1, n - 1).second,
                    seg.getMin(i + 1, n - 1).first + A[i] - i * d});
    }
  }
  sort(es.begin(), es.end(), comp);
  ll res = 0;
  for (int(i) = (0); (i) < (es.size()); (i)++) {
    edge e = es[i];
    if (!uf.same(e.u, e.v)) {
      uf.unite(e.u, e.v);
      res += e.cost;
    }
  }
  cout << res << endl;
}
