#include <bits/stdc++.h>
using namespace std;
const int Max = 1e6 + 7;
long long a[Max], sum[Max], summ[Max];
int main() {
  long long n, x;
  scanf("%lld%lld", &n, &x);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[i + n] = a[i];
  }
  for (int i = 1; i <= 2 * n; i++) {
    sum[i] = sum[i - 1] + a[i];
    summ[i] = summ[i - 1] + a[i] * (a[i] + 1) / 2;
  }
  int l = 1, r = 1;
  long long mmax = -1;
  while (r < 2 * n) {
    if (sum[r] - sum[l - 1] < x)
      r++;
    else {
      long long temp = (sum[r] - sum[l - 1]) - x;
      if (temp > a[l])
        l++;
      else {
        mmax = max((long long)(summ[r] - summ[l - 1] - temp * (temp + 1) / 2),
                   (long long)mmax);
        l++;
      }
    }
  }
  cout << mmax << endl;
  return 0;
}
