#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353, INF = 1e18;
int main() {
  long long n, x, ans = 0;
  cin >> n >> x;
  vector<long long> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    c[i] = a[i];
    b[i] = a[i];
    a[i] = (a[i] * (a[i] + 1)) / 2;
    if (i) {
      b[i] += b[i - 1];
      a[i] += a[i - 1];
    }
  }
  for (int i = 0; i < n; i++) {
    a.push_back(a[i] + a[n - 1]);
    b.push_back(b[i] + b[n - 1]);
    c.push_back(c[i]);
  }
  for (int i = 0; i < n; i++) {
    long long res;
    int itr;
    if (i)
      itr = lower_bound(b.begin(), b.end(), x + b[i - 1]) - b.begin();
    else
      itr = lower_bound(b.begin(), b.end(), x) - b.begin();
    if (i == itr) {
      if (i) {
        long long m = b[i] - b[i - 1] - x;
        res = a[i] - a[i - 1] - (m * (m + 1)) / 2;
      } else {
        long long m = b[i] - x;
        res = a[i] - (m * (m + 1)) / 2;
      }
    } else {
      if (i) {
        long long m = b[itr] - b[i - 1] - x;
        long long mn = c[itr] - m;
        if (m <= c[i]) {
          if (m < 0) m = 0;
          res = a[itr] - a[i - 1] - (m * (m + 1)) / 2;
        } else {
          m = c[i];
          res = a[itr - 1] - a[i - 1] + ((m + mn) * (m + mn + 1)) / 2 -
                (m * (m + 1)) / 2;
        }
      } else if (itr) {
        long long m = b[itr] - x;
        long long mn = c[itr] - m;
        if (m <= c[i])
          res = a[itr] - (m * (m + 1)) / 2;
        else {
          m = c[i];
          res = a[itr - 1] + ((m + mn) * (m + mn + 1)) / 2 - (m * (m + 1)) / 2;
        }
      } else {
        long long m = b[itr] - x;
        res = a[itr] - (m * (m + 1)) / 2;
      }
    }
    ans = max(ans, res);
  }
  cout << ans << "\n";
  return 0;
}
