#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
using ld = long double;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long rk = 256;
const ld PI = 3.141592653589793;
ostream& operator<<(ostream& os, pair<long long, long long> const& x) {
  os << x.first << "," << x.second;
  return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<T> const& x) {
  os << "{ ";
  for (auto& y : x) os << y << " ";
  return os << "}";
}
template <class T>
ostream& operator<<(ostream& os, set<T> const& x) {
  os << "{ ";
  for (auto& y : x) os << y << " ";
  return os << "}";
}
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os,
                                  Container const& x) {
  os << "{ ";
  for (auto& y : x) os << y << " ";
  return os << "}";
}
template <class X, class Y>
ostream& operator<<(ostream& os, pair<X, Y> const& p) {
  return os << "[ " << p.first << ", " << p.second << "]";
}
const int mxn = 1e6 + 5;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  vector<long long> pre(mxn, 0);
  for (int i = 1; i < mxn; i++) {
    pre[i] = pre[i - 1] + i;
  }
  long long n, x;
  cin >> n >> x;
  vector<long long> arr((2 * n) + 1, 0), pre1((2 * n) + 1, 0),
      pre2((2 * n) + 1, 0);
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = n + 1; i <= 2 * n; i++) arr[i] = arr[i - n];
  for (int i = 1; i <= 2 * n; i++) {
    pre1[i] = pre1[i - 1] + pre[arr[i]];
    pre2[i] = pre2[i - 1] + arr[i];
  }
  long long maxans = INT_MIN;
  long long ans;
  for (long long i = 2 * n; i >= n + 1; i--) {
    long long hi = i;
    long long lo = 1;
    while (lo <= hi) {
      long long m = (lo + hi) / 2;
      if (pre2[i] - pre2[m] <= x) {
        ans = m;
        hi = m - 1;
      } else {
        lo = m + 1;
      }
    }
    long long days = pre2[i] - pre2[ans - 1];
    long long rem = days - x;
    long long tmp = pre1[i] - pre1[ans - 1] - pre[rem];
    maxans = max(maxans, tmp);
  }
  cout << maxans << '\n';
  return 0;
}
