#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, days;
  cin >> n >> days;
  long long a[2 * n + 1];
  long long prefixDays[2 * n + 1];
  long long pre2[2 * n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[n + i] = a[i];
  }
  for (int i = 1; i <= 2 * n; i++) {
    prefixDays[i] = prefixDays[i - 1] + (a[i] * (a[i] + 1)) / 2;
    pre2[i] = pre2[i - 1] + a[i];
  }
  long long maxi = 0;
  for (int i = 2 * n; i >= n + 1; i--) {
    int ans = upper_bound(pre2, pre2 + 2 * n, pre2[i] - days) - pre2;
    long long temp = pre2[i] - pre2[ans - 1] - days;
    long long sum = prefixDays[i] - prefixDays[ans - 1];
    sum -= (temp * (temp + 1)) / 2;
    maxi = max(maxi, sum);
  }
  cout << maxi << endl;
  return 0;
}
