#include <bits/stdc++.h>
using namespace std;
long long int sum(long long int n) { return n * (n + 1) / 2; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, x;
  cin >> n >> x;
  long long int a[2 * n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long int i = n; i < 2 * n; i++) {
    a[i] = a[i - n];
  }
  long long int p1 = 0;
  long long int p2 = 0;
  long long int num = a[0];
  long long int b[2 * n];
  long long int c[2 * n];
  c[0] = a[0];
  for (long long int i = 0; i < 2 * n; i++) {
    b[i] = a[i] * (a[i] + 1) / 2;
  }
  for (long long int i = 1; i < 2 * n; i++) {
    b[i] += b[i - 1];
    c[i] = c[i - 1] + a[i];
  }
  while (1) {
    if (num >= x) {
      break;
    }
    p2++;
    num += a[p2];
  }
  long long int ans = 0;
  while (1) {
    if (p2 == 2 * n) {
      break;
    }
    long long int temp = b[p2] - b[p1];
    long long int y = x - (c[p2] - c[p1]);
    if (y < 0) {
      p1++;
      continue;
    }
    temp += sum(a[p1]) - sum(a[p1] - y);
    ans = max(ans, temp);
    p2++;
    if (c[p2] - c[p1] >= x) {
      p1++;
    }
  }
  cout << ans;
  return 0;
}
