#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  long long x;
  cin >> n >> x;
  long long d[n];
  for (int i = 0; i < n; ++i) cin >> d[i];
  long long sum[n], tri_sum[n];
  sum[0] = d[0];
  tri_sum[0] = d[0] * (d[0] + 1) / 2;
  for (int i = 1; i < n; ++i) {
    sum[i] = sum[i - 1] + d[i];
    tri_sum[i] = tri_sum[i - 1] + d[i] * (d[i] + 1) / 2;
  }
  long long answer = 0;
  for (int i = 0; i < n; ++i) {
    bool wrap = (x > sum[i]);
    long long target = sum[i] - x;
    if (wrap) target += sum[n - 1];
    int lo = 0;
    int hi = n - 1;
    int bs_ind = -1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      if (lo == hi) {
        bs_ind = mid;
        break;
      }
      if (target == sum[mid]) {
        bs_ind = mid;
        break;
      }
      if (target > sum[mid]) {
        lo = mid + 1;
      } else {
        hi = mid;
      }
    }
    long long after = tri_sum[i] - tri_sum[bs_ind];
    long long extra = target;
    if (bs_ind > 0) extra -= sum[bs_ind - 1];
    long long curr = d[bs_ind] * (d[bs_ind] + 1) / 2 - extra * (extra + 1) / 2;
    long long hugs = curr + after;
    if (wrap) hugs += tri_sum[n - 1];
    answer = max(answer, hugs);
  }
  cout << answer << '\n';
}
