#include <bits/stdc++.h>
using namespace std;
int n, lft, rgt, pos;
long long sum, total, x, sol;
long long d[400005];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> x;
  for (int i = 1; i <= n; ++i) {
    cin >> d[i];
    d[n + i] = d[i];
  }
  lft = pos = 1;
  while (rgt <= 2 * n) {
    while (total <= x && rgt <= 2 * n) {
      ++rgt;
      total += d[rgt];
      sum += 1LL * d[rgt] * (d[rgt] + 1) / 2LL;
      if (total == x) {
        long long elim = total - x;
        sol = max(sol, sum - 1LL * elim * (elim + 1) / 2LL);
      }
    }
    while (total > x) {
      if (total - d[lft] < x) {
        long long elim = total - x;
        sol = max(sol, sum - 1LL * elim * (elim + 1) / 2LL);
      }
      total -= d[lft];
      sum -= 1LL * d[lft] * (d[lft] + 1) / 2LL;
      ++lft;
    }
  }
  cout << sol;
  return 0;
}
