#include <bits/stdc++.h>
using namespace std;
long long a[1000005];
long long v[1000005];
long long pre[1000005];
long long vpre[1000005];
int main() {
  v[0] = 0;
  vpre[0] = pre[0] = 0;
  for (int i = 1; i <= 1000000; i++) {
    v[i] = v[i - 1] + i;
  }
  int n;
  long long x;
  scanf("%d%lld", &n, &x);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[n + i] = a[i];
    pre[i] = pre[i - 1] + a[i];
    vpre[i] = vpre[i - 1] + v[a[i]];
  }
  for (int i = n + 1; i <= 2 * n; i++) {
    pre[i] = pre[i - 1] + a[i];
    vpre[i] = vpre[i - 1] + v[a[i]];
  }
  int l = 1;
  long long res = 0;
  for (int i = n; i <= 2 * n; i++) {
    int pos = upper_bound(pre + 1, pre + 1 + 2 * n, pre[i] - x) - pre;
    if (pos == i) {
      res = max(res, (a[i] + a[i] - x + 1) * x / 2);
    } else {
      long long num = pre[i] - pre[pos];
      long long rd = x - num;
      res = max(res, vpre[i] - vpre[pos] + (a[pos] + a[pos] - rd + 1) * rd / 2);
    }
  }
  printf("%lld\n", res);
}
