#include <bits/stdc++.h>
using namespace std;
vector<long long> d;
long long hug(long long x) { return (x * (x + 1)) / 2; }
int main() {
  long long n, x, a;
  cin >> n >> x;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    d.push_back(a);
  }
  long long i = 0, j = 0, H = hug(d[0]), maxbr = -1, brdana = d[0], visak;
  while (i < n) {
    if (brdana < x) {
      j++;
      if (j == n) {
        j = 0;
      }
      H += hug(d[j]);
      brdana += d[j];
      continue;
    }
    visak = brdana - x;
    if ((H - hug(visak)) > maxbr) {
      maxbr = H - hug(visak);
    }
    H -= hug(d[i]);
    brdana -= d[i];
    i++;
  }
  cout << maxbr << endl;
  return 0;
}
