#include <bits/stdc++.h>
using namespace std;
struct Timer {
  chrono::time_point<chrono::high_resolution_clock> start, end;
  chrono::duration<float> dur;
  Timer() { start = chrono::high_resolution_clock::now(); }
  ~Timer() {
    end = chrono::high_resolution_clock::now();
    dur = end - start;
    cout << "\nTime Elapsed : " << dur.count() << " s\n";
  }
};
long long int sum() { return 0; }
template <typename T, typename... Args>
T sum(T a, Args... args) {
  return a + sum(args...);
}
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template <typename... Args>
  Vec(int n = 0, Args... args)
      : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, T val = T()) : vector<T>(n, val) {}
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int testCases = 1;
  while (testCases--) {
    long long int n, x;
    cin >> n >> x;
    vector<long long int> d(2 * n), pref(2 * n), prefHug(2 * n);
    for (int i = 0; i < n; i++) {
      cin >> d[i];
      d[n + i] = d[i];
    }
    n *= 2;
    for (int i = 0; i < n; i++) {
      pref[i] = d[i] + (i > 0 ? pref[i - 1] : 0);
      prefHug[i] = (d[i] * (d[i] + 1)) / 2 + (i > 0 ? prefHug[i - 1] : 0);
    }
    long long int res = 0;
    for (int i = 0; i < n; i++) {
      if (pref[i] >= x) {
        int ans = distance(pref.begin(),
                           upper_bound(pref.begin(), pref.end(), pref[i] - x));
        long long int cur = prefHug[i] - prefHug[ans];
        long long int rem = x - (pref[i] - pref[ans]);
        cur += (d[ans] * (d[ans] + 1)) / 2;
        cur -= ((d[ans] - rem) * (d[ans] - rem + 1)) / 2;
        res = max(res, cur);
      }
    }
    cout << res << "\n";
  }
}
