#include <bits/stdc++.h>
using namespace std;
long long pr[3000000], a[3000000], b[3000000], sum[3000000], aa[3000000];
int main() {
  ios_base::sync_with_stdio(false);
  long long i, j = 1, k, m, n, l = 0, p, t, h, mod = 1e9 + 7, mx = 0, cnt = 0,
               mx1 = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];
  n *= 2;
  for (i = 1; i <= n; i++) b[i] = (a[i] * (a[i] + 1)) / 2;
  for (i = 1; i <= n; i++) b[i] += b[i - 1];
  for (i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  for (i = 1; i <= n; i++) {
    l = lower_bound(sum + 1, sum + n + 1, sum[i - 1] + m) - sum;
    k = sum[l] - sum[i - 1] - m;
    if (l != i && k > 0) {
      k = a[l] - k;
      k = (a[l] * (a[l] + 1)) / 2 - (k * (k + 1)) / 2;
    } else
      k = (k * (k + 1)) / 2;
    if (k >= 0) mx = max(mx, b[l] - b[i - 1] - k);
  }
  n /= 2;
  for (i = n; i > 0; i--) aa[n - i + 1] = a[i];
  for (i = n + 1; i <= 2 * n; i++) aa[i] = aa[i - n];
  n *= 2;
  for (i = 1; i <= n; i++) b[i] = (aa[i] * (aa[i] + 1)) / 2;
  for (i = 1; i <= n; i++) b[i] += b[i - 1];
  for (i = 1; i <= n; i++) sum[i] = sum[i - 1] + aa[i];
  for (i = 1; i <= n; i++) {
    l = lower_bound(sum + 1, sum + n + 1, sum[i - 1] + m) - sum;
    k = sum[l] - sum[i - 1] - m;
    k = (k * (k + 1)) / 2;
    if (k >= 0) mx1 = max(mx1, b[l] - b[i - 1] - k);
  }
  cout << max(mx, mx1) << endl;
  return 0;
}
