#include <bits/stdc++.h>
using namespace std;
const int nsz = 2e5;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n;
bool vis[nsz + 5];
long long d, a[nsz + 5], w1[nsz + 5], w2[nsz + 5];
struct segment {
  int u, v;
  pair<long long, int> a1, a2, b1, b2;
  long long res;
  segment() {
    u = v = 0;
    a1 = a2 = b1 = b2 = {inf, 0};
    res = inf;
  }
  segment(pair<long long, int> a1, pair<long long, int> a2,
          pair<long long, int> b1, pair<long long, int> b2) {
    this->a1 = a1, this->a2 = a2, this->b1 = b1, this->b2 = b2;
  }
};
segment inline operator&(const segment &ls, const segment &rs) {
  segment res;
  res.a1 = min(ls.a1, rs.a1);
  res.a2 = min(ls.a2, rs.a2);
  res.b1 = min(ls.b1, rs.b1);
  res.b2 = min(ls.b2, rs.b2);
  if (ls.res < rs.res) {
    res.res = ls.res;
    res.u = ls.u, res.v = ls.v;
  } else {
    res.res = rs.res;
    res.u = rs.u, res.v = rs.v;
  }
  if (ls.a2.first + rs.b1.first < res.res) {
    res.res = ls.a2.first + rs.b1.first;
    res.u = ls.a2.second, res.v = rs.b1.second;
  }
  if (ls.b2.first + rs.a1.first < res.res) {
    res.res = ls.b2.first + rs.a1.first;
    res.u = ls.b2.second, res.v = rs.a1.second;
  }
  return res;
}
struct segment_tree {
  segment tr[4 * nsz + 5];
  void init(long long b1[], long long b2[], int u = 1, int l = 1, int r = n) {
    if (l == r) {
      tr[u] = segment({inf, l}, {inf, l}, {b1[l], l}, {b2[l], l});
      tr[u].res = inf, tr[u].u = 0, tr[u].v = 0;
      return;
    }
    int md = (l + r) >> 1;
    init(b1, b2, (u << 1), l, md);
    init(b1, b2, (u << 1 | 1), md + 1, r);
    tr[u] = tr[(u << 1)] & tr[(u << 1 | 1)];
  }
  void set(int id, long long a1, long long a2, long long b1, long long b2,
           int u = 1, int l = 1, int r = n) {
    if (l == r) {
      tr[u] = segment({a1, l}, {a2, l}, {b1, l}, {b2, l});
      return;
    }
    int md = (l + r) >> 1;
    id <= md ? set(id, a1, a2, b1, b2, (u << 1), l, md)
             : set(id, a1, a2, b1, b2, (u << 1 | 1), md + 1, r);
    tr[u] = tr[(u << 1)] & tr[(u << 1 | 1)];
  }
  segment inline qry_all() { return tr[1]; }
};
segment_tree tr;
long long inline w(int u, int v) {
  if (u < v) swap(u, v);
  return w1[u] + w2[v];
}
long long inline prim(int s = 1) {
  tr.init(w1, w2);
  long long res = 0;
  tr.set(s, w1[s], w2[s], inf, inf);
  vis[s] = 1;
  for (int cnt = 1; cnt <= n - 1; ++cnt) {
    segment cur = tr.qry_all();
    int u = cur.u, v = cur.v;
    if (!vis[u]) tr.set(u, w1[u], w2[u], inf, inf);
    if (!vis[v]) tr.set(v, w1[v], w2[v], inf, inf);
    vis[u] = vis[v] = 1;
    res += cur.res;
  }
  return res;
}
int main() {
  scanf("%d%lld", &n, &d);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    w1[i] = a[i] + d * i;
    w2[i] = a[i] - d * i;
  }
  printf("%lld\n", prim());
}
