#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6) {
    if (n % i == 0 || n % (i + 2) == 0) return false;
  }
  return true;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (a < b) swap(a, b);
  return gcd(a % b, b);
}
long long gcdextended(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1, gcd = gcdextended(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
long long modinverse(long long a, long long m) {
  long long x, y;
  long long g = gcdextended(a, m, x, y);
  if (g != 1) {
    cout << "NOT POSSIBLE";
    return -1;
  } else
    return (x % m + m) % m;
}
long long po(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long pom(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long root(long long x, vector<long long> &id) {
  while (id[x] != x) {
    id[x] = id[id[x]];
    x = id[x];
  }
  return x;
}
void uni(long long x, long long y, vector<long long> &id) {
  long long a = root(x, id);
  long long b = root(y, id);
  id[a] = id[b];
}
bool sec(const pair<long long, long long> &a,
         const pair<long long, long long> &b) {
  if (a.second == b.second) return a.first < b.first;
  return a.second < b.second;
}
void solve() {
  long long n, x, i, k, an = -1, c, cn, y, cnt;
  cin >> n >> x;
  long long a[2 * n], b[2 * n], p[2 * n];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = n; i < 2 * n; i++) a[i] = a[i - n];
  for (i = 0; i < 2 * n; i++) {
    p[i] = a[i], b[i] = (a[i] * (a[i] + 1)) / 2;
    if (i) p[i] += p[i - 1], b[i] += b[i - 1];
  }
  for (i = n; i < 2 * n; i++) {
    long long l = 0, h = i, m;
    while (l <= h) {
      m = (l + h) / 2, k = p[i];
      if (m) k -= p[m - 1];
      if (k > x)
        l = m + 1;
      else
        h = m - 1;
    }
    c = b[i], cnt = p[i];
    if (l) c -= b[l - 1], cnt -= p[l - 1];
    if (cnt < x) {
      cn = x - cnt;
      y = a[l - 1];
      c += (y * (y + 1)) / 2;
      c -= ((y - cn) * (y - cn + 1)) / 2;
    }
    an = max(an, c);
  }
  cout << an;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
