#include<bits/stdc++.h>

using namespace std;

template <typename T> bool maximize(T &res, const T &val){if(res < val) return res = val, true; return false;}
template <typename T> bool minimize(T &res, const T &val){if(res > val) return res = val, true; return false;}

#define ll long long
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for(int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for(int i = 0, _n = (n); i < _n; i++)
#define C make_pair
#define MASK(i) (1LL << (i))
#define TURN_ON(i, x) ((x) | MASK(i))
#define TURN_OFF(i, x) ((x) & ~MASK(i))
#define RE(i, x) ((x) ^ MASK(i))

const ll mod = 1e9 + 7;
const ll INF = 1e8;
const int maxn = 1e5 + 5;
typedef pair<double, double> pi;
typedef pair<int, pair<int,int>> pii;
typedef pair<ll, ll> pl;
typedef pair<ll, pair<ll,ll>>pll;

struct edge{
    int u,v,w;
    edge(int u = 0, int v = 0, int w = 0)
    {
        this->u = u;
        this->v = v;
        this->w = w;
    }
};
struct matrix{
    ll val[3][3];
    matrix(){
        memset(val, 0, sizeof(val));
    }
};

const int N = 1e4 + 10;

ll n, c, h[N], ans = +INF;

void nhap(){
	cin >> n >> c;
	FOR(i, 1, n) cin >> h[i];
}
namespace sub2{
	const int limit = 110;
	bool check(){
		FOR(i, 1, n) if(h[i] > 100) return 0;
		return n <= 1000;
	}
	ll dp[1010][120];
	void solve(){
		FOR(i, 1, n) FOR(j, 0, limit) dp[i][j] = +INF;
		FOR(i, h[1], limit)
			dp[1][i] = 1LL * (i - h[1]) * 1LL * (i - h[1]);
		FOR(i, 2, n) FOR(j, h[i], limit){
			FOR(k, h[i - 1], limit){
				if(dp[i - 1][k] == +INF) continue;
				minimize(dp[i][j], dp[i - 1][k] + 1LL * abs(j - k) * c + 1LL * (j - h[i]) * 1LL * (j - h[i]));
			}
		}
		FOR(i, h[n], limit) minimize(ans, dp[n][i]);
		cout << ans;
	}
}
namespace sub3{
	const int limit = 1e3 + 10;
	ll dp[10010][limit + 20], min1V[10010][limit + 20], min2V[10010][limit + 20], ans = +INF;
	
	void solve(){
		FOR(i, 1, n) FOR(j, 0, limit + 1){
			dp[i][j] = +INF;
			min1V[i][j] = +INF;
			min2V[i][j] = +INF;
		}
		FOR(i, h[1], limit) 
			dp[1][i] = 1LL * (i - h[1]) * 1LL * (i - h[1]);
		FOR(i, 2, n){
			FOR(j, 1, limit) min1V[i - 1][j] = min(min1V[i - 1][j - 1], dp[i - 1][j] - c * j);
			FORD(j, limit, 1) min2V[i - 1][j] = min(min2V[i - 1][j + 1], dp[i - 1][j] + c * j);
			FOR(j, h[i], limit){
				dp[i][j] = min(1LL * min1V[i - 1][j] + 1LL * c * j, 1LL * min2V[i - 1][j + 1] - 1LL * c * j) + 1LL * (j - h[i]) * 1LL * (j - h[i]);
			}
		}
		FOR(i, h[n], limit) minimize(ans, dp[n][i]);
		cout << ans;
	}
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    nhap();
    sub3::solve();
    return 0;
}
