#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, ans = 0;
  cin >> n >> x;
  vector<long long int> v(n), pref1, pref2, temp;
  for (int i = 0; i < n; i++) cin >> v[i], temp.push_back(v[i]);
  for (long long int a : temp) v.push_back(a);
  pref1.push_back(0);
  for (long long int i = 0; i < v.size(); i++)
    pref1.push_back(pref1.back() + v[i]);
  pref2.push_back(0);
  for (long long int i = 0; i < v.size(); i++)
    pref2.push_back(pref2.back() + v[i] * (v[i] + 1) / 2);
  for (long long int i = pref1.size() - 1; i >= 0 && pref1[i] - x >= 0; i--) {
    int index =
        lower_bound(pref1.begin(), pref1.end(), pref1[i] - x) - pref1.begin();
    if (index - 1 >= 0) {
      long long int days = pref1[i] - pref1[index - 1], extra = days - x;
      ans = max(ans, pref2[i] - pref2[index - 1] - extra * (extra + 1) / 2);
    }
  }
  cout << ans << '\n';
  return 0;
}
