#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x * f;
}
int n;
long long x, d[1000100], s[1000100], ans, now;
int main() {
  n = read(), x = read();
  for (int i = 1; i <= n; ++i) {
    d[i] = read();
    d[i + n] = d[i];
  }
  for (int r = 1, l = 1; r <= (n << 1); ++r) {
    x -= d[r];
    now += d[r] * (d[r] + 1) / 2;
    while (l <= (n << 1) && x < 0) {
      now -= d[l] * (d[l] + 1) / 2;
      x += d[l];
      ++l;
    }
    if (x > d[l - 1]) continue;
    ans = max(ans, now + (d[l - 1] + (d[l - 1] - x + 1)) * x / 2);
  }
  cout << ans << endl;
  return 0;
}
