#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, d, i, j, k, l, x;
  cin >> n >> d;
  vector<long long> v;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  reverse((v).begin(), (v).end());
  for (i = 0; i < n; i++) {
    v.push_back(v[i]);
  }
  vector<pair<long long, long long>> vs;
  for (i = 0; i < v.size(); i++) {
    vs.push_back({v[i], (v[i] * (v[i] + 1)) / 2LL});
  }
  for (i = 1; i < vs.size(); i++) {
    vs[i].first += vs[i - 1].first;
    vs[i].second += vs[i - 1].second;
  }
  long long ans = 0;
  long long sz = vs.size();
  for (i = 1; i < sz; i++) {
    auto it = upper_bound((vs).begin(), (vs).end(),
                          make_pair(vs[i - 1].first + d, 0LL));
    it = prev(it);
    long long idx = it - vs.begin();
    long long num = vs[idx].first - vs[i - 1].first;
    long long diff = d - num;
    long long tmp = vs[idx].second - vs[i - 1].second;
    if (diff == 0) {
      ans = max(ans, tmp);
      continue;
    }
    if (diff > 0 && idx < sz - 1) {
      long long st = v[idx + 1];
      tmp += (diff * (2LL * st + 1 - diff)) / 2LL;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}
