#include <bits/stdc++.h>
struct Edge {
  int node1;
  int node2;
  long long cost;
};
class Union_Find {
 public:
  std::vector<int> par;
  Union_Find() {}
  Union_Find(int n) {
    par.resize(n, 0);
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }
  void simplify(int x) {
    std::vector<int> path;
    while (par[x] != x) {
      path.push_back(x);
      x = par[x];
    }
    for (int p : path) {
      par[p] = x;
    }
  }
  int find(int x) {
    simplify(x);
    return par[x];
  }
};
const int MAX_N = 200050;
int N;
long long D, A[MAX_N];
int right_path[MAX_N] = {};
int left_path[MAX_N] = {};
Union_Find uf = Union_Find(MAX_N);
long long total_cost = 0;
void unite(int x, int y, long long cost) {
  x = uf.find(x);
  y = uf.find(y);
  if (x != y) {
    uf.par[y] = x;
    total_cost += cost;
  }
}
int main(int argc, char** argv) {
  std::cin >> N >> D;
  for (int i = 1; i <= N; i++) {
    std::cin >> A[i];
  }
  std::vector<std::pair<int, long long>> right_cand, left_cand;
  for (int i = 1; i <= N; i++) {
    right_cand.push_back(std::pair<int, long long>({i, A[i] + D * i}));
    left_cand.push_back(std::pair<int, long long>({i, A[i] - D * i}));
  }
  std::sort(
      right_cand.begin(), right_cand.end(),
      [](const std::pair<int, long long>& a,
         const std::pair<int, long long>& b) { return a.second < b.second; });
  std::sort(
      left_cand.begin(), left_cand.end(),
      [](const std::pair<int, long long>& a,
         const std::pair<int, long long>& b) { return a.second < b.second; });
  int begin = 1;
  for (auto pair : right_cand) {
    while (begin < pair.first) {
      right_path[begin] = pair.first;
      begin++;
    }
  }
  begin = N;
  for (auto pair : left_cand) {
    while (pair.first < begin) {
      left_path[begin] = pair.first;
      begin--;
    }
  }
  std::vector<Edge> graph;
  for (int i = 1; i <= N; i++) {
    if (i < N) {
      Edge e;
      e.node1 = i;
      e.node2 = right_path[i];
      e.cost = D * (right_path[i] - i) + A[i] + A[right_path[i]];
      graph.push_back(e);
    }
    if (1 < i) {
      Edge e;
      e.node1 = i;
      e.node2 = left_path[i];
      e.cost = D * (i - left_path[i]) + A[i] + A[left_path[i]];
      graph.push_back(e);
    }
  }
  std::sort(graph.begin(), graph.end(),
            [](const Edge& a, const Edge& b) { return a.cost < b.cost; });
  for (auto e : graph) {
    unite(e.node1, e.node2, e.cost);
  }
  std::cout << total_cost << std::endl;
  return 0;
}
