#include <bits/stdc++.h>
using i32 = int;
using i64 = long long;
i64 qrt(i64 x) { return x * x; }
i64 value(i32 x, i32 k) {
  i32 v = x / k;
  i32 c1 = x % k;
  i32 c0 = k - c1;
  return c0 * qrt(v) + c1 * qrt(v + 1);
}
i32 main() {
  std::ios::sync_with_stdio(false);
  std::cout.tie(nullptr);
  std::cin.tie(nullptr);
  i32 n, k;
  std::cin >> n >> k;
  i64 ans = 0;
  std::vector<i32> a(n), c(n, 1);
  std::priority_queue<std::pair<i64, i32>> q;
  for (i32 i = 0; i < n; i++) {
    std::cin >> a[i];
    ans += qrt(a[i]);
    q.emplace(value(a[i], 1) - value(a[i], 2), i);
  }
  for (i32 i = n; i < k; i++) {
    ans -= q.top().first;
    i32 x = q.top().second;
    q.pop();
    if (++c[x] <= a[x]) q.emplace(value(a[x], c[x]) - value(a[x], c[x] + 1), x);
  }
  std::cout << ans << "\n";
  return 0;
}
