#include <bits/stdc++.h>
using namespace std;
int tc;
unsigned long long a[400005], sum[400005], pre[400005];
void pre_cal(int n) {
  sum[0] = pre[0] = 0;
  for (int i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];
  for (int i = 1; i <= 2 * n; i++) {
    long long x = (a[i] * (a[i] + 1)) / 2;
    sum[i] = sum[i - 1] + x;
    pre[i] = pre[i - 1] + a[i];
  }
}
long long sol(long long n, long long k) {
  long long lo = 1, hi = 1, now, ans = 0, x;
  while (lo <= hi && hi <= 2 * n) {
    now = pre[hi] - pre[lo - 1];
    if (now < k) {
      hi++;
    } else if (now == k) {
      x = sum[hi] - sum[lo - 1];
      ans = max(ans, x);
      hi++;
    } else {
      long long extra = now - k;
      long long s1 = sum[hi] - sum[lo - 1];
      long long s2 = (extra * (extra + 1)) / 2;
      ans = max(ans, s1 - s2);
      lo++;
    }
  }
  return ans;
}
void solve() {
  long long n, k, ans = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] >= k) {
      long long z = a[i];
      long long x = (z * (z + 1)) / 2;
      z = a[i] - k;
      long long y = (z * (z + 1)) / 2;
      ans = max(ans, x - y);
    }
  }
  if (ans) {
    cout << ans << endl;
    return;
  }
  pre_cal(n);
  ans = sol(n, k);
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
