#include <bits/stdc++.h>
using namespace std;
vector<long long> sieve;
void Sieve(int N) {
  const long long maxn = N;
  sieve.resize(maxn);
  for (long long(i) = 0; (i) < (maxn); ++(i)) sieve[i] = i;
  sieve[1] = -1;
  sieve[0] = -1;
  for (long long(i) = 2; (i) <= (maxn); (i) += (1))
    if (i == sieve[i])
      for (long long j = 2 * i; j < maxn; j += i)
        if (sieve[j] == j) sieve[j] = i;
}
long long extended_GCD(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;
  long long gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
long long power(long long a, long long b, long long m = 1000000007) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod = 1000000007) {
  long long x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0) x += mod;
  return x;
}
void solve() {
  long long n;
  long long x;
  cin >> n >> x;
  long long a[2 * n];
  long long b[2 * n + 1];
  long long ma = -1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > ma) ma = a[i];
  }
  for (int i = 0; i < n; ++i) {
    a[i + n] = a[i];
  }
  b[0] = 0;
  for (int i = 1; i <= 2 * n; ++i) {
    b[i] = a[i - 1] + b[i - 1];
  }
  if (x <= ma) {
    long long cc = (x * (2 * ma - (x - 1))) / 2;
    cout << cc << "\n";
    return;
  }
  long long ans = 0;
  long long in = 2 * n - 1;
  long long cur = 0;
  long long c = 0;
  long long f = 0;
  for (int i = 2 * n - 1; i >= n; i--) {
    if (i != 2 * n - 1) {
      in++;
      long long cc = a[in] - f;
      c -= cc;
      cur -= ((cc) * (2 * a[in] - (cc - 1))) / 2;
      cur -= (a[i + 1] * (a[i + 1] + 1)) / 2;
      c -= a[i + 1];
      f = 0;
    }
    if (c <= 0) {
      c = 0;
      cur = 0;
    }
    while (c != x) {
      if (x - c >= a[in]) {
        cur += (a[in] * (a[in] + 1)) / 2;
        c += a[in];
      } else {
        cur += ((x - c) * (2 * a[in] - (x - c - 1))) / 2;
        f = a[in] - (x - c);
        c = x;
      }
      in--;
    }
    ans = max(ans, cur);
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
