#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, X;
  cin >> N >> X;
  vector<long long> d(2 * N);
  for (int i = 0; i < N; i++) {
    long long D;
    cin >> D;
    d[i] = D;
  }
  for (int i = 0; i < N; i++) d[i + N] = d[i];
  vector<long long> dsum;
  dsum.push_back(0);
  for (int i = 0; i < 2 * N; i++) dsum.push_back(dsum[i] + d[i]);
  vector<long long> hsum;
  hsum.push_back(0);
  for (int i = 0; i < 2 * N; i++)
    hsum.push_back(hsum[i] + d[i] * (d[i] + 1) / 2);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (X <= d[i]) {
      ans = max(ans, (d[i] - X + 1 + d[i]) * X / 2);
    } else {
      auto it = upper_bound(dsum.begin(), dsum.end(), X + dsum[i]);
      it--;
      int month = it - dsum.begin();
      long long day = X + dsum[i] - dsum[month];
      long long tmp = hsum[month] - hsum[i];
      long long dday = min(d[i] - 1, d[month] - day);
      tmp += (day + dday) * (day + dday + 1) / 2 - dday * (dday + 1) / 2;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
