#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
ll a[400001],pref[400001],x,pref1[400001];
int bin(int l,int d,int i){
if(l==d)return l;
if(l==d-1){
if(pref[l]>i)
return l;
return d;
}
int mid=(l+d)/2;
if(pref[mid]>i&&pref[mid-1]<=i)return mid;
if(pref[mid]<=i)
return bin(mid+1,d,i);
return bin(l,mid-1,i);
}
ll resi(int i){
if(pref[i]<x)
return -1;
ll m=(a[i]+1)*a[i]/2ll;
if(i==0){
if(x>=a[0])
return m;
ll u=(a[0]-x)*(a[0]-x+1)/2ll;
return m-u;
}
if(x==a[i]) return m;
if(x<=a[i]){
ll u=(a[i]-x)*(a[i]-x+1)/2ll;
return m-u;
}
int mes=bin(0,i-1,pref[i]-x);
ll trx=x-(pref[i]-pref[mes]);
if(trx<0)return -1; //this should not be negative but it sometimes is, i dont know why
ll o=(a[mes]+1ll)*a[mes]/2ll,p=(a[mes]-trx)*(a[mes]-trx+1ll)/2ll;
return pref1[i]-pref1[mes]+o-p;
}
int main(){
cin>>n>>x;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=n;i<2*n;i++)a[i]=a[i-n];
n*=2;
pref[0]=a[0];pref1[0]=a[0]*(a[0]+1)/2ll;
for(int i=1;i<n;i++){pref[i]=pref[i-1]+a[i];pref1[i]=pref1[i-1]+a[i]*(a[i]+1)/2ll;}
ll res=1;
for(int i=0;i<n;i++) //fixing the end and binary searching for the beginning
res=max(res,resi(i));
cout<<res;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKaW50IG47CmxsIGFbNDAwMDAxXSxwcmVmWzQwMDAwMV0seCxwcmVmMVs0MDAwMDFdOwppbnQgYmluKGludCBsLGludCBkLGludCBpKXsgIAoJaWYobD09ZClyZXR1cm4gbDsKCWlmKGw9PWQtMSl7CgkJaWYocHJlZltsXT5pKQoJCQlyZXR1cm4gbDsKCQlyZX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