#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, x;
  cin >> n >> x;
  vector<long long int> v(2 * n), p(2 * n), sum(2 * n);
  for (int i = 0; i < (int)n; i++) {
    cin >> v[i];
    sum[i] = (1 + v[i]) * v[i] / 2;
  }
  for (int i = 0; i < (int)n; i++) {
    v[n + i] = v[i];
    sum[n + i] = sum[i];
  }
  vector<long long int> psum(2 * n);
  psum[0] = sum[0];
  for (int i = 1; i < 2 * n; i++) psum[i] = psum[i - 1] + sum[i];
  p[0] = v[0];
  for (int i = 1; i < 2 * n; i++) p[i] = p[i - 1] + v[i];
  long long int ans = 0;
  for (int i = 0; i < (int)2 * n; i++) {
    if (p[i] < x) continue;
    long long int idx = lower_bound(p.begin(), p.end(), p[i] - x) - p.begin();
    long long int days = x - (p[i] - p[idx]);
    long long int curr_ans =
        sum[idx] - ((1 + v[idx] - days) * (v[idx] - days) / 2);
    curr_ans += psum[i] - psum[idx];
    ans = max(ans, curr_ans);
  }
  cout << ans << endl;
  return 0;
}
