#include <bits/stdc++.h>
using namespace std;
long long pM[400004];
long long pD[400004];
long long M[400004];
void solve() {
  int n;
  cin >> n;
  long long x;
  cin >> x;
  for (int i = 0; i < n; i++) {
    cin >> M[i];
  }
  for (int i = n; i < 2 * n; i++) {
    M[i] = M[i - n];
  }
  reverse(M, M + 2 * n);
  for (int i = 0; i < 2 * n; i++) {
    if (i == 0) {
      pM[0] = M[i];
      pD[0] = (M[i] * (M[i] + 1)) / 2;
    } else {
      pM[i] = pM[i - 1] + M[i];
      pD[i] = pD[i - 1] + (M[i] * (M[i] + 1)) / 2;
    }
  }
  long long fans = -1e10;
  for (int i = 0; i < n; i++) {
    long long ans = 0;
    long long tx = x;
    int pos = upper_bound(pM, pM + 2 * n, x) - pM;
    pos--;
    ans += pD[pos];
    if (i > 0) ans -= pD[i - 1];
    tx -= pM[pos];
    ans += tx * (M[pos + 1] + 1) - (tx * (tx + 1)) / 2;
    x += M[i];
    fans = max(fans, ans);
  }
  cout << fans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }
  return 0;
}
