#include <bits/stdc++.h>
using namespace std;
long long sum(long long x) { return x * (x + 1) / 2; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n = 0, x = 0, tot = 0, ans = 0, last = 1, ind = 0, cur = 0;
  cin >> n >> x;
  vector<long long> d(2 * n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    d[i + n] = d[i];
  }
  vector<long long> prefd(2 * n + 1, 0), preft(2 * n + 1, 0);
  for (int i = 0; i < 2 * n; i++) {
    prefd[i + 1] = prefd[i] + d[i];
    preft[i + 1] = preft[i] + sum(d[i]);
  }
  for (int end = n + 1, first = 0; end <= 2 * n; end++) {
    while (first < end && prefd[end] - prefd[first + 1] >= x) first++;
    long long cur = preft[end] - preft[first + 1];
    long long days_in_f = x - (prefd[end] - prefd[first + 1]);
    cur += sum(d[first]) - sum(d[first] - days_in_f);
    ans = max(ans, cur);
  }
  cout << ans;
  return 0;
}
