#include <bits/stdc++.h>
using namespace std;
class UnionFind {
  vector<int> par, sz;

 public:
  UnionFind() {}
  UnionFind(int n) {
    par = sz = vector<int>(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      sz[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sz[x] > sz[y]) {
      par[y] = x;
      sz[x] += sz[y];
    } else {
      par[x] = y;
      sz[y] += sz[x];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sz[find(x)]; }
};
int n;
long long d;
long long a[300000];
UnionFind uf;
vector<pair<long long, int> > loop(bool b) {
  map<int, long long> mp;
  set<pair<long long, int> > se;
  vector<pair<long long, int> > res;
  for (int i = 0; i < (n); i++) {
    int id = (b ? n - i - 1 : i);
    if (se.empty()) {
      res.push_back(pair<long long, int>(0x3f3f3f3f3f3f3f3f, -1));
    } else {
      auto it = se.begin();
      while (it != se.end() && it->second == uf.find(id)) it++;
      if (it != se.end()) {
        res.push_back(
            pair<long long, int>(d * i + it->first + a[i], it->second));
      } else {
        res.push_back(pair<long long, int>(0x3f3f3f3f3f3f3f3f, -1));
      }
    }
    long long cost = -i * d + a[i];
    if (!mp.count(uf.find(id)) || cost < mp[uf.find(id)]) {
      if (mp.count(uf.find(id)))
        se.erase(pair<long long, int>(mp[uf.find(id)], uf.find(id)));
      mp[uf.find(id)] = cost;
      se.insert(pair<long long, int>(cost, uf.find(id)));
    }
  }
  return res;
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < (n); i++) scanf("%lld", &a[i]);
  uf = UnionFind(n);
  long long ans = 0;
  while (uf.size(0) != n) {
    auto res = loop(0);
    for (int i = 0; i < (n / 2); i++) swap(a[i], a[n - i - 1]);
    auto res2 = loop(1);
    for (int i = 0; i < (n / 2); i++) {
      swap(a[i], a[n - i - 1]);
      swap(res2[i], res2[n - i - 1]);
    }
    map<int, pair<long long, int> > mp;
    for (int i = 0; i < (n); i++) {
      if (!mp.count(uf.find(i)) || mp[uf.find(i)] > res[i]) {
        mp[uf.find(i)] = res[i];
      }
      if (!mp.count(uf.find(i)) || mp[uf.find(i)] > res2[i]) {
        mp[uf.find(i)] = res2[i];
      }
    }
    for (auto p : mp) {
      if (p.second.first == 0x3f3f3f3f3f3f3f3f) continue;
      if (!uf.same(p.first, p.second.second)) {
        uf.unite(p.first, p.second.second);
        ans += p.second.first;
      }
    }
  }
  cout << ans << endl;
}
