#include <bits/stdc++.h>
using namespace std;
vector<long long> v, vc, gg;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    vc.push_back(a);
    gg.push_back(a * (a + 1) / 2);
  }
  for (i = 0; i < n; i++) {
    v.push_back(v[i]);
    vc.push_back(vc[i]);
    gg.push_back(gg[i]);
  }
  n *= 2;
  for (i = 1; i < n; i++) {
    vc[i] += vc[i - 1];
    gg[i] += gg[i - 1];
  }
  p = 0;
  while (vc[p] < k) p++;
  long long ans = 0;
  for (i = p; i < n; i++) {
    long long en = vc[i];
    long long st = en - k + 1;
    d = lower_bound(vc.begin(), vc.end(), st) - vc.begin();
    f = gg[i] - (d > 0 ? gg[d - 1] : 0LL);
    l = k - (vc[i] - vc[d]);
    b = v[d] - l;
    f -= b * (b + 1) / 2;
    ans = max(ans, f);
  }
  cout << ans << '\n';
  return 0;
}
