#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-14;
const long long maxn = 100500;
const long long mod = 1e9 + 7;
vector<long long> cnt, sum;
long long n, x;
long long get(long long x) { return x * (x + 1) / 2; }
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  long long ans = 0;
  vector<long long> a(n);
  for (auto &x : a) cin >> x;
  for (long long i = 0; i < n; ++i) a.push_back(a[i]);
  cnt.push_back(a[0]);
  sum.push_back(a[0] * (a[0] + 1) / 2);
  for (long long i = 1; i < 2 * n; ++i) {
    cnt.push_back(cnt.back() + a[i]);
    sum.push_back(sum.back() + get(a[i]));
  }
  for (long long i = 0; i < 2 * n - 1; ++i) {
    if (x < a[i]) {
      ans = max(ans, get(a[i]) - get(a[i] - x));
      continue;
    }
    long long lo = i + 1, hi = 2 * n - 1;
    long long rem = x - a[i];
    while (lo <= hi) {
      long long mid = (lo + hi) >> 1;
      if (cnt[mid] - cnt[i] <= rem)
        lo = mid + 1;
      else
        hi = mid - 1;
    }
    if (lo == 2 * n) break;
    rem -= cnt[lo - 1] - cnt[i];
    long long d = a[lo] - rem;
    long long ad = sum[lo - 1] - sum[i];
    if (d > a[i]) {
      ad += get(rem + a[i]);
    } else {
      ad += get(a[lo]) + get(a[i]) - get(d);
    }
    ans = max(ans, ad);
  }
  cout << ans << '\n';
  return 0;
}
