#include <bits/stdc++.h>
using namespace std;
int const Nmax = 1e5 + 50;
int n, k;
int64_t a[Nmax];
int curPieces[Nmax];
int64_t f(int id, int pieces) {
  int64_t w = a[id] / pieces;
  if (w == 0) return -1e18;
  int64_t k1 = a[id] % pieces;
  int64_t k2 = pieces - k1;
  return k1 * (w + 1) * (w + 1) + k2 * w * w;
}
void Enter() {
  cin >> n >> k;
  for (int i = (int)1; i <= (int)n; ++i) cin >> a[i];
  for (int i = (int)1; i <= (int)n; ++i) curPieces[i] = 1;
}
void Solve() {
  int64_t result = 0;
  for (int i = (int)1; i <= (int)n; ++i) result += (int64_t)a[i] * a[i];
  priority_queue<pair<int64_t, int> > pq;
  for (int i = (int)1; i <= (int)n; ++i)
    if (f(i, 2) != -1e18) pq.push(pair<int64_t, int>(f(i, 1) - f(i, 2), i));
  k -= n;
  while (k > 0) {
    pair<int64_t, int> TOP = pq.top();
    pq.pop();
    result -= TOP.first;
    curPieces[TOP.second]++;
    if (f(TOP.second, curPieces[TOP.second] + 1) != -1e18)
      pq.push(pair<int64_t, int>(f(TOP.second, curPieces[TOP.second]) -
                                     f(TOP.second, curPieces[TOP.second] + 1),
                                 TOP.second));
    k--;
  }
  cout << result;
}
int main() {
  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  Enter();
  Solve();
}
