#include <bits/stdc++.h>
using namespace std;
long long get_sum(int a, int b, long long* sum1, int n) {
  if (a <= b) {
    return sum1[b + 1] - sum1[a];
  } else {
    return sum1[b + 1] - sum1[0] + sum1[n] - sum1[a];
  }
}
int main() {
  int n;
  long long x;
  cin >> n >> x;
  int* d = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  long long* sum = new long long[2 * n];
  for (int i = 0; i < 2 * n; i++) {
    if (i == 0) {
      sum[i] = d[i % n];
    } else {
      sum[i] = sum[i - 1] + d[i % n];
    }
  }
  long long ans = 0;
  long long curr = 0;
  long long* sum1 = new long long[n + 1];
  sum1[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum1[i] = sum1[i - 1] + ((long long)d[i - 1] * (d[i - 1] + 1) / 2);
  }
  for (int i = 0; i < n; i++) {
    int ind = lower_bound(sum, sum + 2 * n, x + curr) - sum;
    int t = sum[ind] - (x + curr);
    long long temp_ans;
    if (t >= d[i]) {
      temp_ans = 0;
    } else {
      temp_ans = get_sum(i, ind % n, sum1, n) - ((long long)(t) * (t + 1) / 2);
    }
    ans = max(ans, temp_ans);
    curr += d[i];
  }
  cout << ans << endl;
}
