#include <bits/stdc++.h>
using namespace std;
void Fast_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
vector<int> v;
vector<vector<int> > ed;
void dfs(int i) {
  v[i] = 1;
  for (auto& j : ed[i])
    if (!v[j]) dfs(j);
}
int main() {
  Fast_IO();
  int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    long long m;
    cin >> m;
    vector<long long> arr(2 * n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < n; i++) {
      arr[n + i] = (arr[i]);
    }
    vector<long long> dp(2 * n, 0);
    dp[0] = arr[0];
    for (int i = 1; i < 2 * n; i++) dp[i] = dp[i - 1] + arr[i];
    vector<long long> dp2(2 * n, 0);
    dp2[0] = (arr[0] * (arr[0] + 1) / 2);
    for (int i = 1; i < 2 * n; i++)
      dp2[i] = dp2[i - 1] + (arr[i] * (arr[i] + 1) / 2);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      long long tmp = m - arr[n + i];
      if (tmp <= 0) {
        ans = max(ans, (arr[n + i] * (arr[n + i] + 1) / 2) -
                           ((-tmp) * ((-tmp) + 1) / 2));
        continue;
      }
      tmp = dp[n + i] - m;
      int l = 0;
      int r = n + i;
      while (l < r) {
        int m = (l + r) / 2;
        if (dp[m] <= tmp) {
          if (dp[m + 1] > tmp)
            r = m;
          else
            l = m + 1;
        } else
          r = m - 1;
      }
      l++;
      long long z = dp[n + i] - dp[l];
      long long y = m - z;
      y = arr[l] - y;
      ans = max(ans, (arr[l] * (arr[l] + 1) / 2) - (y * (y + 1) / 2) +
                         dp2[n + i] - dp2[l]);
      tmp = 1 + dp[n + i - 1] - m;
      l = 0;
      r = n + i;
      while (l < r) {
        int m = (l + r) / 2;
        if (dp[m] <= tmp) {
          if (dp[m + 1] > tmp)
            r = m;
          else
            l = m + 1;
        } else
          r = m - 1;
      }
      l++;
      z = dp[n + i - 1] + 1 - dp[l];
      y = m - z;
      y = arr[l] - y;
      ans = max(ans, (arr[l] * (arr[l] + 1) / 2) - (y * (y + 1) / 2) +
                         dp2[n + i - 1] - dp2[l] + 1);
    }
    cout << ans;
    cout << '\n';
  }
  return 0;
}
