#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 4;
long long psum(long long n) { return n * (n + 1) / 2; }
long long rsum(long long l, long long r) { return psum(r) - psum(l - 1); }
int main() {
  int n;
  long long x;
  scanf("%d", &n);
  scanf("%lld", &x);
  long long a[2 * n], pre[2 * n], profit[2 * n];
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    pre[i] = pre[i + n] = a[i];
    a[i + n] = a[i];
    profit[i] = profit[i + n] = psum(a[i]);
  }
  n *= 2;
  for (int i = 1; i < n; i++) {
    pre[i] += pre[i - 1];
    profit[i] += profit[i - 1];
  }
  long long ans = 0;
  for (int i = n / 2; i < n; i++) {
    int low = 0, high = i - 1;
    long long temp_x = x;
    while (low < high) {
      int mid = (low + high + 1) / 2;
      if (pre[i] - pre[mid] >= temp_x)
        low = mid;
      else
        high = mid - 1;
    }
    temp_x -= (pre[i] - pre[low + 1]);
    long long profit_here =
        profit[i] - profit[low + 1] + rsum(a[low + 1] - temp_x + 1, a[low + 1]);
    ans = max(ans, profit_here);
  }
  printf("%lld", ans);
  return 0;
}
