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[][] h=new long[s[0]][];
		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++){h[i]=new long[]{a[i],i};}
		Array.Sort(h,ca);
		fdu((int)h[0][1],h[0][0]+h[0][1]*s[1],0);
		fdu((int)h[0][1],h[0][0]+(s[0]-h[0][1]-1)*s[1],1);
		for(int i=1;i<s[0];i++){
			long[] q=fdg((int)h[i][1]+1,n-1,0,0,m-1,0);
			if(q[0]!=long.MaxValue){hpa(a[h[i][1]]+a[(int)q[1]]+(q[1]-h[i][1])*s[1],(int)h[i][1],(int)q[1]);}
			q=fdg(0,(int)h[i][1]-1,0,0,m-1,1);
			if(q[0]!=long.MaxValue){hpa(a[h[i][1]]+a[(int)q[1]]+(h[i][1]-q[1])*s[1],(int)h[i][1],(int)q[1]);}
			fdu((int)h[i][1],h[i][0]+h[i][1]*s[1],0);
			fdu((int)h[i][1],h[i][0]+(s[0]-h[i][1]-1)*s[1],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 int ca(long[] a,long[] b){
		if(a[0]>b[0]){return 1;}
		else if(a[0]<b[0]){return -1;}
		else{return 0;}
	}
	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[]{long.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]);}
}

Measured memory_bytes: 73388