#include <bits/stdc++.h>
template <class T>
inline void rd(T &x) {
  char c = getchar(), f = 0;
  x = 0;
  while (!isdigit(c)) f = (c == '-'), c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x = f ? -x : x;
}
const int MAXN = 4e5 + 7;
int n, d[MAXN];
long long pre[MAXN], prei[MAXN];
long long k;
long long cal(int a, int b) { return 1ll * (a + b) * (b - a + 1) / 2; }
int main() {
  rd(n), rd(k);
  for (int i = (1); i <= (n); ++i) rd(d[i]);
  for (int i = (n + 1); i <= (2 * n); ++i) d[i] = d[i - n];
  for (int i = (1); i <= (2 * n); ++i)
    pre[i] = pre[i - 1] + d[i], prei[i] = prei[i - 1] + cal(1, d[i]);
  long long ans = LLONG_MIN;
  for (int l = (1); l <= (n); ++l) {
    int r = std::lower_bound(pre + 1, pre + 2 * n + 1, k + pre[l - 1]) - pre;
    long long tmp = prei[r - 1] - prei[l - 1];
    int lenb = k - (pre[r - 1] - pre[l - 1]);
    tmp += cal(1, lenb);
    int mn = std::min(d[l] - 1, d[r] - lenb);
    tmp -= cal(1, mn);
    tmp += cal(lenb + 1, lenb + mn);
    ans = std::max(ans, tmp);
  }
  printf("%lld\n", ans);
  return 0;
}
