#include <bits/stdc++.h>
using namespace std;
void shikhar7s(long long int cas) {
  long long int n, i, x, s, f = 0, l, r;
  cin >> n >> x;
  long long int a[n];
  vector<long long int> v(2 * n + 1, 0), ans(2 * n + 1, 0);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    f = max(a[i], f);
    s = (a[i] * (a[i] + 1)) / 2;
    ans[i + 1] = ans[i] + s;
    v[i + 1] = v[i] + a[i];
  }
  if (f >= x) {
    l = (f * (f + 1)) / 2;
    r = f - x;
    r = (r * (r + 1)) / 2;
    cout << l - r;
    return;
  }
  for (i = 0; i < n; i++) {
    v[i + n + 1] = v[i + n] + a[i];
    s = (a[i] * (a[i] + 1)) / 2;
    ans[i + n + 1] = ans[i + n] + s;
  }
  long long int j, fa = 0;
  for (i = 0; i < n; i++) {
    j = lower_bound(v.begin(), v.end(), v[i] + x) - v.begin();
    j--;
    s = x + v[i] - v[j];
    if (a[i] - 1 < a[(j % n)] - s) {
      l = ans[j] - ans[i + 1];
      l += a[i];
      r = s + a[i] - 1;
      l += (r * (r + 1)) / 2;
    } else {
      l = ans[j + 1] - ans[i];
      r = a[(j % n)] - s;
      l -= (r * (r + 1)) / 2;
    }
    fa = max(fa, l);
  }
  cout << fa;
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  long long int cas = 1;
  while (cas <= t) {
    shikhar7s(cas);
    cas++;
  }
  return 0;
}
