#include <bits/stdc++.h>
using namespace std;
int n, d[410000];
long long x, res, s[410000], a[410000];
int main() {
  scanf("%d%I64d", &n, &x);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = n + 1; i <= 2 * n; i++) d[i] = d[i - n];
  for (int i = 1; i <= 2 * n; i++) s[i] = s[i - 1] + d[i];
  for (int i = 1; i <= 2 * n; i++) a[i] = a[i - 1] + (1ll + d[i]) * d[i] / 2;
  for (int i = n + 1; i <= 2 * n; i++) {
    int l = 1, r = i;
    long long t, ans;
    while (l < r) {
      int mid = l + r >> 1;
      if (s[i] - s[mid - 1] > x) {
        l = mid + 1;
      } else {
        r = mid;
      }
    }
    t = x - (s[i] - s[l - 1]);
    if (l == i && t <= 0) {
      ans = (2ll * d[l] - x + 1) * x / 2;
    } else {
      ans = (2ll * d[l - 1] - t + 1) * t / 2 + (a[i] - a[l - 1]);
    }
    res = max(ans, res);
  }
  printf("%lld\n", res);
}
