#include <bits/stdc++.h>
using namespace std;
long long int BinSea(vector<long long int>& a, long long int low,
                     long long int high, long long int n) {
  long long int ct = high;
  long long int ans = high;
  while (low <= high) {
    long long int mid = low + ((high - low) / 2);
    long long int val = a[ct] - a[mid];
    if (val <= n) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  return ans;
}
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a(2 * n + 1);
  vector<long long int> p1(2 * n + 1), p2(2 * n + 1);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    a[n + i] = a[i];
  }
  long long int v1 = 0, v2 = 0;
  for (long long int i = 0; i < 2 * n; i++) {
    v1 += (a[i] * (a[i] + 1)) / 2;
    v2 += a[i];
    p1[i] = v1;
    p2[i] = v2;
  }
  long long int mx = 0;
  for (long long int i = 2 * n - 1; i > n - 1; i--) {
    long long int val = BinSea(p2, 0, i, k);
    long long int fullmt = p1[i] - p1[val];
    long long int remdy = a[val] - (k - (p2[i] - p2[val]));
    long long int sumrem = remdy * (remdy + 1) / 2;
    long long int sum = a[val] * (a[val] + 1) / 2;
    fullmt += (sum - sumrem);
    mx = max(mx, fullmt);
  }
  cout << mx << endl;
  return 0;
}
