#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool umax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
long long POW(long long a, long long p, long long M) {
  if (!p) return 1LL;
  long long T = POW(a, p / 2, M);
  T = T * T % M;
  if (p & 1) T = T * (a % M) % M;
  return T;
}
long long SQRT(long long a) {
  long long b = (long long)sqrtl(((double)a) + 0.5);
  while (b * b < a) ++b;
  while (b * b > a) --b;
  return (b * b == a) ? b : -1;
}
const long long MOD = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  long long n, x;
  cin >> n >> x;
  vector<long long> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  long long ans = 0;
  int l, r;
  l = r = 0;
  long long sm = 0;
  long long tsm = 0;
  while (l < n) {
    long long here = 0;
    while (sm < x) {
      sm += d[r];
      tsm += d[r] * (d[r] + 1) / 2;
      r++;
      r %= n;
    }
    int lst = r - 1 + n;
    lst %= n;
    if (l == lst) {
      here = d[l] * (d[l] + 1) / 2;
      here -= (d[l] - x) * (d[l] - x + 1) / 2;
    } else {
      long long lft = sm - x;
      long long usd = d[lst] - lft;
      lft = min(lft, d[l]);
      here = tsm - (d[lst] * (d[lst] + 1) / 2);
      here -= lft * (lft + 1) / 2;
      usd += lft;
      here += usd * (usd + 1) / 2;
    }
    umax(ans, here);
    sm -= d[l];
    tsm -= d[l] * (d[l] + 1) / 2;
    l++;
  }
  cout << ans << endl;
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}
