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

using namespace std;

const int maxn = 1e6 + 3;

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

void solve()
{
    priority_queue <long long> pq;
    long long ans = 0;
    for (int i = 1; i <= n; i++)
    {
        long long x = (long long)i * s - (long long)p[i];
        pq.push(x);

        long long maxs = pq.top();
        if (-x + maxs <= 0)
            continue;

        else
        {
            ans += maxs - x;
            pq.pop();
            pq.push(x);
        }
    }

    cout << ans << endl;
}

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

    read();
    solve();
}
