#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
deque<long long> dq;
signed main() {
  long long n, x;
  cin >> n >> x;
  a.resize(n);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  for (long long i = 0; i < n; ++i) a.push_back(a[i]);
  long long sum = 0, val = 0, ans = 0, l = 0, r = -1;
  for (long long i = 0; i < a.size(); ++i) {
    dq.push_back(a[i]), sum += a[i], val += a[i] * (a[i] + 1) / 2, ++r;
    while (dq.size() and (sum >= x or r - l + 1 > n))
      sum -= dq.front(), val -= dq.front() * (dq.front() + 1) / 2,
          dq.pop_front(), ++l;
    if (sum < x and l != 0) {
      ans =
          max(ans, val + (x - sum) * (a[l - 1] + a[l - 1] + 1 - (x - sum)) / 2);
    }
    ans = max(ans, val);
  }
  cout << ans << '\n';
}
