#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const long long INF = 1e18;
int n;
long long d, ans;
long long a[maxn], tmp[maxn];
vector<int> vs[maxn];
class SegmentTree {
 private:
  static const int siz = 262144;
  pair<long long, int> dat[siz << 1];

 public:
  inline int size() { return siz; }
  inline void build(int x, int l, int r) {
    if (l == r) {
      if (l < n)
        dat[x] = make_pair(tmp[l], l);
      else
        dat[x] = make_pair(INF, -1);
      return;
    }
    int md = l + r >> 1;
    build(x << 1, l, md);
    build(x << 1 | 1, md + 1, r);
    dat[x] = min(dat[x << 1], dat[x << 1 | 1]);
    return;
  }
  inline void update(int x, int l, int r, int y, long long k) {
    if (l == r) {
      dat[x].first = k;
      return;
    }
    int md = l + r >> 1;
    if (y <= md)
      update(x << 1, l, md, y, k);
    else
      update(x << 1 | 1, md + 1, r, y, k);
    dat[x] = min(dat[x << 1], dat[x << 1 | 1]);
  }
  inline pair<long long, int> query(int x, int l, int r, int s, int t) {
    if (l >= s && r <= t) {
      return dat[x];
    }
    int md = l + r >> 1;
    if (s > md) return query(x << 1 | 1, md + 1, r, s, t);
    if (t <= md) return query(x << 1, l, md, s, t);
    return min(query(x << 1, l, md, s, t), query(x << 1 | 1, md + 1, r, s, t));
  }
} seg1, seg2;
class Dsu {
 private:
  int fa[maxn], sz[maxn];

 public:
  inline void init() {
    for (int i = (0); i < (n); ++i) {
      fa[i] = i;
      sz[i] = 1;
    }
    return;
  }
  inline int find(int x) { return (x == fa[x] ? x : fa[x] = find(fa[x])); }
  inline int size(int x) { return sz[find(x)]; }
  inline bool combine(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (sz[x] < sz[y]) swap(x, y);
    for (int i = (0); i < (vs[y].size()); ++i) vs[x].push_back(vs[y][i]);
    sz[x] += sz[y];
    fa[y] = x;
    return true;
  }
} dsu;
int main() {
  scanf("%d%lld", &n, &d);
  for (int i = (0); i < (n); ++i) {
    scanf("%lld", a + i);
  }
  for (int i = (0); i < (n); ++i) tmp[i] = -i * d + a[i];
  seg1.build(1, 0, seg1.size() - 1);
  for (int i = (0); i < (n); ++i) tmp[i] = i * d + a[i];
  seg2.build(1, 0, seg2.size() - 1);
  dsu.init();
  for (int i = (0); i < (n); ++i) vs[i].push_back(i);
  while (dsu.size(0) != n) {
    vector<pair<pair<int, int>, long long> > ed;
    for (int u = (0); u < (n); ++u)
      if (dsu.find(u) == u) {
        pair<int, int> e;
        long long mn = INF;
        for (int i = (0); i < (vs[u].size()); ++i) {
          int v = vs[u][i];
          seg1.update(1, 0, seg1.size() - 1, v, INF);
          seg2.update(1, 0, seg2.size() - 1, v, INF);
        }
        for (int i = (0); i < (vs[u].size()); ++i) {
          int v = vs[u][i];
          pair<long long, int> res1 = seg1.query(1, 0, seg1.size() - 1, 0, v);
          pair<long long, int> res2 =
              seg2.query(1, 0, seg2.size() - 1, v, n - 1);
          if (res1.first + v * d + a[v] < mn) {
            e = make_pair(v, res1.second);
            mn = res1.first + v * d + a[v];
          }
          if (res2.first - v * d + a[v] < mn) {
            e = make_pair(v, res2.second);
            mn = res2.first - v * d + a[v];
          }
        }
        if (mn != INF) {
          ed.push_back(make_pair(e, mn));
        }
        for (int i = (0); i < (vs[u].size()); ++i) {
          int v = vs[u][i];
          seg1.update(1, 0, seg1.size() - 1, v, -v * d + a[v]);
          seg2.update(1, 0, seg2.size() - 1, v, v * d + a[v]);
        }
      }
    for (int i = (0); i < (ed.size()); ++i)
      ans +=
          (dsu.combine(ed[i].first.first, ed[i].first.second)) * ed[i].second;
  }
  printf("%lld\n", ans);
  return 0;
}
