#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long long INF = 1e18;
const int N = 1 << 18;
struct SEGTREE {
  pair<long long, int> tree[N * 2];
  long long a[N * 2];
  void modify(int index, long long val) {
    index += N - 1;
    tree[index] = make_pair(val, index - N + 1);
    index >>= 1;
    while (index) {
      tree[index] = min(tree[index << 1], tree[index << 1 | 1]);
      index >>= 1;
    }
  }
  void build() {
    for (int i = N + N - 1; i >= 1; --i) {
      if (i >= N) {
        tree[i].first = a[i - N + 1];
        tree[i].second = i - N + 1;
      } else {
        tree[i] = min(tree[i << 1], tree[i << 1 | 1]);
      }
    }
  }
  pair<long long, int> query(int a, int b, int now = 1, int l = 1,
                             int r = N + 1) {
    if (r <= a || l >= b) {
      return make_pair(INF, INF);
    }
    if (r <= b && l >= a) {
      return tree[now];
    }
    int mid = (l + r) >> 1;
    return min(query(a, b, now << 1, l, mid),
               query(a, b, now << 1 | 1, mid, r));
  }
} tree1, tree2;
int n, d, a[N + 1];
bool cleared[N + 1];
void my_clear(int index) {
  cleared[index] = 1;
  tree1.modify(index, INF);
  tree2.modify(index, INF);
}
int fa[200000 + 1];
vector<int> have[200000 + 1];
int root(int x) {
  if (fa[x] == x) return x;
  return fa[x] = root(fa[x]);
}
void merge(int u, int v) {
  u = root(u);
  v = root(v);
  if (have[u].size() > have[v].size()) {
    for (auto it : have[v]) {
      have[u].push_back(it);
    }
    fa[v] = u;
    have[v].clear();
  } else {
    for (auto it : have[u]) {
      have[v].push_back(it);
    }
    fa[u] = v;
    have[u].clear();
  }
}
vector<pair<int, int> > vv;
vector<int> g[200000 + 1];
bool vis[200000 + 1];
long long cost(int i, int j) { return 1ll * abs(i - j) * d + a[i] + a[j]; }
long long MST() {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  q.push(make_pair(0ll, 1));
  long long rest = 0;
  while (!q.empty()) {
    pair<long long, int> now = q.top();
    if (vis[now.second]) {
      q.pop();
      continue;
    }
    q.pop();
    rest += now.first;
    vis[now.second] = 1;
    for (auto it : g[now.second]) {
      q.push(make_pair(cost(it, now.second), it));
    }
  }
  return rest;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) fa[i] = i, have[i].push_back(i);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    vv.push_back(make_pair(a[i], i));
  }
  memset(tree1.a, 127, sizeof(tree1.a));
  memset(tree2.a, 127, sizeof(tree2.a));
  sort(vv.begin(), vv.end());
  tree1.build();
  tree2.build();
  for (int i = 1; i <= n; ++i) {
    pair<long long, int> best = make_pair(INF, INF);
    if (vv[i - 1].second != 1) {
      pair<long long, int> tmp = tree2.query(1, vv[i - 1].second);
      tmp.first += 1ll * vv[i - 1].second * d + vv[i - 1].first;
      best = tmp;
    }
    if (vv[i - 1].second != n) {
      pair<long long, int> tmp = tree1.query(vv[i - 1].second + 1, n + 1);
      tmp.first += -1ll * vv[i - 1].second * d + vv[i - 1].first;
      best = min(best, tmp);
    }
    if (best.first < 1e15) {
      g[vv[i - 1].second].push_back(best.second);
      g[best.second].push_back(vv[i - 1].second);
    }
    tree1.modify(vv[i - 1].second,
                 1ll * vv[i - 1].second * d + vv[i - 1].first);
    tree2.modify(vv[i - 1].second,
                 -1ll * vv[i - 1].second * d + vv[i - 1].first);
  }
  memset(tree1.a, 127, sizeof(tree1.a));
  memset(tree2.a, 127, sizeof(tree2.a));
  tree1.build();
  tree2.build();
  for (int i = n; i >= 1; --i) {
    pair<long long, int> best = make_pair(INF, INF);
    if (vv[i - 1].second != 1) {
      pair<long long, int> tmp = tree2.query(1, vv[i - 1].second);
      tmp.first += 1ll * vv[i - 1].second * d + vv[i - 1].first;
      best = tmp;
    }
    if (vv[i - 1].second != n) {
      pair<long long, int> tmp = tree1.query(vv[i - 1].second + 1, n + 1);
      tmp.first += -1ll * vv[i - 1].second * d + vv[i - 1].first;
      best = min(best, tmp);
    }
    if (best.first < 1e15) {
      g[vv[i - 1].second].push_back(best.second);
      g[best.second].push_back(vv[i - 1].second);
    }
    tree1.modify(vv[i - 1].second,
                 1ll * vv[i - 1].second * d + vv[i - 1].first);
    tree2.modify(vv[i - 1].second,
                 -1ll * vv[i - 1].second * d + vv[i - 1].first);
  }
  cout << MST() << endl;
  return 0;
}
