#include <bits/stdc++.h>
using namespace std;

long long n, s, p [1000006];

int main (){

    ios::sync_with_stdio (false);
    cin.tie (0);

    cin >> n >> s;

    long long ans = 0;
    vector <pair <long long, int> > v;
    for (int i = 1; i <= n; i ++){
        cin >> p [i];
        ans -= p [i] + (n - i) * s;
        v.push_back ({- p [i] - (n - i) * s, i});
    }
    sort (v.begin (), v.end ());

    set <int> nums;
    for (int i = 1; i <= n; i ++) nums.insert (i);

    for (auto x : v){
        int i = x.second;
        auto it = nums.upper_bound (i);
        if (it == nums.begin ()) continue;
        it --;
        ans -= x.first;
        it = nums.erase (it);
        if (it == nums.begin ()) continue;
        it --;
        ans -= x.first;
        nums.erase (it);
    }

    cout << ans << '\n';

}
