#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long d;
  cin >> n >> d;
  vector<long long> a(n);
  vector<int> mps;
  long long maxdays = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxdays = max(maxdays, a[i]);
  }
  long long maxans = 0;
  int s = n - 1;
  long long now = 0;
  long long nowans = 0;
  for (int i = 0; i < n; i++) {
    now += a[i];
    nowans += (a[i]) * (a[i] + 1) / 2;
    while (now + a[s] <= d) {
      nowans += (a[s]) * (a[s] + 1) / 2;
      now += a[s];
      s--;
      if (s < 0) s = n - 1;
    }
    while (now > d) {
      int ts = s + 1;
      if (ts > n - 1) ts = 0;
      now -= a[ts];
      nowans -= (a[ts]) * (a[ts] + 1) / 2;
      s++;
      if (s > n - 1) s = 0;
    }
    long long md = d - now;
    long long temp =
        ((a[s]) * (a[s] + 1) / 2) - ((a[s] - md) * ((a[s] - md) + 1) / 2);
    temp += nowans;
    maxans = max(temp, maxans);
  }
  cout << maxans << "\n";
  return 0;
}
