#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long d[2 * N];
long long h[2 * N];
long long t[2 * N];
long long ans;
int main() {
  int n;
  long long x;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
    d[i + n] = d[i];
  }
  for (int i = 1; i <= 2 * n; i++) {
    t[i] = t[i - 1] + d[i];
    h[i] = h[i - 1] + (1 + d[i]) * d[i] / 2;
  }
  int ct = 0;
  for (int i = 1; i <= 2 * n; i++) {
    if (t[i] >= x) {
      ct++;
      long long p = lower_bound(t + 1, t + 2 * n + 1, t[i] - x) - t;
      long long res = x - (t[i] - t[p]);
      long long last1 = (d[p] * (d[p] + 1)) / 2;
      long long last = last1 - (d[p] - res) * (d[p] - res + 1) / 2;
      ans = max(ans, last + h[i] - h[p]);
    }
    if (ct == n) break;
  }
  cout << ans << endl;
}
