#include <iostream>

using namespace std;

int main()
{
    long long n, s;

    int week[100000];
    bool sold[100000];
    cin >> n >> s;

   for(int i=0; i<n; i++){
    cin >> week[i];
   }

    int lastBestI, lastBestQ;
    long long q = n-1;
    int currentValue = 0;
    int currentBest = 0;
    for(int z=0; z<n/2; z++){
    currentBest = 0;
    for(int i=0; i<n-1; i++){
       for(q=i+1; q<n; q++){
        if(sold[q]!=true && sold[i]!=true && week[q]-week[i]-s*(q-i)> currentBest){
        currentBest =week[q]-week[i]-s*(q-i);
        lastBestI = i;
        lastBestQ = q;
        }
        }
       }
         sold[lastBestI] = true;
        sold[lastBestQ] = true;
        currentValue += currentBest;
    }


    cout << currentValue;
    return 0;
}
