#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
ll const N = 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, a;
  cin >> n >> a;
  vector<ll> v(n * 2), smdays, values;
  for (int var = 0; var < n; ++var) {
    cin >> v[var];
    v[var + n] = v[var];
  }
  smdays.push_back(0);
  values.push_back(0);
  for (int var = 0; var < n * 2; ++var) {
    if (!var) {
      smdays.push_back(v[var]);
      values.push_back(v[var] * (v[var] + 1) / 2);
    } else
      smdays.push_back(smdays.back() + v[var]),
          values.push_back(values.back() + v[var] * (v[var] + 1) / 2);
  }
  ll res = 0;
  for (int var = 0; var < n * 2; ++var) {
    if (smdays[var] >= a) {
      ll indx = upper_bound(smdays.begin(), smdays.end(), smdays[var] - a) -
                smdays.begin();
      ll nmofdays = 0, ans = 0;
      nmofdays = smdays[var] - smdays[indx];
      ans = values[var] - values[indx];
      ll total = a - nmofdays;
      ans += v[indx - 1] * (v[indx - 1] + 1) / 2;
      ans -= (v[indx - 1] - total) * (v[indx - 1] - total + 1) / 2;
      res = max(res, ans);
    }
  }
  cout << res << '\n';
  return 0;
}
