#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
int n;
long long x;
long long d[maxn * 2];
long long suf[maxn * 2];
long long pre[maxn * 2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
  }
  for (int i = n + 1; i <= n * 2; i++) {
    d[i] = d[i - n];
  }
  for (int i = 2 * n; i >= 1; i--) {
    suf[i] = d[i] + suf[i + 1];
  }
  for (int i = 1; i <= n * 2; i++) {
    pre[i] = pre[i - 1] + d[i] * (d[i] + 1) / 2;
  }
  long long ans = 0;
  for (int i = n + 1; i <= 2 * n; i++) {
    long long max1 = 0;
    long long temp = x + suf[i + 1];
    int p =
        upper_bound(suf + 1, suf + 1 + 2 * n, temp, greater<long long>()) - suf;
    max1 += pre[i] - pre[p - 1];
    temp -= suf[p];
    max1 += d[p - 1] * temp - temp * (temp - 1) / 2;
    ans = max(ans, max1);
  }
  cout << ans << '\n';
}
