#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, i;
  long long x;
  cin >> n >> x;
  long long pre1[2 * n + 1], pre2[2 * n + 1];
  int d[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> d[i];
  }
  pre2[0] = pre1[0] = d[0] = 0;
  for (i = 1; i <= n; i++) {
    pre2[i] = d[i];
    pre2[i + n] = pre2[i];
    pre1[i] = (1LL * d[i] * (d[i] + 1)) / 2;
    pre1[i + n] = pre1[i];
  }
  for (i = 1; i <= 2 * n; i++) {
    pre2[i] += pre2[i - 1];
    pre1[i] += pre1[i - 1];
  }
  int low, mid, high, ans;
  long long maxm = 0;
  for (i = 2 * n; i > n; i--) {
    low = 1, high = i, ans = i;
    while (low <= high) {
      mid = (low + high) / 2;
      if ((pre2[i] - pre2[mid]) < x) {
        ans = mid;
        high = mid - 1;
      } else
        low = mid + 1;
    }
    long long xtra = pre2[i] - pre2[ans - 1] - x;
    long long sum = pre1[i] - pre1[ans - 1] - ((xtra * (xtra + 1)) / 2);
    maxm = max(maxm, sum);
  }
  cout << maxm << endl;
  return 0;
}
