/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;
int n,d,a[202020],ans[202020],res=0,lnk[202020],sze[202020],vis[202020],p[202020];
int fnd(int x){
while(lnk[x]!=x)x=lnk[x];
return x;
}
bool issame(int a, int b){
return fnd(a)==fnd(b);
}
void unite(int a, int b){
a = fnd(a);
b = fnd(b);
if(sze[a]<sze[b])swap(a,b);
lnk[b]=a;
sze[a]+=sze[b];
}
set<int> s;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);

#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif

cin >> n >> d;
for(int i=1;i<n+1;i++){
       cin >> a[i];
       lnk[i]=i;
       sze[i]=1;
}
int pre = 1;
for(int i=2;i<n+1;i++){
       ans[i] = a[pre]+a[i]+(i-pre)*d;
       p[i]=pre;
       if(a[i]<=(i-pre)*d){
              pre=i;
       }
}
pre = n;
for(int i=n-1;i>=1;i--){
       int temp = a[pre]+a[i]+abs(pre-i)*d;
       //ans[i]=min(temp,ans[i]);
       p[i]=pre;
       if(ans[i]>temp){
              unite(i,pre);
              ans[i]=temp;
       }
       else {
              unite(p[i],i);
       }
       if(a[i]<=abs(pre-i)*d){
              pre=i;
       }
       res+=ans[i];
}
res += ans[n];
for(int i=1;i<=n;i++){
       s.insert(fnd(i));
}
//cout << s.size() << endl;
if(s.size()==1){
       cout << res << endl;
       return 0;
}
else {
       assert(s.size()<=2);
       auto it = s.begin();
       int k = fnd(1);
       int rem = 1e18;
       for(int i=1;i<=n;i++){
              if(fnd(i)==k){
                     vis[i]=1;
              }
       }
       pre = 1;
       for(int i=1;i<=n;i++){
              if(!vis[i]){
                     int temp = a[i]+a[pre]+(i-pre)*d;
                     rem = min(rem,temp);
              }
              else {
                     if((i-pre)*d>a[i]){
                            pre=i;
                     }
              }
       }
       pre=-100000000000000;
       for(int i=1;i<=n;i++){
              if(vis[i]&&pre>1){
                     int temp = a[i]+a[pre]+(i-pre)*d;
                     rem = min(rem,temp);
              }
              else {
                            if((i-pre)*d>a[i]){
                            pre=i;
                     }
              }
       }
       cout << res+rem << endl;
}
//cout << res << endl;

return 0;}
///....
