#include <bits/stdc++.h>
using namespace std;
long long N, D;
vector<long long> A;
vector<pair<long long, pair<int, int>>> edges;
constexpr long long LARGE(int i) { return (i == 0) ? 1 : (LARGE(i - 1) * 10); }
void addEdges(int l, int r) {
  edges.emplace_back(pair<long long, pair<int, int>>(
      D * abs(l - r) + A[l] + A[r], pair<int, int>(l, r)));
}
void solve(int l, int r) {
  if (l + 1 == r) return;
  int half = (l + r) / 2;
  solve(l, half);
  solve(half, r);
  {
    long long huge = LARGE(10);
    int pos = -1;
    for (int i(half); i < r; ++i) {
      if (i * D + A[i] < huge) {
        huge = i * D + A[i];
        pos = i;
      }
    }
    for (int i(l); i < half; ++i) {
      addEdges(i, pos);
    }
    {
      long long huge = LARGE(10);
      int pos = -1;
      for (int i(l); i < half; ++i) {
        if ((-i) * D + A[i] < huge) {
          huge = (-i) * D + A[i];
          pos = i;
        }
      }
      for (int i(half); i < r; ++i) {
        addEdges(i, pos);
      }
    }
  }
}
int find(vector<pair<int, int>>& v, int i) {
  if (v[i].first != i) v[i].first = find(v, v[i].first);
  return v[i].first;
}
void Union(vector<pair<int, int>>& v, int a, int b) {
  int pa = find(v, a);
  int pb = find(v, b);
  if (v[pa].second < v[pb].second)
    v[pa].first = pb;
  else if (v[pa].second > v[pb].second)
    v[pb].first = pa;
  else {
    v[pb].first = pa;
    v[pa].second += 1;
  }
}
long long mst(vector<pair<long long, pair<int, int>>> e, long long N) {
  vector<pair<int, int>> cities(N);
  long long weight(0);
  for (int n(0); n < N; ++n) {
    cities[n].first = n;
    cities[n].second = 0;
  }
  for (int i(0); i < e.size(); ++i) {
    int a = find(cities, e[i].second.first);
    int b = find(cities, e[i].second.second);
    if (a != b) {
      Union(cities, a, b);
      weight += e[i].first;
    }
  }
  return weight;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> D;
  for (int i(0); i < N; ++i) {
    long long a;
    cin >> a;
    A.push_back(a);
  }
  solve(0, N);
  sort(edges.begin(), edges.end());
  cout << mst(edges, N);
  return 0;
}
