#include <bits/stdc++.h>
using namespace std;
long long int arr[500001];
long long int psum[500001];
long long int csum[500001];
long long int srch(long long int val, long long int s, long long int e) {
  if (s > e)
    return INT_MAX;
  else if (s == e) {
    if (psum[s] >= val) return s;
    return INT_MAX;
  }
  long long int mid = (s + e) >> 1;
  if (psum[mid] < val) return srch(val, mid + 1, e);
  return min(srch(val, s, mid - 1), mid);
}
void solve(long long int n, long long int x) {
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  for (long long int i = 0; i < n - 1; i++) arr[i + n] = arr[i];
  n = 2 * n - 1;
  psum[0] = arr[0];
  csum[0] = ((arr[0] * (arr[0] + 1))) / 2;
  for (long long int i = 1; i < n; i++) psum[i] = psum[i - 1] + arr[i];
  for (long long int i = 1; i < n; i++)
    csum[i] = csum[i - 1] + ((arr[i] * (arr[i] + 1)) / 2);
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    long long int selem = psum[i] - x;
    if (selem < 0) continue;
    long long int elem = srch(selem, 0, n - 1);
    if (elem == INT_MAX) continue;
    long long int diff = psum[elem] - selem;
    ans = max(ans, csum[i] - csum[elem] + ((arr[elem]) * (arr[elem] + 1)) / 2 -
                       ((arr[elem] - diff) * ((arr[elem] - diff) + 1)) / 2);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, x;
  cin >> n >> x;
  solve(n, x);
}
