#include <bits/stdc++.h>
using namespace std;
struct fast {
  fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
} cincout;
long long arr[400010], cum[400010], sumCum[400010];
long long sum(long long n) { return n * (n + 1) / 2; }
long long more(long long rem, long long from, long long n) {
  if (rem <= 0) return 0;
  int low = from, high = from + n - 1, ret = -1, mid;
  while (low <= high) {
    mid = (low + high) / 2;
    if (cum[mid] - cum[from - 1] < rem) {
      low = mid + 1;
    } else {
      ret = mid;
      high = mid - 1;
    }
  }
  if (ret == -1) return 0;
  rem -= cum[ret - 1] - cum[from - 1];
  long long res = sumCum[ret - 1] - sumCum[from - 1];
  return res + sum(rem);
}
long long f(long long mid, long long x, long long has, long long i,
            long long n) {
  has = min(has, x + mid);
  long long ret = sum(has) - sum(mid);
  ret += more(x - (has - mid), i + 1, n);
  return ret;
}
int main() {
  long long n, x;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i + n] = arr[i];
  }
  cum[0] = arr[0];
  sumCum[0] = sum(arr[0]);
  for (int i = 1; i < 2 * n; i++) {
    cum[i] = arr[i] + cum[i - 1];
    sumCum[i] = sumCum[i - 1] + sum(arr[i]);
  }
  long long ans = 0;
  for (int i = 0; i < 2 * n; i++) {
    long long low = -1, mid, high = arr[i];
    while (high - low > 1) {
      mid = (low + high) / 2;
      if (f(mid, x, arr[i], i, n) > f(mid + 1, x, arr[i], i, n))
        high = mid;
      else
        low = mid;
    }
    ans = max(ans, f(low + 1, x, arr[i], i, n));
  }
  cout << ans;
  return 0;
}
