#include <bits/stdc++.h>
using namespace std;
int fa[200005], n;
long long ans, a[200005], m;
struct node {
  int L, R;
  long long val;
  node(long long x, int y, int z) { val = x, L = y, R = z; }
  bool operator<(const node &x) const {
    if (val != x.val) return val < x.val;
    if (L != x.L) return L < x.L;
    return R < x.R;
  }
};
int search(int x) {
  if (fa[x] == x) return x;
  return fa[x] = search(fa[x]);
}
vector<node> v;
void solve(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1, min_l, mn = -1, min_r;
  for (int i = l; i <= mid; i++) {
    long long value = a[i] - m * (long long)i;
    if (mn == -1 || mn > value) min_l = i, mn = value;
  }
  mn = -1;
  for (int i = mid + 1; i <= r; i++) {
    long long value = a[i] + m * (long long)i;
    if (mn == -1 || mn > value) min_r = i, mn = value;
    long long tmp = a[i] + a[min_l] + m * (long long)(i - min_l);
    v.push_back(node(tmp, min_l, i));
  }
  for (int i = l; i <= mid; i++) {
    long long tmp = a[i] + a[min_r] + m * (long long)(min_r - i);
    v.push_back(node(tmp, i, min_r));
  }
  solve(l, mid);
  solve(mid + 1, r);
}
int main() {
  for (int i = 0; i < 200005; i++) fa[i] = i;
  scanf("%d%lld", &n, &m);
  for (int i = 0; i < n; i++) scanf("%lld", a + i);
  solve(0, n - 1);
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    int x = search(v[i].L), y = search(v[i].R);
    if (x == y) continue;
    ans += v[i].val;
    fa[x] = y;
  }
  printf("%lld\n", ans);
  return 0;
}
