#include <bits/stdc++.h>
const long long N = 2e5 + 5;
const long long M = 2e5 + 5;
const long long mod = 998244353;
using namespace std;
long long a[2 * N];
long long sum[2 * N];
long long ANS[2 * N];
signed main() {
  long long n, x;
  cin >> n >> x;
  for (long long i = (1); i <= (n); i++) {
    cin >> a[i];
  }
  for (long long i = (n + 1); i <= (2 * n); i++) {
    a[i] = a[i - n];
  }
  for (long long i = (1); i <= (2 * n); i++) {
    sum[i] = sum[i - 1] + a[i];
    ANS[i] = ANS[i - 1] + (a[i] + 1) * (a[i]) / 2;
  }
  long long ans = 0;
  for (long long i = (1); i <= (2 * n); i++) {
    long long pos = lower_bound(sum + i, sum + 2 * n + 1, x + sum[i - 1]) - sum;
    long long xx = (x - (sum[pos - 1] - sum[i - 1]) + 1) *
                   (x - (sum[pos - 1] - sum[i - 1])) / 2;
    long long tmp = x - (sum[pos - 1] - sum[i - 1]);
    if (pos == i) {
      ans = max(ans, (1 + a[pos]) * (a[pos]) / 2 -
                         (a[pos] - x + 1) * (a[pos] - x) / 2);
    } else if (tmp <= a[pos]) {
      ans = max(ans, ANS[pos - 1] - ANS[i - 1] + xx + (tmp) * (a[pos] - (tmp)));
    }
  }
  cout << ans << endl;
  return 0;
}
