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

long long n, s, p [1000006];

int fenwick [1000006];
void upd (int x, int val){
    while (x <= n){
        fenwick [x] += val;
        x += x & -x;
    }
}
int query (int x){
    int ans = 0;
    while (x > 0){
        ans += fenwick [x];
        x -= x & -x;
    }
    return ans;
}

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> s;
    for (int i = 1; i <= n; i ++) s.insert (i);

    for (auto x : v){
        int i = x.second;
        int q = query (i);
        if (i + q >= 2){
            ans -= 2 * x.first;
            auto it = s.lower_bound (i);
            if (*it != i) it --;
            upd (*it, -1);
            it = s.erase (it);
            it --;
            upd (*it, -1);
            s.erase (it);
        }
        else if (i + q == 1){
            ans -= x.first;
            upd (i, -1);
            auto it = s.lower_bound (i);
            if (*it != i) it --;
            upd (*it, -1);
            s.erase (it);
        }
    }

    cout << ans << '\n';

}
