#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, x;
  cin >> n >> x;
  vector<long long int> d(n);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> d[i];
  vector<long long int> days(2 * n + 1);
  vector<long long int> sum(2 * n + 1);
  days[0] = 0;
  sum[0] = 0;
  for (__typeof(2 * n) i = (0) - ((0) > (2 * n));
       i != (2 * n) - ((0) > (2 * n)); i += 1 - 2 * ((0) > (2 * n))) {
    long long int k = d[i % n];
    days[i + 1] = days[i] + k;
    sum[i + 1] = sum[i] + (k * (k + 1)) / 2;
  }
  long long int ans = 0;
  for (__typeof(2 * n + 1) i = (n + 1) - ((n + 1) > (2 * n + 1));
       i != (2 * n + 1) - ((n + 1) > (2 * n + 1));
       i += 1 - 2 * ((n + 1) > (2 * n + 1))) {
    if (days[i] >= x) {
      long long int idx =
          upper_bound(days.begin(), days.end(), days[i] - x) - days.begin();
      long long int hugs = sum[i] - sum[idx];
      long long int rem = x - days[i] + days[idx];
      rem = days[idx] - days[idx - 1] - rem;
      hugs += sum[idx] - sum[idx - 1] - ((rem) * (rem + 1)) / 2;
      ans = max(hugs, ans);
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int test;
  test = 1;
  while (test--) {
    solve();
    cout << '\n';
  }
  return 0;
}
