#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]); ll sum = 0; rep(i, 0, M - 1) sum += S[i]; ll ans = sum; rep(i, 1, N - M + 1) { sum -= S[i - 1]; sum += S[i + M - 2]; ans = min(ans, sum); } cout << ans << '\n'; }