using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static long[,,] dat;
	static int m=1;
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long[] a=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long ans=0;

		int n=s[0];
		while(m<=n){m*=2;}
		dat=new long[m+n-1,2,2];

		for(int i=0;i<m+n-1;i++){
			dat[i,0,0]=long.MaxValue;
			dat[i,1,0]=long.MaxValue;
		}
		for(int i=0;i<s[0];i++){
			fdu(i,a[i]+i*s[1],0);
			fdu(i,a[i]+(s[0]-i-1)*s[1],1);
		}
		long[] q=fdg(1,n-1,0,0,m-1,0);
		hpa(a[0]+a[(int)q[1]]+q[1]*s[1],0,(int)q[1]);
		q=fdg(0,n-2,0,0,m-1,1);
		hpa(a[n-1]+a[(int)q[1]]+(n-1-q[1])*s[1],n-1,(int)q[1]);
		for(int i=1;i<s[0]-1;i++){
			q=fdg(i+1,n-1,0,0,m-1,0);
			hpa(a[i]+a[(int)q[1]]+(q[1]-i)*s[1],i,(int)q[1]);
			q=fdg(0,i-1,0,0,m-1,1);
			hpa(a[i]+a[(int)q[1]]+(i-q[1])*s[1],i,(int)q[1]);
		}
		uf uf=new uf(n);
		while(he.Count>0){
			if(!uf.same((int)he[0][1],(int)he[0][2])){
				uf.union((int)he[0][1],(int)he[0][2]);
				ans+=he[0][0];
			}
			hpr();
		}
		Console.WriteLine(ans);
	}
	static void fdu(int q,long b,int z){
		int c=q;
		q+=m-1;
		dat[q,z,0]=b;
		dat[q,z,1]=c;
		while(q>0){
			if(dat[(q-1)/2,z,0]>b){
				dat[(q-1)/2,z,0]=b;
				dat[(q-1)/2,z,1]=c;
				q=(q-1)/2;
			}
			else{break;}
		}
	}
	static long[] fdg(int a,int b,int k,int l,int r,int z){
		if(r<a||b<l){return new long[]{int.MaxValue,0};}
		if(a<=l&&r<=b){return new long[]{dat[k,z,0],dat[k,z,1]};}
		else{
			long[] l1=fdg(a,b,k*2+1,l,(l+r)/2,z);
			long[] l2=fdg(a,b,k*2+2,(l+r+1)/2,r,z);
			if(l1[0]<l2[0]){return new long[]{l1[0],l1[1]};}
			else {return new long[]{l2[0],l2[1]};}
		}
	}
	static List<long[]> he=new List<long[]>();
	static void hpa(long a,int b,int c){
		he.Add(new long[]{a,b,c});
		int j=he.Count-1;
		while(he[j][0]<he[(j-1)/2][0]){//
			long v=he[j][0];he[j][0]=he[(j-1)/2][0];he[(j-1)/2][0]=v;
			v=he[j][1];he[j][1]=he[(j-1)/2][1];he[(j-1)/2][1]=v;
			v=he[j][2];he[j][2]=he[(j-1)/2][2];he[(j-1)/2][2]=v;
			j=(j-1)/2;
		}
	}
	static void hpr(){
		he[0]=he[he.Count-1];
		he.RemoveAt(he.Count-1);
		int j=0;
		while(true){
			if(j*2+2<he.Count){
				if(he[j*2+1][0]<he[j*2+2][0]){j=j*2+1;}//
				else{j=j*2+2;}
			}
			else if(j*2+1<he.Count){j=j*2+1;}
			else{break;}
			if(he[j][0]>=he[(j-1)/2][0]){break;}//
			long v=he[j][0];he[j][0]=he[(j-1)/2][0];he[(j-1)/2][0]=v;
			v=he[j][1];he[j][1]=he[(j-1)/2][1];he[(j-1)/2][1]=v;
			v=he[j][2];he[j][2]=he[(j-1)/2][2];he[(j-1)/2][2]=v;
		}
	}
}
public class uf{
	private int[] arr;
	private int[] hi;
	public uf(int n){
		arr=new int[n];
		hi=new int[n];
		for(int i=0;i<n;i++){arr[i]=-1;}
	}
	public void union(int a,int b){
		a=root(a);
		b=root(b);
		if(a!=b){
			if(hi[a]<hi[b]){
				int v=b;
				b=a;
				a=v;
			}
			arr[a]+=arr[b];
			hi[a]=Math.Max(hi[a],hi[b]+1);
			arr[b]=a;
		}
	}
	public bool same(int a,int b){return root(a)==root(b);}
	public int total(int a){return -arr[root(a)];}
	private int root(int a){return arr[a]<0?a:arr[a]=root(arr[a]);}
}