#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

int const MAXN = 270000;

struct {
  int N;
  vector<P> dat = vector<P>(2*MAXN);

  void init(int n) {
    N = 1;
    while(N < n) N *= 2;
    for(int i=0; i<2*N-1; i++) {
      dat[i] = P(LONG_MAX, 0);
    }
  }

  // update i-th element
  void update(int i, P a) {
    i += N-1;
    dat[i] = a;
    while(i > 0) {
      i = (i-1)/2;
      if (dat[i*2+1].first < dat[i*2+2].first) {
        dat[i] = dat[i*2+1];
      } else {
        dat[i] = dat[i*2+2];
      }
    }
  }

  // return min[a, b)
  P query(int a, int b) {
    return query(a, b, 0, 0, N);
  }
  P query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return P(LONG_MAX, 0);
    if (a <= l && r <= b) {
      return dat[k];
    }
    int m = (l+r)/2;

    if (query(a,b,k*2+1,l,m).first < query(a,b,k*2+2,m,r).first) {
      return query(a,b,k*2+1,l,m);
    } else {
      return query(a,b,k*2+2,m,r);
    }
  }

} B, C;

vector<P> graph[200005];
vector<bool> used(200005);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  ll d; cin >> d;
  vector<P> a(n+1);
  a[0] = P(0,0);
  for(int i=1; i<=n; i++) {
    ll tmp; cin >> tmp;
    a[i] = P(tmp, i);
  }
  sort(a.begin(), a.end());

  B.init(n); // left
  C.init(n); // right

  for(int i=1; i<=n; i++) {
    int pos = a[i].second;
    ll cost = a[i].first;
    P p = B.query(1, pos);
    if (p.first != LONG_MAX) {
      int left = p.second;
      ll leftcost = cost + a[left].first + abs(pos - a[left].second)*d;
      //debug(i); debug(left); debugln(leftcost);
      graph[i].push_back(P(leftcost, left));
      graph[left].push_back(P(leftcost, i));
    }

    p = C.query(pos+1, n+1);
    if (p.first != LONG_MAX) {
      int right = p.second;
      ll rightcost = cost + a[right].first + abs(pos - a[right].second)*d;
      //debug(i); debug(right); debugln(rightcost);
      graph[i].push_back(P(rightcost, right));
      graph[right].push_back(P(rightcost, i));
    }

    ll bcost = cost + (n-pos)*d;
    ll ccost = cost + pos*d;
    B.update(pos, P(bcost,i));
    C.update(pos, P(ccost,i));
  }

  priority_queue<P, vector<P>, greater<>> que;
  for(auto e: graph[1]) {
    que.push(e);
  }
  used[1] = true;
  ll ans = 0;
  while(!que.empty()) {
    P p = que.top(); que.pop();
    ll cost = p.first;
    int pos = p.second;
    if (used[pos]) continue;
    used[pos] = true;
    ans += cost;
    for(auto e: graph[pos]) {
      if (used[e.second]) continue;
      que.push(e);
    }
  }

  cout << ans << endl;
}
