#include #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); 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), C(N); for(int i = 0; i < N - 1; i++) { B[i] = (long long) (A[i + 1] - A[i]) * (A[i + 1] - A[i]); C[i + 1] = C[i] + B[i]; } long long ans = 4000000000000000000; for(int i = 0; i + M - 1 < N; i++) { ans = min(ans, C[i + M - 1] - C[i]); } cout << ans << '\n'; return 0; }