#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n;
long long x, ans, a[N * 2], s[N * 2], d[N * 2], sh[N * 2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    a[i] = (d[i] + 1) * d[i] / 2;
    d[n + i] = d[i];
    a[n + i] = a[i];
  }
  for (int i = 1; i <= 2 * n; i++) {
    s[i] = s[i - 1] + d[i];
    sh[i] = sh[i - 1] + a[i];
  }
  for (int i = 1; i <= 2 * n; i++) {
    if (s[i] >= x) {
      int l = 1, r = i;
      while (l < r) {
        int m = (l + r + 1) >> 1;
        if (s[i] - s[m - 1] > x) {
          l = m;
        } else {
          r = m - 1;
        }
      }
      long long re = x - (s[i] - s[l]);
      ans = max(ans, sh[i] - sh[l] + re * (d[l] + d[l] - re + 1) / 2);
    }
    if (s[2 * n] - s[i] + 1 > x) {
      int l = i, r = 2 * n;
      while (l < r) {
        int m = (l + r) >> 1;
        if (s[m] - s[i] + 1 <= x) {
          l = m + 1;
        } else {
          r = m;
        }
      }
      long long re = x - (s[l - 1] - s[i] + 1);
      ans = max(ans, d[i] + sh[l - 1] - sh[i] + re * (1 + re) / 2);
    }
  }
  cout << ans << "\n";
}
