#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
vector<long long> arr(400001, 1ll << 41);
vector<long long> sm(400001, 0);
int main() {
  long long n, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i + n] = arr[i];
  }
  sm[0] = (arr[0] * (arr[0] + 1)) / 2;
  for (int i = 1; i < 2 * n; i++) {
    sm[i] += (sm[i - 1] + ((arr[i] * (arr[i] + 1)) / 2));
    arr[i] += arr[i - 1];
  }
  long long res = 0;
  for (int i = 0; i < n; i++) {
    long long fnd = d + ((i == 0) ? 0 : arr[i - 1]);
    int indx =
        lower_bound(arr.begin() + i, arr.begin() + (2 * n), fnd) - arr.begin();
    long long rem = arr[indx] - fnd;
    long long val = sm[indx] - ((i == 0) ? 0 : sm[i - 1]);
    res = max(res, val - ((rem * (rem + 1)) / 2));
  }
  cout << res << endl;
  return 0;
}
