#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long int n, k;
long long int a[N];
long long int month[2 * N];
long long int sum(long long int days) { return (days * (days + 1) / 2); }
void solve() {
  cin >> n >> k;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    month[i] = a[i];
    month[n + i] = a[i];
  }
  long long int j = 0;
  long long int hugs = 0, days = 0, best = 0;
  for (long long int i = 0; i < 2 * n; i++) {
    hugs += sum(month[i]);
    days += month[i];
    while (days > k) {
      days -= month[j];
      hugs -= sum(month[j]);
      j++;
    }
    long long int curr = hugs;
    if (j > 0) {
      long long int skips = month[j - 1] + days - k;
      curr += sum(month[j - 1]) - sum(skips);
    }
    best = max(best, curr);
  }
  cout << best << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
