#include using namespace std; #if __has_include("Today's/debug.cpp") #include "Today's/debug.cpp" #else #define debug(...) #define print_line #define debugc(...) #define cerr \ if (false) cerr #endif int 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()); long long ans = 0; for (int i = 0; i < m - 1; i++) { ans += (a[i + 1] - a[i]) * (a[i + 1] - a[i]); } long long tmp = ans; for (int i = 1; i + m - 1 < n; i++) { tmp -= (a[i] - a[i - 1]) * (a[i] - a[i - 1]); tmp += (a[i + m - 1] - a[i + m - 2]) * (a[i + m - 1] - a[i + m - 2]); ans = min(ans, tmp); } cout << ans << endl; }