#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long int n, x;
  std::cin >> n >> x;
  vector<long long int> d(n);
  for (long long int i = 0; i < n; i++) scanf("%lld", &d[i]);
  vector<long long int> st(n, 10000000000), amari(n), hugs(n, 0);
  long long int y = x, prev = 0, ad = 0, h = 0;
  for (long long int i = 0; i < n; i++) {
    y += ad;
    st[i] = prev - 1;
    if (d[i] > x) {
      st[i] = i;
      amari[i] = x;
      ad = 0;
      prev = i + 1;
      y = x;
      h = 0;
      continue;
    }
    for (int j = prev % n;; j = (j + 1) % n) {
      if (y >= d[j]) {
        st[i] = j;
        y -= d[j];
        h += (d[j] * (d[j] + 1)) / 2;
      } else
        break;
    }
    hugs[i] = h;
    h -= (d[i] * (d[i] + 1)) / 2;
    st[i] = (st[i] + 1) % n;
    amari[i] = y;
    ad = min(d[i], x);
    prev = st[i];
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    long long int to = st[i];
    long long int base = hugs[i];
    long long int z = min(d[i], d[to] - amari[i]);
    ans = max(ans, base - (z * (z + 1)) / 2 +
                       ((amari[i] + z) * (amari[i] + z + 1)) / 2);
  }
  std::cout << ans << '\n';
  return 0;
}
