#include <bits/stdc++.h>
#define ll long long
#define TIME (1.0*clock()/CLOCKS_PER_SEC)
using namespace std;

void input(){
	#define taskname ""
	if(fopen(taskname ".inp", "r")){
		freopen(taskname ".inp", "r", stdin);
		freopen(taskname ".out","w",stdout);
	}
}
const int N = 2e5+1;
const ll INF =1e18;
const int Q =1e9+7;
ll a[N];
ll n,k;
int main(){
	cin.tie(0)->sync_with_stdio(0);
	cout.tie(0);
	input();
	cin >> n >> k;
	for(ll i=1;i<=n;++i) cin >> a[i];
    sort(a+1,a+n+1);
    vector<ll>w(n+1);
    for(ll i=1;i<n;++i) w[i] = (a[i+1] - a[i])*(a[i+1]-a[i]);
    w[0] = INF;
    w[n] = INF;
    ll sz = n-1;
    vector<ll>pre(sz+2),nxt(sz+2);
    vector<bool>ck(sz+2,0);
    for(ll i=0;i<=sz+1;++i){
        pre[i] = i-1;
        nxt[i] = i+1;
    }
    priority_queue<pair<ll,ll>>q;
    for(ll i=1;i<=sz;++i) q.push({-w[i],i});
    ll ans = 0;
    while(k--){
        while(ck[q.top().second] || -q.top().first != w [q.top().second]) q.pop();
        ll val = q.top().first;
        ll id = q.top().second;
        q.pop();
        val = -val;
        ans += val;
        ll l = pre[id], r = nxt[id];
        w[id] = w[l] + w[r] - w[id];
        ck[l] = 1;
        ck[r] = 1;
        if(l >= 0) pre[id] = pre[l];
        else pre[id] = -1; 
        if(r<=sz+1) nxt[id] = nxt[r];
        else nxt[id] = sz+2;
        if(pre[id] >= 0) nxt[pre[id]] = id;
        if(nxt[id] <= sz+1) pre[nxt[id]] = id;
        q.push({-w[id],id});
    }
    cout << ans << endl;
	return 0;
}