#include <bits/stdc++.h>
using namespace std;
int n;
long long pre[500010], pre2[500010], d[500010], x;
void code() {
  cin >> n >> x;
  for (int i = 1; i < n + 1; i++) {
    cin >> d[i];
    d[i + n] = d[i];
  }
  n *= 2;
  for (int i = 1; i < n + 1; i++) {
    pre[i] = pre[i - 1] + d[i];
    pre2[i] = pre2[i - 1] + (d[i] * (d[i] + 1)) / 2;
  }
  long long res = 0;
  for (int i = 1; i < n + 1; i++) {
    long long tmp = pre[i] - x;
    int j = upper_bound(pre, pre + n, tmp) - pre;
    if (j <= 0) continue;
    long long ans = pre2[i] - pre2[j - 1];
    long long left = x - pre[i] + pre[j];
    long long rem = d[j] - left;
    ans -= (rem * (rem + 1)) / 2;
    res = max(res, ans);
  }
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    code();
  }
}
