#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  int t = 1;
  while (t--) {
    long long n, m, i, j, k, a, b, x, y, z, w, t1, t2, t3, ans = 0;
    cin >> n >> x;
    vector<long long> v(2 * n + 1), pre1(2 * n + 1, 0), pre2(2 * n + 1, 0);
    for (i = 1; i <= n; i++) cin >> v[i];
    for (i = n + 1; i <= 2 * n; i++) v[i] = v[i - n];
    n = 2 * n;
    for (i = 1; i <= n; i++)
      pre1[i] = pre1[i - 1] + v[i],
      pre2[i] = pre2[i - 1] + (v[i] * (v[i] + 1)) / 2;
    for (i = 1; i <= n; i++) {
      if (v[i] >= x) {
        ans = max(ans, (x * (x + 1)) / 2 + (x * (v[i] - x)));
      } else {
        j = lower_bound(pre1.begin() + 1, pre1.end(), x + pre1[i - 1]) -
            pre1.begin();
        if (j > n) break;
        y = pre2[j - 1] - pre2[i - 1];
        z = x - (pre1[j - 1] - pre1[i - 1]);
        y += (z * (z + 1)) / 2;
        ans = max(ans, y);
      }
    }
    reverse(v.begin() + 1, v.end());
    for (i = 1; i <= n; i++)
      pre1[i] = pre1[i - 1] + v[i],
      pre2[i] = pre2[i - 1] + (v[i] * (v[i] + 1)) / 2;
    for (i = 1; i <= n; i++) {
      if (v[i] >= x) {
        ans = max(ans, (x * (x + 1)) / 2 + (x * (v[i] - x)));
      } else {
        j = lower_bound(pre1.begin() + 1, pre1.end(), x + pre1[i - 1]) -
            pre1.begin();
        if (j > n) break;
        y = pre2[j - 1] - pre2[i - 1];
        z = x - (pre1[j - 1] - pre1[i - 1]);
        y += (z * (z + 1)) / 2 + z * (v[j] - z);
        ans = max(ans, y);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
