#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int rest;

Int cnt(vector<Int> &a, Int m){
    Int ans = 0;
    for(int i = 0;i < a.size() - 1;i++){
        ans += max(0ll, a[i] - m + 1);
    }
    ans += a.back() - max(rest, m-1);
    return ans;
}

int main(){
    Int n, m, k;
    cin >> n >> m >> k;
    vector<Int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    rest = m;
    while(!a.empty() && a.back() <=rest){
        rest -= a.back();
        a.pop_back();
    }
   
    Int sum = 0;
    for(auto x:a)sum += x;
    if(sum - k - rest <= 0){
        cout << 0 << endl;
        return 0;             
    }
    
    Int bottom = 0, top = a.back() + 1;
    while(top - bottom > 1){
        Int mid = (top + bottom) / 2;
        if(cnt(a, mid) <= k)top = mid;
        else bottom = mid;
    }
    for(int i = 0;i < a.size();i++){
        Int goal = top-1;
        if(i+1 == a.size())goal = max(goal, rest);
        if(a[i] >= goal){
            k -= a[i] - goal;
            a[i] = goal;
        }
    }
    if(a.back() == rest){
        rest = 0;
        a.pop_back();
    }
    for(int i = (int)a.size()-1;i >= 0 && k > 0;i--){
        a[i]--;
        k--;
    }
    Int ans = 0;
    for(auto x:a)ans += (x+1) * x / 2;
    ans -= (rest + 1) * rest / 2;
    cout << ans << endl;
    return 0;
}
