#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7, N = 1e5 + 10;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, x;
  cin >> n >> x;
  vector<ll> A(2 * n);
  for (ll i = 0; i < n; i++) {
    cin >> A[i];
    A[i + n] = A[i];
  }
  vector<ll> Pre(2 * n), val(2 * n);
  Pre[0] = A[0];
  val[0] = A[0] * (A[0] + 1) / 2;
  for (ll i = 1; i < 2 * n; i++) {
    Pre[i] = Pre[i - 1] + A[i];
    val[i] = val[i - 1] + (A[i] * (A[i] + 1)) / 2;
  }
  auto V = [&](ll in, ll v) {
    ll done = x - (A[in] - v + 1);
    if (done <= 0) {
      return (v + x - 1) * (v + x) / 2 - v * (v - 1) / 2;
    }
    ll R = A[in] * (A[in] + 1) / 2 - v * (v - 1) / 2;
    auto k = lower_bound(Pre.begin(), Pre.end(), Pre[in] + done) - Pre.begin();
    k--;
    R += val[k] - val[in];
    done -= (Pre[k] - Pre[in]);
    R += done * (done + 1) / 2;
    return R;
  };
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ll l = 1, r = A[i];
    while (r - l > 3) {
      ll m1 = l + (r - l) / 3;
      ll m2 = r - (r - l) / 3;
      ll c1 = V(i, m1), c2 = V(i, m2);
      if (c1 < c2)
        l = m1;
      else
        r = m2;
    }
    for (ll j = l; j < r + 1; j++) {
      ans = max(ans, V(i, j));
    }
  }
  cout << ans << '\n';
  return 0;
}
