#include <bits/stdc++.h>
using namespace std;
long long nSum(int n) { return (long long)n * (n + 1) / 2; }
long long solve(vector<int> &d, long long x) {
  long long ans = 0;
  long long aSum = 0, sum = 0;
  int j = 0;
  for (int i = 0; i < d.size(); i++) {
    while (j < d.size() && sum <= x) {
      sum += d[j];
      aSum += nSum(d[j]);
      j++;
    }
    ans = max(ans, aSum - nSum(d[j - 1]) +
                       nSum(min((long long)d[j - 1], x - (sum - d[j - 1]))));
    sum -= d[i];
    aSum -= nSum(d[i]);
  }
  j = d.size() - 1;
  sum = 0;
  aSum = 0;
  for (int i = d.size(); i--;) {
    while (j >= 0 && sum <= x) {
      sum += d[j];
      aSum += nSum(d[j]);
      j--;
    }
    ans = max(ans, aSum - nSum(max((long long)0, sum - x)));
    sum -= d[i];
    aSum -= nSum(d[i]);
  }
  return ans;
}
int main() {
  iostream::sync_with_stdio(false);
  int n;
  long long x;
  cin >> n >> x;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  for (int i = 0; i < n; i++) d.push_back(d[i]);
  cout << solve(d, x) << '\n';
}
