#include <bits/stdc++.h>
using namespace std;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T, class Y>
ostream& operator<<(ostream& o, const pair<T, Y>& p) {
  return o << "(" << p.first << ", " << p.second << ")";
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& v) {
  fill((T*)array, (T*)(array + N), v);
}
__int128_t gcd(__int128_t a, __int128_t b, __int128_t& x, __int128_t& y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  __int128_t d = gcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
long long gcd(long long a, long long b) {
  __int128_t x = 0, y = 0;
  return gcd(a, b, x, y);
}
long long modPow(__int128_t a, __int128_t n, long long m) {
  if (!a) return a;
  __int128_t p = 1;
  for (; n > 0; n >>= 1, a = a * a % m)
    if (n & 1) p = p * a % m;
  return (long long)p;
}
bool isPrime(long long n) {
  if (n < 2 || n % 2 == 0) return n == 2;
  __int128_t t = n - 1, d = t / (t & -t);
  for (__int128_t a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022})
    if (a % n) {
      for (t = d, a = modPow(a, t, n); t != n - 1 && a != 1 && a != n - 1;
           a = a * a % n, t = t * 2 % n)
        ;
      if (a != n - 1 && t % 2 == 0) return 0;
    }
  return 1;
}
void dout(double d) { printf("%.12f\n", d); }
const int IINF = 1e9 + 6;
const long long LINF = 1e18;
const int MOD = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());
const int N = 2e5;
struct UnionFind {
  vector<int> p;
  int g;
  void init(int n) {
    p = vector<int>(n, -1);
    g = n;
  }
  int find(int a) { return p[a] < 0 ? a : p[a] = find(p[a]); }
  bool merge(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return 0;
    g--;
    if (p[a] > p[b]) swap(a, b);
    p[a] += p[b];
    p[b] = a;
    return 1;
  }
} uf;
V<pair<long long, pair<int, int>>> v;
int n;
long long a[N], d;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> d;
  for (int i = (0); i < (n); i++) cin >> a[i];
  {
    long long mi = a[0];
    int idx = 0;
    for (int i = (1); i < (n); i++) {
      v.push_back(
          make_pair(a[idx] + a[i] + d * abs(i - idx), make_pair(i, idx)));
      long long t = a[i] - d * i;
      if (t < mi) {
        mi = t;
        idx = i;
      }
    }
  }
  {
    long long mi = a[n - 1];
    int idx = n - 1;
    for (int i = (n - 2); i >= (0); i--) {
      v.push_back(
          make_pair(a[idx] + a[i] + d * abs(i - idx), make_pair(i, idx)));
      long long t = a[i] - d * (n - 1 - i);
      if (t < mi) {
        mi = t;
        idx = i;
      }
    }
  }
  sort((v.begin()), (v.end()));
  uf.init(n);
  long long ans = 0;
  for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
    if (uf.merge(itr->second.first, itr->second.second)) ans += itr->first;
  cout << ans << endl;
}
