#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
long long a[maxn], sum[maxn];
void solve() {
  long long n, x;
  cin >> n >> x;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i + n] = a[i];
    sum[i] = sum[i + n] = (1 + a[i]) * a[i] / 2;
  }
  for (int i = 1; i <= 2 * n; ++i) {
    a[i] += a[i - 1];
    sum[i] += sum[i - 1];
  }
  long long ans = 0, p, low;
  for (int i = 1; i <= 2 * n; ++i) {
    if (a[i] < x) continue;
    low = a[i] - x;
    p = lower_bound(a + 1, a + 1 + 2 * n, low) - a;
    if (a[i] - a[p] == x) {
      ans = max(ans, sum[i] - sum[p]);
    } else {
      long long last = low - a[p - 1];
      ans = max(ans, sum[i] - sum[p - 1] - (1 + last) * last / 2);
    }
  }
  cout << ans << '\n';
}
int main() { solve(); }
