#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[1024][1024];

int pechalbaPri(int doKade, int sKolkoPetrol){
    if(doKade == 0){
        if(sKolkoPetrol == 0){
            return 0;
        }else{
            return -mnogo;
        }
    }
    if(abs(sKolkoPetrol) > doKade){
        return -mnogo;
    }
    if(priTolova[doKade][sKolkoPetrol + petrol] > -1){
        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(){

    cin>>broiDni>>cenaPrestoi;

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

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

    int pechalba = pechalbaPri(broiDni, 0);

    cout<<pechalba<<endl;

    return 0;
}
