#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 99;
const long long inf = 1e18;
int n, k, a[N], b[N];
long long sum, ans;
set<pair<long long, int> > s1, s2;
long long calc(int x, int k) {
  if (k == 0 || x < k) return inf;
  long long res = 0;
  int c = x / k;
  res += 1ll * c * c * k;
  res += (x % k) * (c * 2 + 1);
  return res;
}
void add(int x) {
  s1.insert(make_pair(calc(a[x], b[x] - 1) - calc(a[x], b[x]), x));
  s2.insert(make_pair(calc(a[x], b[x]) - calc(a[x], b[x] + 1), x));
}
void del(int x) {
  s1.erase(make_pair(calc(a[x], b[x] - 1) - calc(a[x], b[x]), x));
  s2.erase(make_pair(calc(a[x], b[x]) - calc(a[x], b[x] + 1), x));
}
void do_it(pair<long long, int> p1, pair<long long, int> p2) {
  ans += p1.first - p2.first;
  del(p1.second);
  b[p1.second]--;
  add(p1.second);
  del(p2.second);
  b[p2.second]++;
  add(p2.second);
}
int main() {
  cin >> n >> k;
  int copy = k;
  k -= n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    ;
    b[i] = 1 + min(k, a[i] - 1);
    k -= min(k, a[i] - 1);
    ans += calc(a[i], b[i]);
  }
  if (n == 1) return cout << calc(a[0], copy), 0;
  for (int i = 0; i < n; i++) add(i);
  while (1) {
    pair<long long, int> a, b, c, d;
    a = *s1.begin();
    s1.erase(a);
    b = *s1.begin();
    c = *s2.rbegin();
    s2.erase(c);
    d = *s2.rbegin();
    if (a.first < c.first && a.second != c.second)
      do_it(a, c);
    else {
      if (a.first < d.first && a.second != d.second)
        do_it(a, d);
      else {
        if (b.first < c.first && b.second != c.second)
          do_it(b, c);
        else
          break;
      }
    }
  }
  cout << ans;
}
