#include <bits/stdc++.h>
using namespace std;
struct st {
  long long l, r;
};
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long ans = 1;
  while (b > 0) {
    if (b & 1) (ans = ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
void solve() {
  long long n, x;
  cin >> n >> x;
  long long a[(2 * (n)) + 1];
  long long pre1[(2 * (n)) + 1], pre2[(2 * (n)) + 1];
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i + n] = a[i];
  }
  pre1[0] = 0;
  pre2[0] = 0;
  a[0] = 0;
  for (long long i = 1; i <= 2 * n; ++i) {
    pre2[i] = pre2[i - 1] + a[i];
    pre1[i] = pre1[i - 1] + (a[i] * (a[i] + 1)) / 2;
  }
  long long maxi = 0;
  for (long long i = 2 * n; i >= n; --i) {
    long long low = 1, high = i, ans = i;
    while (low <= high) {
      long long mid = (low + high) / 2;
      if (pre2[i] - pre2[mid] < x) {
        ans = mid;
        high = mid - 1;
      } else
        low = mid + 1;
    }
    long long temp = pre2[i] - pre2[ans - 1] - x;
    long long sum = pre1[i] - pre1[ans - 1];
    sum -= ((temp * (temp + 1))) / 2;
    maxi = max(maxi, sum);
  }
  cout << maxi;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
