#include <string.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int dp[2005][1005];
int main(int argc, char** argv) {
int w[2005];
int n, k;
while(scanf("%d%d",&n,&k)!=EOF){
for(int i = 1; i <= n; i++) scanf("%d",&w[i]);
sort(w + 1, w + n + 1);
for(int i = 0; i <= k; i++) dp[0][i] = 0;//前0个物品选i对
for(int i = 0; i <= n; i++) dp[i][0] = 0;//前i个物品选0个
for(int i = 1; i <= n; i++){
for(int j = 1; j <= k; j++){
dp[i][j] = 0x7fffffff;
}
}
for(int i = 2; i <= n; i++){
for(int j = 1; j * 2 <= i; j++){
dp[i][j] = min(dp[i - 2][j - 1] + (w[i] - w[i - 1]) * (w[i] - w[i - 1]),dp[i - 1][j] );
}
}
printf("%d\n",dp[n][k]);
}
return 0;
}