#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, len;
  cin >> n >> len;
  vector<long long> A(2 * n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    A[n + i] = A[i];
  }
  n *= 2;
  vector<long long> B = {0}, C = {0};
  for (int i = 0; i < n; ++i) {
    B.push_back(B.back() + A[i]);
  }
  for (int i = 0; i < n; ++i) {
    C.push_back(C.back() + (A[i] * (A[i] + 1)) / 2);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (B[i + 1] >= len) {
      long long z = upper_bound(B.begin(), B.end(), B[i + 1] - len) - B.begin();
      long long cnt = C[i + 1] - C[z];
      long long days = B[i + 1] - B[z];
      long long too = len - days;
      cnt += ((A[z - 1] * (A[z - 1] + 1)) / 2);
      cnt -= (((A[z - 1] - too) * (A[z - 1] - too + 1)) / 2);
      ans = max(ans, cnt);
    }
  }
  cout << ans;
  return 0;
}
