#include <bits/stdc++.h>
using namespace std;
long long int a[500001], pref[500001], valv[500001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int t, i, j, k, l, m = 0, n, o, p, q, r, s, x;
  cin >> n >> x;
  pref[0] = 0;
  valv[0] = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    valv[i + 1] = valv[i] + (a[i] * (a[i] + 1)) / 2;
    a[i + n] = a[i];
    pref[i + 1] = pref[i] + a[i];
    m = max(m, a[i]);
  }
  for (i = n; i < 2 * n; i++) {
    pref[i + 1] = pref[i] + a[i];
    valv[i + 1] = valv[i] + (a[i] * (a[i] + 1)) / 2;
  }
  long long int ans = 0;
  if (m >= x) {
    while (x > 0) {
      ans += m;
      m--;
      x--;
    }
    cout << ans << "\n";
    return 0;
  }
  for (i = 0; i < 2 * n; i++) {
    long long int start = 0;
    long long int end = i, index = 0;
    while (start <= end) {
      long long int mid = (start + end) / 2;
      if (pref[i + 1] - pref[mid] >= x) {
        index = mid;
        start = mid + 1;
      } else {
        end = mid - 1;
      }
    }
    long long int ss = pref[i + 1] - pref[index + 1], ans1, s1, s2;
    ans1 = valv[i + 1] - valv[index + 1];
    long long int sum = x - ss;
    s1 = a[index];
    ans1 += (s1 * (s1 + 1)) / 2;
    long long int z = max(0LL, s1 - sum);
    ans1 -= (z * (z + 1)) / 2;
    ans = max(ans1, ans);
  }
  cout << ans << "\n";
  return 0;
}
