#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'

using namespace std;

const int maxn = 1e4 + 3;
const long long inf = 1e18;

int n, s;
int p[maxn];
void read()
{
    cin >> n >> s;
    for (int i = 1; i <= n; i++)
        cin >> p[i];
}

long long dp[maxn], nxt_dp[maxn];
void solve()
{
    for (int i = 1; i <= n; i++)
        dp[i] = -inf;
    dp[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        long long x = (long long)i * s - (long long)p[i];
        for (int j = 0; j <= n; j++)
            nxt_dp[j] = dp[j];

        for (int j = 1; j <= n; j++)
            nxt_dp[j] = max(nxt_dp[j], dp[j-1] + x);

        for (int j = 0; j <= n-1; j++)
            nxt_dp[j] = max(nxt_dp[j], dp[j+1] - x);

        for (int j = 0; j <= n; j++)
            dp[j] = nxt_dp[j];
    }

    cout << dp[0] << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    read();
    solve();
}
