#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

ll sumf(const vector<ll> &a,ll lb){
	ll re=0;
	for(auto x:a) re+=max(0ll,x-lb);
	return re;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int n,m;
	ll t;
	cin>>n>>m>>t;
	vector<ll> a(n);
	for(auto &x:a) cin>>x;
	sort(all(a));
	int rem=m;
	while(a.size() && rem>=a.back()){
		rem-=a.back();
		a.pop_back();
	}
	if(a.empty()){
		cout<<0 NL;
		return 0;
	}
	out(a,1);
	//keep x==rem if pos
	if(t>sumf(a,rem+1)){
		assert(a.back()>=rem);
		t-=a.back()-rem;
		rem=0;
		a.pop_back();
	}
	if(a.empty()){
		cout<<0 NL;
		return 0;
	}
	out(a,1);

	if(t>=sumf(a,0)){
		cout<<0 NL;
		return 0;
	}
	int l=0,r=MOD;
	while(r-l>1){
		int m=(l+r)/2;
		(sumf(a,m)<=t?r:l)=m;
	}
	out(a,r,1);
	t-=sumf(a,r);
	for(auto &x:a) MN<ll>(x,r);
	rep(i,t) --a[a.size()-1-i];
	sort(rall(a));
	ll re=0;
	for(ll x:a){
		ll t=min<ll>(x,rem);
		rem-=t;
		re+=x*(x+1)/2-t*(t+1)/2;
	}
	cout<<re NL;
  return 0;
}


