#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
void qread(int &x) {
  int neg = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar();
  x *= neg;
}
const int maxn = 400005;
int n, d, tot;
int a[maxn];
long long ans;
class Edge {
 public:
  int u, v;
  long long w;
  Edge(int _u = 0, int _v = 0, long long _w = 0) : u(_u), v(_v), w(_w) {}
  bool operator<(const Edge &o) const { return w < o.w; }
} e[maxn];
namespace Dsu {
int f[maxn];
void init() {
  for (int(i) = 1; (i) <= n; i++) f[i] = i;
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
}  // namespace Dsu
int main() {
  scanf("%d%d", &n, &d);
  for (int(i) = 1; (i) <= n; i++) scanf("%d", &a[i]);
  pair<long long, int> mn = make_pair(1e18, 0);
  for (int(i) = 1; (i) <= n; i++) {
    if (i > 1) e[++tot] = Edge(mn.second, i, mn.first + 1LL * i * d + a[i]);
    mn = min(mn, make_pair(-1LL * i * d + a[i], i));
  }
  mn = make_pair(1e18, 0);
  for (int i = n; i >= 1; i--) {
    if (i < n) e[++tot] = Edge(i, mn.second, mn.first - 1LL * i * d + a[i]);
    mn = min(mn, make_pair(1LL * i * d + a[i], i));
  }
  sort(e + 1, e + 1 + tot);
  Dsu::init();
  for (int(i) = 1; (i) <= tot; i++) {
    int u = Dsu::find(e[i].u), v = Dsu::find(e[i].v);
    if (u == v) continue;
    Dsu::f[u] = v;
    ans += e[i].w;
  }
  printf("%lld\n", ans);
  return 0;
}
