#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define ALL(C) (C).begin(),(C).end()
#define INPUT(P) std::cin>>(P)
#define INPUT2(P1,P2) std::cin>>(P1)>>(P2)
#define INPUT3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INPUTS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUTPUT(P) std::cout<<P<<std::endl
#define OUTPUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUTPUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTPUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using namespace std;
struct Node{
    bool operator<(const struct Node &arg) const{
        return weight < arg.weight;
    };
    ull from,to,weight;
};

ull parent[200000],height[200000];

ull getParent(ull id){
    if(parent[id] == id)return id;
    else{
        return parent[id] = getParent(parent[id]);
    }
}

bool isSame(ull a, ull b){
    return getParent(a) == getParent(b);
}

void unite(ull a,ull b){
    ull a_parent = getParent(a);
    ull b_parent = getParent(b);

    if(a_parent == b_parent)return;

    if(height[a_parent] > height[b_parent]){
        parent[b_parent] = a_parent;
    }else{
        if(height[a_parent] == height[b_parent])height[b_parent]++;
        parent[a_parent] = b_parent;
    }
}

ull i,j,k;
ull N,D;
ull A[200000];
inline void solve(){
  INPUT2(N,D);
  INPUTS(i,N,A);
  Node nodes[N*N];
  for(ull i = 0; i < N; i++){
    parent[i] = i;
    height[i] = 0;
  }
  REP(i,N)REP(j,N){
    nodes[i*N+j].from=i;
    nodes[i*N+j].to=j;
    nodes[i*N+j].weight=abs(i-j)*D+A[i]+A[j];
  }
  sort(nodes,nodes+N*N);

  ull sum = 0;
  for(ull i = 0; i < N*N; i++){
    if(!isSame(nodes[i].from,nodes[i].to)){
      sum += nodes[i].weight;
      unite(nodes[i].from,nodes[i].to);
    }
  }
  OUTPUT(sum);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}
