#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);

const ll INF = 1LL << 60;
int const MAXN = 270000;

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

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

  // update i-th element
  void update(int i, long long a) {
    i += N-1;
    dat[i] = a;
    while(i > 0) {
      i = (i-1)/2;
      dat[i] = min(dat[i*2+1], dat[i*2+2]);
    }
  }

  // return min[a, b)
  long long query(int a, int b) {
    return query(a, b, 0, 0, N);
  }
  long long query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return LONG_MAX;
    if (a <= l && r <= b) {
      return dat[k];
    }
    int m = (l+r)/2;
    return min(query(a, b, k*2+1, l, m), 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<ll> orig(n+1);
  vector<P> a(n+1);
  a[0] = P(0,0);
  for(int i=1; i<=n; i++) {
    ll tmp; cin >> tmp;
    orig[i] = tmp;
    a[i] = P(tmp, i);
  }
  sort(a.begin(), a.end());

  B.init(n); // left
  C.init(n); // right
  multimap<ll, int> mpb;
  multimap<ll, int> mpc;

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

    ll rightcost = C.query(pos+1, n+1);
    if (rightcost != LONG_MAX) {
      auto range = mpc.equal_range(rightcost);
      auto it = range.first;
      while(it != range.second) {
        int rightpos = -(*it).second;
        if (pos < rightpos) {
          rightcost = cost + orig[rightpos] + abs(pos - rightpos)*d;
          //debug(i); debug(right); debugln(rightcost);
          graph[pos].push_back(P(rightcost, rightpos));
          graph[rightpos].push_back(P(rightcost, pos));
          break;
        }
        ++it;
      }
    }

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

  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;
}


Measured memory_bytes: 69872