#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <numeric>

using LL = long long;
const int kN = 200000 + 5;
const LL inf = 1e17;
int n, d;
int a[kN];
int group[kN];

int find(int x) {
  return group[x] == x ? x : group[x] = find(group[x]);
}

int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; ++ i) {
    scanf("%d", a + i);
  }
  std::iota(group, group + n, 0);
  LL result = 0;
  while (true) {
    if ([&]() {
      for (int i = 1; i < n; ++ i)
        if (find(i) != find(0))
          return false;
      return true;
    }()) {
      break;
    }
    using Pair = std::pair<LL, int>;
    using Set = std::set<Pair>;
    std::vector<Set> incs(n), decs(n);
    Set inc, dec;
    for (int i = 0; i < n; ++ i) {
      int g = find(i);
      incs[g].emplace(a[i] + i * 1LL * d, i);
    }
    for (int g = 0; g < n; ++ g) if (!incs[g].empty()) {
      inc.emplace(incs[g].begin()->first, g);
    }
    std::vector<Pair> bests(n, std::make_pair(inf, -1));
    for (int i = 0; i < n; ++ i) {
      int g = find(i);

      inc.erase(std::make_pair(incs[g].begin()->first, g));
      incs[g].erase(std::make_pair(a[i] + i * 1LL * d, i));
      if (!incs[g].empty()) {
        inc.emplace(incs[g].begin()->first, g);
      }

      if (!decs[g].empty()) {
        dec.erase(std::make_pair(decs[g].begin()->first, g));
      }
      decs[g].emplace(a[i] + (n - 1 - i) * 1LL * d, i);
      dec.emplace(decs[g].begin()->first, g);

      if (!inc.empty()) {
        auto it = inc.begin();
        if (it->second == g) ++ it;
        if (it != inc.end()) {
          int p = it->second;
          int j = incs[p].begin()->second;
          LL cost = a[i] + a[j] + std::abs(i - j) * 1LL * d;
          bests[g] = std::min(bests[g], std::make_pair(cost, p));
        }
      }
      if (!dec.empty()) {
        auto it = dec.begin();
        if (it->second == g) ++ it;
        if (it != dec.end()) {
          int p = it->second;
          int j = decs[p].begin()->second;
          LL cost = a[i] + a[j] + std::abs(i - j) * 1LL * d;
          bests[g] = std::min(bests[g], std::make_pair(cost, p));
        }
      }
    }
    for (int g = 0; g < n; ++ g) if (bests[g].second != -1) {
      int a = find(g);
      int b = find(bests[g].second);
      if (a != b) {
        result += bests[g].first;
        group[a] = b;
      }
    }
  }
  printf("%lld\n", result);
}