#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) long long idx,
               __attribute__((unused)) long long LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, long long idx, long long LINE_NUM, Head H,
               Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
double get_time() { return 1.0 * clock() / CLOCKS_PER_SEC; }
void solve() {
  long long n, x;
  cin >> n >> x;
  vector<long long> d(2 * n), pref(2 * n + 1), score(2 * n),
      pref_score(2 * n + 1);
  for (long long i = 0; i < n; i++) {
    cin >> d[i];
    d[i + n] = d[i];
    score[i] = score[i + n] = (d[i] * (d[i] + 1)) / 2;
  }
  for (long long i = 0; i < 2 * n; i++) {
    pref[i + 1] = pref[i] + d[i];
    pref_score[i + 1] = score[i] + pref_score[i];
  }
  long long res = 0;
  for (long long i = 0; i < 2 * n; i++) {
    long long idx =
        lower_bound(pref.begin(), pref.begin() + i + 1, pref[i + 1] - x) -
        pref.begin();
    assert(pref[i + 1] - pref[idx] <= x);
    assert(idx == 0 || d[idx - 1] > x - (pref[i + 1] - pref[idx]));
    long long can = pref_score[i + 1] - pref_score[idx];
    if (idx > 0) {
      long long need = x - (pref[i + 1] - pref[idx]);
      can += (d[idx - 1] + d[idx - 1] - need + 1) * need / 2;
    }
    res = max(res, can);
  }
  cout << res << '\n';
}
int32_t main() {
  long long t;
  t = 1;
  while (t--) solve();
}
