#include <bits/stdc++.h>
using namespace std;
long long sum(long long x) {
  x = x * (x + 1);
  return x / 2;
}
int main() {
  long long n, x;
  cin >> n >> x;
  long long i, a[2 * n], a2[2 * n], a3[2 * n];
  for (i = 0; i < n; i++) cin >> a[i];
  for (; i < 2 * n; i++) a[i] = a[i - n];
  a2[0] = sum(a[0]);
  for (i = 1; i < 2 * n; i++) {
    a2[i] = a2[i - 1] + sum(a[i]);
  }
  a3[0] = a[0];
  for (i = 1; i < 2 * n; i++) a3[i] = a3[i - 1] + a[i];
  long long cnt = 0;
  for (i = n; i < 2 * n; i++) {
    long long l = i - n, r = i, mid, ans;
    while (l <= r) {
      mid = (l + r) / 2;
      if (a3[mid] > a3[i] - x) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    long long an = a2[i];
    an = an - a2[ans];
    long long x2 = x;
    x2 = x2 - (a3[i] - a3[ans]);
    long long y = a[ans];
    an += sum(y) - sum(y - x2);
    cnt = max(cnt, an);
  }
  cout << cnt;
  return 0;
}
