#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector a(n), s(n); cin >> a; sort(a.begin(), a.end()); ll ans = 1ll << 61; for(int i = 0; i + 1 < n; i++){ s[i + 1] = s[i] + (a[i + 1] - a[i]) * (a[i + 1] - a[i]); } for(int i = 0; i + m < n; i++){ ans = min(ans, s[i + m - 1] - s[i]); } cout << ans << '\n'; }