#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
long long a[N];
long long pf[N], pfc[N];
long long f(long long x) {
  if (x < 0) return 0;
  return (x * (x + 1)) / 2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T, cs = 0;
  int n;
  long long x;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[n + i] = a[i];
  }
  reverse(a + 1, a + n + n + 1);
  for (int i = 1; i <= 2 * n; i++) {
    pf[i] = pf[i - 1] + a[i];
    pfc[i] = pfc[i - 1] + f(a[i]);
  }
  long long res = 0;
  for (int i = 1; i <= 2 * n; i++) {
    long long k = x;
    k += pf[i - 1];
    int id = upper_bound(pf + 1, pf + 2 * n + 1, k) - pf;
    if (k > pf[2 * n]) break;
    long long leftd = k - pf[id - 1];
    long long tmp = pfc[id - 1] - pfc[i - 1];
    tmp += f(a[id]) - f(a[id] - leftd);
    res = max(res, tmp);
  }
  cout << res << '\n';
  return 0;
}
