#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
mt19937_64 gen(time(0));
const long long N = 1e6 + 10;
const long long MOD = 1e9 + 7;
const long long M = 1e5 + 10;
const long double eps = 1e-8;
const long long inf = 1e18;
long long d[N], sum[N], pref[N], sumpref[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, x;
  cin >> n >> x;
  for (long long i = 0; i < n; ++i) {
    cin >> d[i];
    d[i + n] = d[i];
    sum[i] = d[i] * (d[i] + 1) / 2;
    sum[i + n] = sum[i];
  }
  n *= 2;
  pref[n - 1] = d[n - 1];
  sumpref[n - 1] = sum[n - 1];
  for (long long i = n - 2; i >= 0; --i) {
    pref[i] = pref[i + 1] + d[i];
    sumpref[i] = sumpref[i + 1] + sum[i];
  }
  vector<long long> v;
  for (long long k = 0; k < n; ++k) {
    unsigned long long ans = 0;
    if (d[k] >= x || k == 0) {
      long long y = d[k] - x;
      y = max(y, 1ll * 0);
      ans = -(y * (y + 1) / 2) + (d[k] * (d[k] + 1) / 2);
      v.push_back(ans);
      continue;
    }
    long long l = 0, r = k, i = -1;
    while (l <= r) {
      long long mid = (l + r) / 2;
      long long s = pref[mid] - pref[k + 1];
      if (s <= x) {
        r = mid - 1;
        i = mid;
      } else
        l = mid + 1;
    }
    ans = sumpref[i] - sumpref[k + 1];
    if (i > 0) {
      long long y = d[i - 1] - (x - (pref[i] - pref[k + 1]));
      ans = ans - y * (y + 1) / 2 + d[i - 1] * (d[i - 1] + 1) / 2;
    }
    v.push_back(ans);
  }
  long long ans = 0;
  for (long long i = 0; i < v.size(); ++i) ans = max(ans, v[i]);
  cout << ans;
  return 0;
}
