#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, x;
  cin >> n >> x;
  vector<long long> v(2 * n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    v[n + i] = v[i];
  }
  n += n;
  vector<long long> b, c;
  b.push_back(0), c.push_back(0);
  for (long long i = 0; i < n; i++) {
    b.push_back(b.back() + v[i]);
  }
  for (long long i = 0; i < n; i++) {
    c.push_back(c.back() + (v[i] * (v[i] + 1) / 2));
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (b[i + 1] >= x) {
      long long z = upper_bound(b.begin(), b.end(), b[i + 1] - x) - b.begin();
      long long cnt = b[i + 1] - b[z];
      long long sum = c[i + 1] - c[z];
      long long mid = x - cnt;
      sum += (v[z - 1] * (v[z - 1] + 1) / 2);
      sum -= ((v[z - 1] - mid) * (v[z - 1] - mid + 1) / 2);
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}
