#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
using namespace std;

const int mnogo = 1000000007;
const int petrol = 350;

int broiDni;
int cenaPrestoi;

int ceniPetrol[1000010];

int priTolova[2048][2048];

int pechalbaPri(int doKade, int sKolkoPetrol){
    if(doKade == 0){
        if(sKolkoPetrol == 0){
            return 0;
        }else{
            return -mnogo;
        }
    }
    if(priTolova[doKade][sKolkoPetrol + petrol] > -mnogo){
        return priTolova[doKade][sKolkoPetrol + petrol];
    }

    int akoNePipame = pechalbaPri(doKade - 1, sKolkoPetrol);

    int akoKupim = pechalbaPri(doKade - 1, sKolkoPetrol + 1) - ceniPetrol[doKade];

    int akoProdadem = pechalbaPri(doKade - 1, sKolkoPetrol - 1) + ceniPetrol[doKade];

    int tuka = max(akoNePipame, max(akoKupim, akoProdadem)) - cenaPrestoi*abs(sKolkoPetrol);

    priTolova[doKade][sKolkoPetrol + petrol] = tuka;
    return tuka;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>broiDni>>cenaPrestoi;

    for(int i = 1; i <= broiDni; i++){
        cin>>ceniPetrol[i];
    }

    for(int i = 0; i <= 2048; i++){
        for(int j = 0; j <= 2048; j++){
            priTolova[i][j] = -mnogo;
        }
    }

    int pechalba = pechalbaPri(broiDni, 0);

    cout<<pechalba<<endl;

    return 0;
}
