#include <bits/stdc++.h>
using namespace std;
int minDistance(int dist[], bool sptSet[], int V) {
  int min = INT_MAX, min_index;
  for (int v = 0; v < V; v++)
    if (sptSet[v] == false && dist[v] <= min) min = dist[v], min_index = v;
  return min_index;
}
long calculateSolution(int dist[], int V) {
  long c = 0;
  for (int i = 0; i < V; i++) c += dist[i];
  return c;
}
long dijkstra(vector<int> A, int src, int D, int V) {
  int graph[V][V];
  for (int i = 0; i < V; i++) {
    for (int j = i; j < V; j++) {
      graph[i][j] = abs(i - j) * D + A[i] + A[j];
      graph[j][i] = graph[i][j];
    }
  }
  int dist[V];
  bool sptSet[V];
  for (int i = 0; i < V; i++) dist[i] = INT_MAX, sptSet[i] = false;
  dist[src] = 0;
  for (int count = 0; count < V - 1; count++) {
    int u = minDistance(dist, sptSet, V);
    sptSet[u] = true;
    for (int v = 0; v < V; v++)
      if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX &&
          dist[u] + graph[u][v] < dist[v])
        dist[v] = dist[u] + graph[u][v];
  }
  return calculateSolution(dist, V);
}
int main() {
  int N, D;
  cin >> N >> D;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cout << dijkstra(A, 0, D, N);
  return 0;
}
