#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
long long a[maxn], b[maxn], pre[maxn];
int main() {
  long long n, x;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
    b[i] = b[i - 1] + a[i];
    pre[i] += pre[i - 1] + a[i] * (a[i] + 1) / 2;
  }
  for (int i = n + 1; i <= 2 * n; i++) {
    pre[i] = pre[i - 1] + a[i] * (a[i] + 1) / 2;
    b[i] = b[i - 1] + a[i];
  }
  long long ans = 0;
  for (int i = n + 1; i <= 2 * n; i++) {
    int j = upper_bound(b + 1, b + 2 * n + 1, b[i] - x) - (b + 1);
    j++;
    long long temp = x - (b[i] - b[j]);
    long long sum =
        a[j] * (a[j] + 1) / 2 - (a[j] - temp) * (1 + a[j] - temp) / 2;
    ans = max(ans, pre[i] - pre[j] + sum);
  }
  cout << ans;
  return 0;
}
