#include <bits/stdc++.h>
using namespace std;
long long int d[200007] = {};
long long int s[200007] = {};
long long int cal(long long int u, long long int d) {
  long long int h = u - d + 1;
  if (1 != 0 && 0 == 1) printf("cal >>> %lld\n", (u + d) * h / 2);
  return (u + d) * h / 2;
}
int main() {
  int i, j;
  int n;
  long long int x;
  scanf("%d %lld", &n, &x);
  for (i = 0; i < n; i++) {
    scanf("%lld", &d[i]);
  }
  for (i = 0; i < n; i++) {
    s[i] = cal(d[i], 1);
  }
  long long int day = 0;
  long long int sum = 0;
  for (i = n - 1; i >= 0; i--) {
    day += d[i];
    sum += s[i];
    if (day > x) break;
  }
  long long int ans = sum - s[i] + cal(d[i], d[i] - (x - day + d[i]) + 1);
  j = i;
  if (1 != 0 && 0 == 1) printf("origin( %d, %d): %lld\n", j, n - 1, ans);
  for (i = 0; i < n; i++) {
    day += d[i];
    sum += s[i];
    for (; day - d[j] > x; j = (j + 1) % n) {
      day -= d[j];
      sum -= s[j];
    }
    long long int val = sum - s[j] + cal(d[j], d[j] - (x - day + d[j]) + 1);
    if (1 != 0 && 0 == 1) printf("( %d, %d) = %lld\n", j, i, val);
    ans = max(ans, val);
  }
  printf("%lld\n", ans);
  return 0;
}
