#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() const ll mod = 1e9 + 7; int main() { cin.tie(nullptr); int N, M; cin >> N >> M; vector A(N); rep(i, 0, N) cin >> A[i]; if (N == 1) { cout << 0 << '\n'; return 0; } sort(all(A)); vector S(N - 1); rep(i, 0, N - 1) S[i] = (A[i + 1] - A[i])*(A[i + 1] - A[i]); rep(i, 1, N - 1) S[i] += S[i - 1]; ll ans = LLONG_MAX; rep(i, 0, N - M + 1) { if (i == 0) ans = min(ans, S[i + M - 1]); else ans = min(ans, S[i + M - 2] - S[i - 1]); } cout << ans << '\n'; }