#include using namespace std; #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(n) for(int i = 0; i < (int)(n); ++i) #define rep2(i, n) for(int i = 0; i < (int)(n); ++i) #define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) using ll = long long; using ull = unsigned long long; using ld = long double; using u16 = uint16_t; const ll INF = 1 << 30; int main(){ size_t N{}; size_t M{}; cin >> N >> M; vector problems(N); rep(i,N)cin >> problems.at(i); sort(problems.begin(), problems.end()); ull cnt = 0; rep(i,M-1){ cnt += abs(problems.at(i) - problems.at(i+1)) * abs(problems.at(i) - problems.at(i+1)); } ull S = cnt; rep(i,1,N-M+1){ size_t r = M+i-1; size_t l = i; //cout << "l,r = " << l << " " << r << endl; cnt -= abs(problems.at(l) - problems.at(l-1)) * abs(problems.at(l) - problems.at(l-1)); cnt += abs(problems.at(r) - problems.at(r-1)) * abs(problems.at(r) - problems.at(r-1)); S = min(S, cnt); } cout << S << endl; }