#include #include #include #include using namespace std; #define int long long signed main(){ int N,M; cin >> N >> M; vector a(N); for(int i = 0;i < N;i++) cin >> a[i]; sort(a.begin(),a.end()); vector b(N - 1); for(int i = 0;i < N - 1;i++){ b[i] = a[i + 1] - a[i]; b[i] = b[i] * b[i]; } if(M == 1){ cout << 0; return 0; } for(int i = 1;i < N - 1;i++)b[i] += b[i - 1]; int ans = b[M - 2]; for(int i = M - 1;i < N - 1;i++){ ans = min(ans,b[i] - b[i - M + 1]); } cout << ans << endl; }