#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
struct Tll {
  LL first, second, third;
};
struct Fll {
  LL first, second, third, fourth;
};
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, d[700000], a[200000],
    b[200000];
string str, ss;
bool f[200000];
char c[4000][4000];
int di[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct Edge {
  LL to, cost;
};
struct edge {
  LL from, to, cost;
};
vector<vector<Edge>> vec;
vector<edge> ed;
vector<LL> v;
map<string, LL> ma;
set<LL> st;
void YN(bool f) {
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void yn(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
struct Seg {
  LL n;
  vector<pair<LL, LL>> node;
  Seg(LL n_) {
    n = 1;
    while (n < n_) n *= 2;
    node.resize(n * 2 - 1);
    for (LL i = 0; i < n; i++) node[n + i - 1] = pair<LL, LL>(INF, -1);
    for (LL i = n - 2 - 1; i >= 0; i--) node[i] = pair<LL, LL>(INF, -1);
  }
  void update(LL i, LL x) {
    LL y = i;
    i = i + n - 1;
    node[i] = pair<LL, LL>(x, y);
    while (i > 0) {
      i = (i - 1) / 2;
      node[i] =
          (node[i * 2 + 1].first < node[i * 2 + 2].first ? node[i * 2 + 1]
                                                         : node[i * 2 + 2]);
    }
  }
  pair<LL, LL> find(LL l, LL r) { return find(0, 0, n - 1, l, r); }
  pair<LL, LL> find(LL i, LL a, LL b, LL l, LL r) {
    if (b < l || r < a) return pair<LL, LL>(INF, -1);
    if (l <= a && b <= r) return node[i];
    pair<LL, LL> x = find(i * 2 + 1, a, (a + b) / 2, l, r),
                 y = find(i * 2 + 2, (a + b + 1) / 2, b, l, r);
    return (x.first < y.first ? x : y);
  }
};
Seg l(200000), r(200000);
int par[200000];
int find(int x) {
  if (par[x] == x) return x;
  par[x] = find(par[x]);
  return par[x];
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  par[x] = y;
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  cin >> n >> m;
  for (LL i = 0; i < n; i++) {
    cin >> a[i];
    l.update(i, a[i] - m * i);
    r.update(i, a[i] + m * i);
  }
  for (int i = 0; i < n; i++) par[i] = i;
  for (LL i = 0; i < n; i++) {
    pair<LL, LL> x = l.find(0, i - 1), y = r.find(i + 1, n - 1);
    if (i - 1 >= 0) ed.push_back(edge{i, x.second, x.first + m * i + a[i]});
    if (i + 1 <= n - 1) ed.push_back(edge{i, y.second, y.first - m * i + a[i]});
  }
  sort(ed.begin(), ed.end(), [](edge x, edge y) { return x.cost < y.cost; });
  for (LL i = 0; i < ed.size(); i++) {
    edge e = ed[i];
    if (!same(e.from, e.to)) {
      ans += e.cost;
      unite(e.from, e.to);
    }
  }
  cout << ans << endl;
  return 0;
}
