#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 = 300000;

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> a(n+1);
  rep(i, n) {
    cin >> a[i+1];
  }

  B.init(n);
  C.init(n);

  unordered_map<ll, int> mpb;
  for(int i=2; i<=n; i++) {
    ll tmp = a[i]+i*d;
    B.update(i, tmp);
    mpb[tmp] = i;
  }
  unordered_map<ll, int> mpc;
  for(int i=n-1; i>=1; i--) {
    ll tmp = a[i]+(n-i)*d;
    C.update(i, tmp);
    mpc[tmp] = i;
  }

  for(int i=1; i<=n; i++) {
    if (i>1) {
      //debugln("C");
      ll tmp = C.query(1, i);
      int pos = mpc[tmp];
      ll cost = a[i] + a[pos] + abs(i-pos)*d;
      graph[i].push_back(P(cost, pos));
      graph[pos].push_back(P(cost, i));
      //debug(i); debug(pos); debugln(cost);
    }
    if (i<n) {
      //debugln("B");
      ll tmp = B.query(i+1,n+1);
      int pos = mpb[tmp];
      ll cost = a[i] + a[pos] + abs(i-pos)*d;
      graph[i].push_back(P(cost, pos));
      graph[pos].push_back(P(cost, i));
      //debug(i); debug(pos); debugln(cost);
    }
  }

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