#include <bits/stdc++.h>
using namespace std;
long long ara[400002], csum[400002], msum[400002];
long long cnt1(long long s, long long x, long long n) {
  long long l = s - 1, r = 2 * n;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (l + 1 == r) {
      if (csum[r] - csum[s - 1] <= x)
        return r;
      else
        return l;
    }
    if (csum[mid] - csum[s - 1] > x)
      r = mid - 1;
    else
      l = mid;
  }
  return l;
}
long long cnt2(long long s, long long x, long long n) {
  long long l = 0, r = s;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (l + 1 == r) {
      if (csum[s] - csum[l] <= x)
        return l;
      else
        return r;
    }
    if (csum[s] - csum[mid] > x)
      l = mid + 1;
    else
      r = mid;
  }
  return l;
}
int main() {
  long long t;
  long long i, j, k;
  long long n, x;
  scanf("%lld %lld", &n, &x);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &ara[i]);
  }
  for (; i <= 2 * n; i++) {
    ara[i] = ara[i - n];
  }
  for (i = 1; i <= 2 * n; i++) {
    csum[i] = ara[i] + csum[i - 1];
    msum[i] = (ara[i] * (ara[i] + 1)) / 2 + msum[i - 1];
  }
  csum[2 * n + 1] = csum[2 * n];
  msum[2 * n + 1] = msum[2 * n];
  long long res = 0;
  for (i = 1; i <= 2 * n; i++) {
    if (csum[2 * n] - csum[i - 1] < x) continue;
    long long idx = cnt1(i, x, n);
    long long rem = x - csum[idx] + csum[i - 1];
    res = max(res, msum[idx] - msum[i - 1] + (rem * (rem + 1)) / 2);
  }
  for (i = 1; i <= 2 * n; i++) {
    if (csum[i] < x) continue;
    long long idx = cnt2(i, x, n);
    long long rem = x + csum[idx] - csum[i];
    rem = ara[idx] - rem;
    res = max(res, msum[i] - msum[idx] + (ara[idx] * (ara[idx] + 1)) / 2 -
                       (rem * (rem + 1)) / 2);
  }
  printf("%lld\n", res);
}
