#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 1;
int T, d[N << 1];
long long SumDay[N << 1], SumNum[N << 1], n, x, ans;
bool vis[N];
long long calc(long long l, long long r) {
  return (r - l + 1) * l + (r - l + 1) * (r - l) / 2;
}
int main() {
  cin >> n >> x;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
    SumDay[i] = SumDay[i - 1] + d[i];
    SumNum[i] = SumNum[i - 1] + calc(1, d[i]);
  }
  for (int i = n + 1; i <= 2 * n; i++) {
    d[i] = d[i - n];
    SumDay[i] = SumDay[i - 1] + d[i - n];
    SumNum[i] = SumNum[i - 1] + calc(1, d[i - n]);
  }
  for (int i = 2 * n; i >= 1; i--) {
    if (SumDay[i] < x) break;
    int l = 1, r = i;
    while (l < r) {
      int mid = l + r >> 1;
      if (SumDay[i] - SumDay[mid] - x <= 0)
        r = mid;
      else
        l = mid + 1;
    }
    long long temp = SumNum[i] - SumNum[l];
    long long sx = x - (SumDay[i] - SumDay[l]);
    if (sx) temp += calc(d[l] - sx + 1, d[l]);
    ans = max(ans, temp);
  }
  cout << ans << endl;
  return 0;
}
