#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17;
struct data {
  int id[2];
  long long c[2];
  void merge(const data &x, const data &y) {
    if (x.c[0] < y.c[0]) {
      id[0] = x.id[0];
      c[0] = x.c[0];
    } else {
      id[0] = y.id[0];
      c[0] = y.c[0];
    }
    if (x.id[0] != id[0]) {
      id[1] = x.id[0];
      c[1] = x.c[0];
    } else if (y.id[0] != id[0]) {
      id[1] = y.id[0];
      c[1] = y.c[0];
    } else {
      id[1] = id[0];
      c[1] = inf;
      if (x.id[1] != id[0]) {
        id[1] = x.id[1];
        c[1] = x.c[1];
      }
      if (y.id[1] != id[0] && c[1] > y.c[1]) {
        id[1] = y.id[1];
        c[1] = y.c[1];
      }
    }
  }
};
struct info {
  long long val;
  int i, j;
  info() {}
  info(long long val, int i, int j) : val(val), i(i), j(j) {}
  bool operator<(const info &x) const { return val < x.val; }
};
data p[200010 * 4];
data q[200010 * 4];
info ans[200010 * 4];
int n;
long long D;
int a[200010];
void build(int c = 1, int b = 1, int e = n) {
  if (b == e) {
    p[c].id[0] = p[c].id[1] = b;
    p[c].c[0] = D * b + a[b];
    p[c].c[1] = inf;
    q[c].id[0] = q[c].id[1] = b;
    q[c].c[0] = -D * b + a[b];
    q[c].c[1] = inf;
    ans[c] = info(inf, b, b);
    return;
  }
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  build(l, b, m);
  build(r, m + 1, e);
  p[c].merge(p[l], p[r]);
  q[c].merge(q[l], q[r]);
  ans[c] = min(ans[l], ans[r]);
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (p[r].id[i] != q[l].id[j]) {
        ans[c] =
            min(ans[c], info(p[r].c[i] + q[l].c[j], q[l].id[j], p[r].id[i]));
        break;
      }
    }
  }
}
void update(int x, int val, int c = 1, int b = 1, int e = n) {
  if (b == e) {
    p[c].id[0] = p[c].id[1] = val;
    p[c].c[0] = D * b + a[b];
    p[c].c[1] = inf;
    q[c].id[0] = q[c].id[1] = val;
    q[c].c[0] = -D * b + a[b];
    q[c].c[1] = inf;
    return;
  }
  int m = (b + e) >> 1;
  int l = c << 1;
  int r = l + 1;
  if (x <= m) {
    update(x, val, l, b, m);
  } else {
    update(x, val, r, m + 1, e);
  }
  p[c].merge(p[l], p[r]);
  q[c].merge(q[l], q[r]);
  ans[c] = min(ans[l], ans[r]);
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (p[r].id[i] != q[l].id[j]) {
        ans[c] =
            min(ans[c], info(p[r].c[i] + q[l].c[j], q[l].id[j], p[r].id[i]));
        break;
      }
    }
  }
}
int par[200010];
vector<int> v[200010];
int root(int x) {
  if (par[x] == x) return x;
  return par[x] = root(par[x]);
}
void join(int p, int q) {
  p = root(p);
  q = root(q);
  if (v[p].size() > v[q].size()) swap(p, q);
  for (auto i : v[p]) {
    v[q].emplace_back(i);
    update(i, q);
  }
  par[p] = q;
  v[p].clear();
}
int main(int argc, char const *argv[]) {
  scanf("%d %lld", &n, &D);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    par[i] = i;
    v[i].emplace_back(i);
  }
  build();
  long long res = 0;
  for (int i = 1; i < n; i++) {
    int x = ans[1].i;
    int y = ans[1].j;
    res += ans[1].val;
    join(x, y);
  }
  printf("%lld\n", res);
  return 0;
}
