#include <bits/stdc++.h>
using namespace std;
long long int get(long long int x) { return (long long int)(x * (x + 1)) / 2; }
void solve() {
  long long int n, x;
  cin >> n >> x;
  vector<long long int> a(2 * n);
  vector<long long int> msum(2 * n);
  vector<long long int> ksum(2 * n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
  }
  msum[0] = a[0];
  for (int i = 1; i < 2 * n; i++) msum[i] = msum[i - 1] + a[i];
  ksum[0] = get(a[0]);
  for (int i = 1; i < 2 * n; i++) ksum[i] = ksum[i - 1] + get(a[i]);
  long long int ans = 0;
  for (int i = 0; i < 2 * n; i++) {
    if (msum[i] < x) continue;
    int idx = upper_bound(msum.begin(), msum.end(), msum[i] - x) - msum.begin();
    if (msum[i] == x)
      ans = max(ans, ksum[i]);
    else {
      long long int left = (msum[i] - msum[idx] + a[idx]) - x;
      ans = max(ans, ksum[i] - ksum[idx] + get(a[idx]) - get(left));
    }
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  ;
  solve();
}
