#include <bits/stdc++.h>
using namespace std;
bool sortinrev(long long x, long long y) { return x > y; }
void swap(long long* a, long long* b) {
  long long temp = *a;
  *a = *b;
  *b = temp;
}
long long div_ceil(long long a, long long b) { return (a + b - 1) / b; }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
const int MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1e18L + 5;
const int nax = 4000005;
const int N = int(1e6);
void solve() {
  long long n, x;
  cin >> n >> x;
  vector<long long> arr(2 * n);
  vector<long long> pref1 = {0}, pref2 = {0};
  for (long long i = 0; i < n; ++i) {
    cin >> arr[i];
    arr[i + n] = arr[i];
  }
  n *= 2;
  for (long long i = 0; i < n; ++i) {
    pref1.push_back(pref1.back() + arr[i]);
    pref2.push_back(pref2.back() + arr[i] * (arr[i] + 1) / 2);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (pref1[i + 1] >= x) {
      long long z =
          upper_bound((pref1).begin(), (pref1).end(), pref1[i + 1] - x) -
          pref1.begin();
      long long cnt = pref2[i + 1] - pref2[z];
      long long days = pref1[i + 1] - pref1[z];
      long long too = x - days;
      cnt += ((arr[z - 1] * (arr[z - 1] + 1)) / 2);
      cnt -= (((arr[z - 1] - too) * (arr[z - 1] - too + 1)) / 2);
      ans = max(ans, cnt);
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  cerr << "\nI am Winning";
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
